pp.pas 7.4 KB

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