pp.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. {$ifdef XTENSA}
  170. {$ifdef CPUDEFINED}
  171. {$fatal ONLY one of the switches for the CPU type must be defined}
  172. {$endif CPUDEFINED}
  173. {$define CPUDEFINED}
  174. {$endif XTENSA}
  175. {$ifndef CPUDEFINED}
  176. {$fatal A CPU type switch must be defined}
  177. {$endif CPUDEFINED}
  178. {$ifdef support_mmx}
  179. {$ifndef i386}
  180. {$fatal I386 switch must be on for MMX support}
  181. {$endif i386}
  182. {$endif support_mmx}
  183. { Don't care about minstacksize or maxstacksize not beeing supported by current OS }
  184. {$WARN 2077 OFF}
  185. {$WARN 2078 OFF}
  186. {$ifdef win32}
  187. { 256 MB stack }
  188. { under windows the stack can't grow }
  189. {$MAXSTACKSIZE 256000000}
  190. {$setpeflags $20}
  191. {$else win32}
  192. {$ifdef win64}
  193. { 512 MB stack }
  194. { under windows the stack can't grow }
  195. {$MAXSTACKSIZE 512000000}
  196. {$else win64}
  197. { 1 MB stack }
  198. {$MINSTACKSIZE 1000000}
  199. {$endif win64}
  200. {$endif win32}
  201. uses
  202. {$ifdef heaptrc}
  203. ppheap,
  204. {$endif heaptrc}
  205. {$ifdef cmem}
  206. cmem,
  207. {$endif cmem}
  208. {$ifdef profile}
  209. profile,
  210. {$endif profile}
  211. {$ifndef NOCATCH}
  212. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  213. catch,
  214. {$endif}
  215. {$endif NOCATCH}
  216. globals,compiler;
  217. var
  218. oldexit : pointer;
  219. procedure myexit;
  220. begin
  221. exitproc:=oldexit;
  222. {$ifdef nocatch}
  223. exit;
  224. {$endif nocatch}
  225. { Show Runtime error if there was an error }
  226. if (erroraddr<>nil) then
  227. begin
  228. case exitcode of
  229. 100:
  230. begin
  231. erroraddr:=nil;
  232. writeln('Error while reading file');
  233. end;
  234. 101:
  235. begin
  236. erroraddr:=nil;
  237. writeln('Error while writing file');
  238. end;
  239. 202:
  240. begin
  241. erroraddr:=nil;
  242. writeln('Error: Stack Overflow');
  243. end;
  244. 203:
  245. begin
  246. erroraddr:=nil;
  247. writeln('Error: Out of memory');
  248. end;
  249. end;
  250. { we cannot use current_filepos.file because all memory might have been
  251. freed already !
  252. But we can use global parser_current_file var }
  253. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  254. end;
  255. end;
  256. begin
  257. oldexit:=exitproc;
  258. exitproc:=@myexit;
  259. {$ifdef EXTDEBUG}
  260. { Increase the maximum stack trace depth, since the default 8 is often not
  261. enough for debugging the compiler }
  262. Max_Frame_Dump:=50;
  263. {$endif EXTDEBUG}
  264. { Call the compiler with empty command, so it will take the parameters }
  265. Halt(compiler.Compile(''));
  266. end.