pp.pas 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. MOS6502 generate a compiler for the MOS Technology 6502
  34. POWERPC generate a compiler for the PowerPC
  35. POWERPC64 generate a compiler for the PowerPC64 architecture
  36. RISCV32 generate a compiler for the RiscV32 architecture
  37. RISCV64 generate a compiler for the RiscV64 architecture
  38. SPARC generate a compiler for SPARC
  39. SPARC64 generate a compiler for SPARC64
  40. WASM32 generate a compiler for WebAssembly 32-bit
  41. X86_64 generate a compiler for the AMD x86-64 architecture
  42. XTENSA generate a compiler for XTENSA
  43. Z80 generate a compiler for Z80
  44. -----------------------------------------------------------------
  45. Other compiler switches
  46. -----------------------------------------------------------------
  47. CMEM use cmem unit for better memory debugging
  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. {$ifdef MOS6502}
  201. {$ifdef CPUDEFINED}
  202. {$fatal ONLY one of the switches for the CPU type must be defined}
  203. {$endif CPUDEFINED}
  204. {$define CPUDEFINED}
  205. {$endif MOS6502}
  206. {$ifndef CPUDEFINED}
  207. {$fatal A CPU type switch must be defined}
  208. {$endif CPUDEFINED}
  209. {$ifdef support_mmx}
  210. {$ifndef i386}
  211. {$fatal I386 switch must be on for MMX support}
  212. {$endif i386}
  213. {$endif support_mmx}
  214. {$ifdef windows}
  215. {$ifdef win32}
  216. { 256 MB stack }
  217. { under windows the stack can't grow }
  218. {$MAXSTACKSIZE 256000000}
  219. {$setpeflags $20}
  220. {$else win32}
  221. {$ifdef win64}
  222. { 512 MB stack }
  223. { under windows the stack can't grow }
  224. {$MAXSTACKSIZE 512000000}
  225. {$else win64}
  226. { 1 MB stack }
  227. {$MINSTACKSIZE 1000000}
  228. {$endif win64}
  229. {$endif win32}
  230. {$endif windows}
  231. uses
  232. {$ifdef heaptrc}
  233. ppheap,
  234. {$endif heaptrc}
  235. {$ifdef cmem}
  236. cmem,
  237. {$endif cmem}
  238. {$ifdef profile}
  239. profile,
  240. {$endif profile}
  241. {$ifndef NOCATCH}
  242. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  243. catch,
  244. {$endif}
  245. {$endif NOCATCH}
  246. globals,compiler;
  247. var
  248. oldexit : pointer;
  249. procedure myexit;
  250. begin
  251. exitproc:=oldexit;
  252. {$ifdef nocatch}
  253. exit;
  254. {$endif nocatch}
  255. { Show Runtime error if there was an error }
  256. if (erroraddr<>nil) then
  257. begin
  258. case exitcode of
  259. 100:
  260. begin
  261. erroraddr:=nil;
  262. writeln('Error while reading file');
  263. end;
  264. 101:
  265. begin
  266. erroraddr:=nil;
  267. writeln('Error while writing file');
  268. end;
  269. 202:
  270. begin
  271. erroraddr:=nil;
  272. writeln('Error: Stack Overflow');
  273. end;
  274. 203:
  275. begin
  276. erroraddr:=nil;
  277. writeln('Error: Out of memory');
  278. end;
  279. end;
  280. { we cannot use current_filepos.file because all memory might have been
  281. freed already !
  282. But we can use global parser_current_file var }
  283. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  284. end;
  285. end;
  286. begin
  287. oldexit:=exitproc;
  288. exitproc:=@myexit;
  289. {$ifdef EXTDEBUG}
  290. { Increase the maximum stack trace depth, since the default 8 is often not
  291. enough for debugging the compiler }
  292. Max_Frame_Dump:=50;
  293. {$endif EXTDEBUG}
  294. { Call the compiler with empty command, so it will take the parameters }
  295. Halt(compiler.Compile(''));
  296. end.