pp.pas 8.9 KB

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