pp.pas 9.6 KB

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