pp.pas 9.2 KB

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