pp.pas 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. I386 generate a compiler for the Intel i386+
  27. I8086 generate a compiler for the Intel 8086+
  28. JVM generate a compiler for the JVM (Java Virtual Machine)
  29. LOONGARCH64 generate a compiler for the LoongArch64 architecture
  30. M68K generate a compiler for the M68000
  31. MIPS generate a compiler for the MIPS (Big Endian)
  32. MIPSEL generate a compiler for the MIPSEL (Littel Endian)
  33. POWERPC generate a compiler for the PowerPC
  34. POWERPC64 generate a compiler for the PowerPC64 architecture
  35. RISCV32 generate a compiler for the RiscV32 architecture
  36. RISCV64 generate a compiler for the RiscV64 architecture
  37. SPARC generate a compiler for SPARC
  38. SPARC64 generate a compiler for SPARC64
  39. WASM32 generate a compiler for WebAssembly 32-bit
  40. X86_64 generate a compiler for the AMD x86-64 architecture
  41. XTENSA generate a compiler for XTENSA
  42. Z80 generate a compiler for Z80
  43. -----------------------------------------------------------------
  44. Other compiler switches
  45. -----------------------------------------------------------------
  46. CMEM use cmem unit for better memory debugging
  47. MMM use Mormot Memory Manager for faster memory management. x86_64 only.
  48. =======
  49. DEBUG version with debug code is generated
  50. EXTDEBUG some extra debug code is executed
  51. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  52. use external messagefiles, default for TP
  53. LLVM Create an LLVM-based code generator for the selected
  54. target architecture (not supported for all targets)
  55. -----------------------------------------------------------------
  56. ARM specfic switches
  57. -----------------------------------------------------------------
  58. FPC_ARMEL create an arm eabi compiler
  59. FPC_ARMEB create an arm big endian compiler
  60. FPC_OARM create an arm oabi compiler, only needed when the host
  61. compiler is ARMEL or ARMEB
  62. FPC_ARMHF create an armhf (eabi vfp variant) compiler
  63. -----------------------------------------------------------------
  64. I386 specfic switches
  65. -----------------------------------------------------------------
  66. SUPPORT_MMX only i386: releases the compiler switch
  67. MMX which allows the compiler to generate
  68. MMX instructions
  69. -----------------------------------------------------------------
  70. Switches automatically inside fpcdefs.inc
  71. -----------------------------------------------------------------
  72. cpuflags The target processor has status flags (on by default)
  73. cpufpemu The target compiler will also support emitting software
  74. floating point operations
  75. cpu64bitaddr Generate code for a 64-bit address space
  76. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  77. (required for cpu64bitaddr; optional with 32 bit addr space)
  78. -----------------------------------------------------------------
  79. }
  80. {$i fpcdefs.inc}
  81. { Require at least 3.2.0 }
  82. {$if FPC_FULLVERSION<30200}
  83. {$fatal At least FPC 3.2.0 is required to compile the compiler}
  84. {$endif}
  85. { exactly one target CPU must be defined }
  86. {$ifdef I8086}
  87. {$ifdef CPUDEFINED}
  88. {$fatal ONLY one of the switches for the CPU type must be defined}
  89. {$endif CPUDEFINED}
  90. {$define CPUDEFINED}
  91. {$endif I8086}
  92. {$ifdef I386}
  93. {$ifdef CPUDEFINED}
  94. {$fatal ONLY one of the switches for the CPU type must be defined}
  95. {$endif CPUDEFINED}
  96. {$define CPUDEFINED}
  97. {$endif I386}
  98. {$ifdef x86_64}
  99. {$ifdef CPUDEFINED}
  100. {$fatal ONLY one of the switches for the CPU type must be defined}
  101. {$endif CPUDEFINED}
  102. {$define CPUDEFINED}
  103. {$endif x86_64}
  104. {$ifdef M68K}
  105. {$ifdef CPUDEFINED}
  106. {$fatal ONLY one of the switches for the CPU type must be defined}
  107. {$endif CPUDEFINED}
  108. {$define CPUDEFINED}
  109. {$endif M68K}
  110. {$ifdef POWERPC}
  111. {$ifdef CPUDEFINED}
  112. {$fatal ONLY one of the switches for the CPU type must be defined}
  113. {$endif CPUDEFINED}
  114. {$define CPUDEFINED}
  115. {$endif POWERPC}
  116. {$ifdef POWERPC64}
  117. {$ifdef CPUDEFINED}
  118. {$fatal ONLY one of the switches for the CPU type must be defined}
  119. {$endif CPUDEFINED}
  120. {$define CPUDEFINED}
  121. {$endif POWERPC64}
  122. {$ifdef SPARC}
  123. {$ifdef CPUDEFINED}
  124. {$fatal ONLY one of the switches for the CPU type must be defined}
  125. {$endif CPUDEFINED}
  126. {$define CPUDEFINED}
  127. {$endif SPARC}
  128. {$ifdef SPARC64}
  129. {$ifdef CPUDEFINED}
  130. {$fatal ONLY one of the switches for the CPU type must be defined}
  131. {$endif CPUDEFINED}
  132. {$define CPUDEFINED}
  133. {$endif SPARC64}
  134. {$ifdef ARM}
  135. {$ifdef CPUDEFINED}
  136. {$fatal ONLY one of the switches for the CPU type must be defined}
  137. {$endif CPUDEFINED}
  138. {$define CPUDEFINED}
  139. {$endif ARM}
  140. {$ifdef MIPS}
  141. {$ifdef CPUDEFINED}
  142. {$fatal ONLY one of the switches for the CPU type must be defined}
  143. {$endif CPUDEFINED}
  144. {$define CPUDEFINED}
  145. {$endif MIPS}
  146. {$ifdef AVR}
  147. {$ifdef CPUDEFINED}
  148. {$fatal ONLY one of the switches for the CPU type must be defined}
  149. {$endif CPUDEFINED}
  150. {$define CPUDEFINED}
  151. {$endif AVR}
  152. {$ifdef JVM}
  153. {$ifdef CPUDEFINED}
  154. {$fatal ONLY one of the switches for the CPU type must be defined}
  155. {$endif CPUDEFINED}
  156. {$define CPUDEFINED}
  157. {$endif}
  158. {$ifdef AARCH64}
  159. {$ifdef CPUDEFINED}
  160. {$fatal ONLY one of the switches for the CPU type must be defined}
  161. {$endif CPUDEFINED}
  162. {$define CPUDEFINED}
  163. {$endif AARCH64}
  164. {$ifdef RISCV32}
  165. {$ifdef CPUDEFINED}
  166. {$fatal ONLY one of the switches for the CPU type must be defined}
  167. {$endif CPUDEFINED}
  168. {$define CPUDEFINED}
  169. {$endif RISCV32}
  170. {$ifdef RISCV64}
  171. {$ifdef CPUDEFINED}
  172. {$fatal ONLY one of the switches for the CPU type must be defined}
  173. {$endif CPUDEFINED}
  174. {$define CPUDEFINED}
  175. {$endif RISCV64}
  176. {$ifdef XTENSA}
  177. {$ifdef CPUDEFINED}
  178. {$fatal ONLY one of the switches for the CPU type must be defined}
  179. {$endif CPUDEFINED}
  180. {$define CPUDEFINED}
  181. {$endif XTENSA}
  182. {$ifdef Z80}
  183. {$ifdef CPUDEFINED}
  184. {$fatal ONLY one of the switches for the CPU type must be defined}
  185. {$endif CPUDEFINED}
  186. {$define CPUDEFINED}
  187. {$endif Z80}
  188. {$ifdef WASM32}
  189. {$ifdef CPUDEFINED}
  190. {$fatal ONLY one of the switches for the CPU type must be defined}
  191. {$endif CPUDEFINED}
  192. {$define CPUDEFINED}
  193. {$endif WASM32}
  194. {$ifdef LOONGARCH64}
  195. {$ifdef CPUDEFINED}
  196. {$fatal ONLY one of the switches for the CPU type must be defined}
  197. {$endif CPUDEFINED}
  198. {$define CPUDEFINED}
  199. {$endif LOONGARCH64}
  200. {$ifndef CPUDEFINED}
  201. {$fatal A CPU type switch must be defined}
  202. {$endif CPUDEFINED}
  203. {$ifdef support_mmx}
  204. {$ifndef i386}
  205. {$fatal I386 switch must be on for MMX support}
  206. {$endif i386}
  207. {$endif support_mmx}
  208. {$ifdef windows}
  209. {$ifdef win32}
  210. { 256 MB stack }
  211. { under windows the stack can't grow }
  212. {$MAXSTACKSIZE 256000000}
  213. {$setpeflags $20}
  214. {$else win32}
  215. {$ifdef win64}
  216. { 512 MB stack }
  217. { under windows the stack can't grow }
  218. {$MAXSTACKSIZE 512000000}
  219. {$else win64}
  220. { 1 MB stack }
  221. {$MINSTACKSIZE 1000000}
  222. {$endif win64}
  223. {$endif win32}
  224. {$endif windows}
  225. uses
  226. {$ifdef heaptrc}
  227. ppheap,
  228. {$endif heaptrc}
  229. {$IFDEF CPUX86_64}
  230. {$IFDEF MMM}
  231. mormot.core.fpcx64mm,
  232. {$ENDIF}
  233. {$ENDIF}
  234. {$ifdef cmem}
  235. cmem,
  236. {$endif cmem}
  237. {$ifdef profile}
  238. profile,
  239. {$endif profile}
  240. {$ifndef NOCATCH}
  241. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  242. catch,
  243. {$endif}
  244. {$endif NOCATCH}
  245. globals,compiler;
  246. var
  247. oldexit : pointer;
  248. procedure myexit;
  249. begin
  250. exitproc:=oldexit;
  251. {$ifdef nocatch}
  252. exit;
  253. {$endif nocatch}
  254. { Show Runtime error if there was an error }
  255. if (erroraddr<>nil) then
  256. begin
  257. case exitcode of
  258. 100:
  259. begin
  260. erroraddr:=nil;
  261. writeln('Error while reading file');
  262. end;
  263. 101:
  264. begin
  265. erroraddr:=nil;
  266. writeln('Error while writing file');
  267. end;
  268. 202:
  269. begin
  270. erroraddr:=nil;
  271. writeln('Error: Stack Overflow');
  272. end;
  273. 203:
  274. begin
  275. erroraddr:=nil;
  276. writeln('Error: Out of memory');
  277. end;
  278. end;
  279. { we cannot use current_filepos.file because all memory might have been
  280. freed already !
  281. But we can use global parser_current_file var }
  282. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  283. end;
  284. end;
  285. begin
  286. oldexit:=exitproc;
  287. exitproc:=@myexit;
  288. {$ifdef EXTDEBUG}
  289. { Increase the maximum stack trace depth, since the default 8 is often not
  290. enough for debugging the compiler }
  291. Max_Frame_Dump:=50;
  292. {$endif EXTDEBUG}
  293. { Call the compiler with empty command, so it will take the parameters }
  294. Halt(compiler.Compile(''));
  295. end.