pp.pas 8.4 KB

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