pp.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Commandline compiler for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. program pp;
  18. {
  19. possible compiler switches:
  20. -----------------------------------------------------------------
  21. Supported CPUs, alphabetically sorted
  22. -----------------------------------------------------------------
  23. AARCH64 generate a compiler for the AARCH64 (64bit ARM)
  24. ARM generate a compiler for the ARM
  25. AVR generate a compiler for the AVR
  26. I8086 generate a compiler for the Intel 8086+
  27. I386 generate a compiler for the Intel i386+
  28. JVM generate a compiler for the JVM (Java Virtual Machine)
  29. M68K generate a compiler for the M68000
  30. MIPS generate a compiler for the MIPS (Big Endian)
  31. MIPSEL generate a compiler for the MIPSEL (Littel Endian)
  32. POWERPC generate a compiler for the PowerPC
  33. POWERPC64 generate a compiler for the PowerPC64 architecture
  34. RISCV64 generate a compiler for the RiscV64 architecture
  35. SPARC generate a compiler for SPARC
  36. SPARC64 generate a compiler for SPARC64
  37. X86_64 generate a compiler for the AMD x86-64 architecture
  38. -----------------------------------------------------------------
  39. Other compiler switches
  40. -----------------------------------------------------------------
  41. CMEM use cmem unit for better memory debugging
  42. DEBUG version with debug code is generated
  43. EXTDEBUG some extra debug code is executed
  44. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  45. use external messagefiles, default for TP
  46. -----------------------------------------------------------------
  47. ARM specfic switches
  48. -----------------------------------------------------------------
  49. FPC_ARMEL create an arm eabi compiler
  50. FPC_ARMEB create an arm big endian compiler
  51. FPC_OARM create an arm oabi compiler, only needed when the host
  52. compiler is ARMEL or ARMEB
  53. FPC_ARMHF create an armhf (eabi vfp variant) compiler
  54. -----------------------------------------------------------------
  55. I386 specfic switches
  56. -----------------------------------------------------------------
  57. SUPPORT_MMX only i386: releases the compiler switch
  58. MMX which allows the compiler to generate
  59. MMX instructions
  60. -----------------------------------------------------------------
  61. Switches automatically inside fpcdefs.inc
  62. -----------------------------------------------------------------
  63. cpuflags The target processor has status flags (on by default)
  64. cpufpemu The target compiler will also support emitting software
  65. floating point operations
  66. cpu64bitaddr Generate code for a 64-bit address space
  67. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  68. (required for cpu64bitaddr; optional with 32 bit addr space)
  69. -----------------------------------------------------------------
  70. }
  71. {$i fpcdefs.inc}
  72. { Require at least 2.6.0 }
  73. {$if FPC_FULLVERSION<20600}
  74. {$fatal At least FPC 2.6.0 is required to compile the compiler}
  75. {$endif}
  76. { exactly one target CPU must be defined }
  77. {$ifdef I8086}
  78. {$ifdef CPUDEFINED}
  79. {$fatal ONLY one of the switches for the CPU type must be defined}
  80. {$endif CPUDEFINED}
  81. {$define CPUDEFINED}
  82. {$endif I8086}
  83. {$ifdef I386}
  84. {$ifdef CPUDEFINED}
  85. {$fatal ONLY one of the switches for the CPU type must be defined}
  86. {$endif CPUDEFINED}
  87. {$define CPUDEFINED}
  88. {$endif I386}
  89. {$ifdef x86_64}
  90. {$ifdef CPUDEFINED}
  91. {$fatal ONLY one of the switches for the CPU type must be defined}
  92. {$endif CPUDEFINED}
  93. {$define CPUDEFINED}
  94. {$endif x86_64}
  95. {$ifdef M68K}
  96. {$ifdef CPUDEFINED}
  97. {$fatal ONLY one of the switches for the CPU type must be defined}
  98. {$endif CPUDEFINED}
  99. {$define CPUDEFINED}
  100. {$endif M68K}
  101. {$ifdef POWERPC}
  102. {$ifdef CPUDEFINED}
  103. {$fatal ONLY one of the switches for the CPU type must be defined}
  104. {$endif CPUDEFINED}
  105. {$define CPUDEFINED}
  106. {$endif POWERPC}
  107. {$ifdef POWERPC64}
  108. {$ifdef CPUDEFINED}
  109. {$fatal ONLY one of the switches for the CPU type must be defined}
  110. {$endif CPUDEFINED}
  111. {$define CPUDEFINED}
  112. {$endif POWERPC64}
  113. {$ifdef SPARC}
  114. {$ifdef CPUDEFINED}
  115. {$fatal ONLY one of the switches for the CPU type must be defined}
  116. {$endif CPUDEFINED}
  117. {$define CPUDEFINED}
  118. {$endif SPARC}
  119. {$ifdef SPARC64}
  120. {$ifdef CPUDEFINED}
  121. {$fatal ONLY one of the switches for the CPU type must be defined}
  122. {$endif CPUDEFINED}
  123. {$define CPUDEFINED}
  124. {$endif SPARC64}
  125. {$ifdef ARM}
  126. {$ifdef CPUDEFINED}
  127. {$fatal ONLY one of the switches for the CPU type must be defined}
  128. {$endif CPUDEFINED}
  129. {$define CPUDEFINED}
  130. {$endif ARM}
  131. {$ifdef MIPS}
  132. {$ifdef CPUDEFINED}
  133. {$fatal ONLY one of the switches for the CPU type must be defined}
  134. {$endif CPUDEFINED}
  135. {$define CPUDEFINED}
  136. {$endif MIPS}
  137. {$ifdef AVR}
  138. {$ifdef CPUDEFINED}
  139. {$fatal ONLY one of the switches for the CPU type must be defined}
  140. {$endif CPUDEFINED}
  141. {$define CPUDEFINED}
  142. {$endif AVR}
  143. {$ifdef JVM}
  144. {$ifdef CPUDEFINED}
  145. {$fatal ONLY one of the switches for the CPU type must be defined}
  146. {$endif CPUDEFINED}
  147. {$define CPUDEFINED}
  148. {$endif}
  149. {$ifdef AARCH64}
  150. {$ifdef CPUDEFINED}
  151. {$fatal ONLY one of the switches for the CPU type must be defined}
  152. {$endif CPUDEFINED}
  153. {$define CPUDEFINED}
  154. {$endif AARCH64}
  155. {$ifdef RISCV32}
  156. {$ifdef CPUDEFINED}
  157. {$fatal ONLY one of the switches for the CPU type must be defined}
  158. {$endif CPUDEFINED}
  159. {$define CPUDEFINED}
  160. {$endif RISCV32}
  161. {$ifdef RISCV64}
  162. {$ifdef CPUDEFINED}
  163. {$fatal ONLY one of the switches for the CPU type must be defined}
  164. {$endif CPUDEFINED}
  165. {$define CPUDEFINED}
  166. {$endif RISCV64}
  167. {$ifndef CPUDEFINED}
  168. {$fatal A CPU type switch must be defined}
  169. {$endif CPUDEFINED}
  170. {$ifdef support_mmx}
  171. {$ifndef i386}
  172. {$fatal I386 switch must be on for MMX support}
  173. {$endif i386}
  174. {$endif support_mmx}
  175. { Don't care about minstacksize or maxstacksize not beeing supported by current OS }
  176. {$WARN 2077 OFF}
  177. {$WARN 2078 OFF}
  178. {$ifdef win32}
  179. { 256 MB stack }
  180. { under windows the stack can't grow }
  181. {$MAXSTACKSIZE 256000000}
  182. {$setpeflags $20}
  183. {$else win32}
  184. {$ifdef win64}
  185. { 512 MB stack }
  186. { under windows the stack can't grow }
  187. {$MAXSTACKSIZE 512000000}
  188. {$else win64}
  189. { 1 MB stack }
  190. {$MINSTACKSIZE 1000000}
  191. {$endif win64}
  192. {$endif win32}
  193. uses
  194. {$ifdef heaptrc}
  195. ppheap,
  196. {$endif heaptrc}
  197. {$ifdef cmem}
  198. cmem,
  199. {$endif cmem}
  200. {$ifdef profile}
  201. profile,
  202. {$endif profile}
  203. {$ifndef NOCATCH}
  204. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  205. catch,
  206. {$endif}
  207. {$endif NOCATCH}
  208. globals,compiler;
  209. var
  210. oldexit : pointer;
  211. procedure myexit;
  212. begin
  213. exitproc:=oldexit;
  214. {$ifdef nocatch}
  215. exit;
  216. {$endif nocatch}
  217. { Show Runtime error if there was an error }
  218. if (erroraddr<>nil) then
  219. begin
  220. case exitcode of
  221. 100:
  222. begin
  223. erroraddr:=nil;
  224. writeln('Error while reading file');
  225. end;
  226. 101:
  227. begin
  228. erroraddr:=nil;
  229. writeln('Error while writing file');
  230. end;
  231. 202:
  232. begin
  233. erroraddr:=nil;
  234. writeln('Error: Stack Overflow');
  235. end;
  236. 203:
  237. begin
  238. erroraddr:=nil;
  239. writeln('Error: Out of memory');
  240. end;
  241. end;
  242. { we cannot use current_filepos.file because all memory might have been
  243. freed already !
  244. But we can use global parser_current_file var }
  245. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  246. end;
  247. end;
  248. begin
  249. oldexit:=exitproc;
  250. exitproc:=@myexit;
  251. {$ifdef EXTDEBUG}
  252. { Increase the maximum stack trace depth, since the default 8 is often not
  253. enough for debugging the compiler }
  254. Max_Frame_Dump:=50;
  255. {$endif EXTDEBUG}
  256. { Call the compiler with empty command, so it will take the parameters }
  257. Halt(compiler.Compile(''));
  258. end.