pp.pas 9.4 KB

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