pp.pas 8.3 KB

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