pp.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. I386 generate a compiler for the Intel i386+
  23. x86_64 generate a compiler for the AMD x86-64 architecture
  24. M68K generate a compiler for the M68000
  25. SPARC generate a compiler for SPARC
  26. POWERPC generate a compiler for the PowerPC
  27. POWERPC64 generate a compiler for the PowerPC64 architecture
  28. VIS generate a compile for the VIS
  29. DEBUG version with debug code is generated
  30. EXTDEBUG some extra debug code is executed
  31. SUPPORT_MMX only i386: releases the compiler switch
  32. MMX which allows the compiler to generate
  33. MMX instructions
  34. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  35. use external messagefiles, default for TP
  36. FPC_ARMEL create an arm eabi compiler
  37. FPC_OARM create an arm oabi compiler, only needed when the host
  38. compiler is ARMEL
  39. -----------------------------------------------------------------
  40. cpuflags The target processor has status flags (on by default)
  41. cpufpemu The target compiler will also support emitting software
  42. floating point operations
  43. cpu64bitaddr Generate code for a 64-bit address space
  44. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  45. (required for cpu64bitaddr; optional with 32 bit addr space)
  46. -----------------------------------------------------------------
  47. }
  48. {$i fpcdefs.inc}
  49. { Require at least 2.0.2 }
  50. {$ifdef VER2_0}
  51. {$if FPC_PATCH<2}
  52. {$fatal At least FPC 2.0.2 is required to compile the compiler}
  53. {$endif}
  54. {$endif VER2_0}
  55. { exactly one target CPU must be defined }
  56. {$ifdef I386}
  57. {$ifdef CPUDEFINED}
  58. {$fatal ONLY one of the switches for the CPU type must be defined}
  59. {$endif CPUDEFINED}
  60. {$define CPUDEFINED}
  61. {$endif I386}
  62. {$ifdef x86_64}
  63. {$ifdef CPUDEFINED}
  64. {$fatal ONLY one of the switches for the CPU type must be defined}
  65. {$endif CPUDEFINED}
  66. {$define CPUDEFINED}
  67. {$endif x86_64}
  68. {$ifdef M68K}
  69. {$ifdef CPUDEFINED}
  70. {$fatal ONLY one of the switches for the CPU type must be defined}
  71. {$endif CPUDEFINED}
  72. {$define CPUDEFINED}
  73. {$endif M68K}
  74. {$ifdef vis}
  75. {$ifdef CPUDEFINED}
  76. {$fatal ONLY one of the switches for the CPU type must be defined}
  77. {$endif CPUDEFINED}
  78. {$define CPUDEFINED}
  79. {$endif}
  80. {$ifdef iA64}
  81. {$ifdef CPUDEFINED}
  82. {$fatal ONLY one of the switches for the CPU type must be defined}
  83. {$endif CPUDEFINED}
  84. {$define CPUDEFINED}
  85. {$endif iA64}
  86. {$ifdef POWERPC}
  87. {$ifdef CPUDEFINED}
  88. {$fatal ONLY one of the switches for the CPU type must be defined}
  89. {$endif CPUDEFINED}
  90. {$define CPUDEFINED}
  91. {$endif POWERPC}
  92. {$ifdef POWERPC64}
  93. {$ifdef CPUDEFINED}
  94. {$fatal ONLY one of the switches for the CPU type must be defined}
  95. {$endif CPUDEFINED}
  96. {$define CPUDEFINED}
  97. {$endif POWERPC64}
  98. {$ifdef ALPHA}
  99. {$ifdef CPUDEFINED}
  100. {$fatal ONLY one of the switches for the CPU type must be defined}
  101. {$endif CPUDEFINED}
  102. {$define CPUDEFINED}
  103. {$endif ALPHA}
  104. {$ifdef SPARC}
  105. {$ifdef CPUDEFINED}
  106. {$fatal ONLY one of the switches for the CPU type must be defined}
  107. {$endif CPUDEFINED}
  108. {$define CPUDEFINED}
  109. {$endif SPARC}
  110. {$ifdef ARM}
  111. {$ifdef CPUDEFINED}
  112. {$fatal ONLY one of the switches for the CPU type must be defined}
  113. {$endif CPUDEFINED}
  114. {$define CPUDEFINED}
  115. {$endif ARM}
  116. {$ifdef MIPS}
  117. {$ifdef CPUDEFINED}
  118. {$fatal ONLY one of the switches for the CPU type must be defined}
  119. {$endif CPUDEFINED}
  120. {$define CPUDEFINED}
  121. {$endif MIPS}
  122. {$ifdef AVR}
  123. {$ifdef CPUDEFINED}
  124. {$fatal ONLY one of the switches for the CPU type must be defined}
  125. {$endif CPUDEFINED}
  126. {$define CPUDEFINED}
  127. {$endif AVR}
  128. {$ifndef CPUDEFINED}
  129. {$fatal A CPU type switch must be defined}
  130. {$endif CPUDEFINED}
  131. {$ifdef support_mmx}
  132. {$ifndef i386}
  133. {$fatal I386 switch must be on for MMX support}
  134. {$endif i386}
  135. {$endif support_mmx}
  136. {$ifdef win32}
  137. { 256 MB stack }
  138. { under windows the stack can't grow }
  139. {$MAXSTACKSIZE 256000000}
  140. {$else win32}
  141. {$ifdef win64}
  142. { 512 MB stack }
  143. { under windows the stack can't grow }
  144. {$MAXSTACKSIZE 512000000}
  145. {$else win64}
  146. { 1 MB stack }
  147. {$STACKSIZE 1000000}
  148. {$endif win64}
  149. {$endif win32}
  150. uses
  151. {$ifdef cmem}
  152. cmem,
  153. {$endif cmem}
  154. {$ifdef profile}
  155. profile,
  156. {$endif profile}
  157. {$ifndef NOCATCH}
  158. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  159. catch,
  160. {$endif}
  161. {$endif NOCATCH}
  162. globals,compiler;
  163. var
  164. oldexit : pointer;
  165. procedure myexit;
  166. begin
  167. exitproc:=oldexit;
  168. {$ifdef nocatch}
  169. exit;
  170. {$endif nocatch}
  171. { Show Runtime error if there was an error }
  172. if (erroraddr<>nil) then
  173. begin
  174. case exitcode of
  175. 100:
  176. begin
  177. erroraddr:=nil;
  178. writeln('Error while reading file');
  179. end;
  180. 101:
  181. begin
  182. erroraddr:=nil;
  183. writeln('Error while writing file');
  184. end;
  185. 202:
  186. begin
  187. erroraddr:=nil;
  188. writeln('Error: Stack Overflow');
  189. end;
  190. 203:
  191. begin
  192. erroraddr:=nil;
  193. writeln('Error: Out of memory');
  194. end;
  195. end;
  196. { we cannot use current_filepos.file because all memory might have been
  197. freed already !
  198. But we can use global parser_current_file var }
  199. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  200. end;
  201. end;
  202. begin
  203. oldexit:=exitproc;
  204. exitproc:=@myexit;
  205. {$ifdef extheaptrc}
  206. keepreleased:=true;
  207. {$endif extheaptrc}
  208. { Call the compiler with empty command, so it will take the parameters }
  209. Halt(compiler.Compile(''));
  210. end.