pp.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_ARMEB create an arm big endian compiler
  38. FPC_OARM create an arm oabi compiler, only needed when the host
  39. compiler is ARMEL or ARMEB
  40. -----------------------------------------------------------------
  41. cpuflags The target processor has status flags (on by default)
  42. cpufpemu The target compiler will also support emitting software
  43. floating point operations
  44. cpu64bitaddr Generate code for a 64-bit address space
  45. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  46. (required for cpu64bitaddr; optional with 32 bit addr space)
  47. -----------------------------------------------------------------
  48. }
  49. {$i fpcdefs.inc}
  50. { Require at least 2.0.2 }
  51. {$ifdef VER2_0}
  52. {$if FPC_PATCH<2}
  53. {$fatal At least FPC 2.0.2 is required to compile the compiler}
  54. {$endif}
  55. {$endif VER2_0}
  56. { exactly one target CPU must be defined }
  57. {$ifdef I386}
  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 I386}
  63. {$ifdef x86_64}
  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 x86_64}
  69. {$ifdef M68K}
  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 M68K}
  75. {$ifdef vis}
  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}
  81. {$ifdef iA64}
  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 iA64}
  87. {$ifdef POWERPC}
  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 POWERPC}
  93. {$ifdef POWERPC64}
  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 POWERPC64}
  99. {$ifdef ALPHA}
  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 ALPHA}
  105. {$ifdef SPARC}
  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 SPARC}
  111. {$ifdef ARM}
  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 ARM}
  117. {$ifdef MIPS}
  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 MIPS}
  123. {$ifdef AVR}
  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 AVR}
  129. {$ifdef AVR32}
  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 AVR32}
  135. {$ifndef CPUDEFINED}
  136. {$fatal A CPU type switch must be defined}
  137. {$endif CPUDEFINED}
  138. {$ifdef support_mmx}
  139. {$ifndef i386}
  140. {$fatal I386 switch must be on for MMX support}
  141. {$endif i386}
  142. {$endif support_mmx}
  143. {$ifdef win32}
  144. { 256 MB stack }
  145. { under windows the stack can't grow }
  146. {$MAXSTACKSIZE 256000000}
  147. {$else win32}
  148. {$ifdef win64}
  149. { 512 MB stack }
  150. { under windows the stack can't grow }
  151. {$MAXSTACKSIZE 512000000}
  152. {$else win64}
  153. { 1 MB stack }
  154. {$MINSTACKSIZE 1000000}
  155. {$endif win64}
  156. {$endif win32}
  157. uses
  158. {$ifdef cmem}
  159. cmem,
  160. {$endif cmem}
  161. {$ifdef profile}
  162. profile,
  163. {$endif profile}
  164. {$ifndef NOCATCH}
  165. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  166. catch,
  167. {$endif}
  168. {$endif NOCATCH}
  169. globals,compiler;
  170. var
  171. oldexit : pointer;
  172. procedure myexit;
  173. begin
  174. exitproc:=oldexit;
  175. {$ifdef nocatch}
  176. exit;
  177. {$endif nocatch}
  178. { Show Runtime error if there was an error }
  179. if (erroraddr<>nil) then
  180. begin
  181. case exitcode of
  182. 100:
  183. begin
  184. erroraddr:=nil;
  185. writeln('Error while reading file');
  186. end;
  187. 101:
  188. begin
  189. erroraddr:=nil;
  190. writeln('Error while writing file');
  191. end;
  192. 202:
  193. begin
  194. erroraddr:=nil;
  195. writeln('Error: Stack Overflow');
  196. end;
  197. 203:
  198. begin
  199. erroraddr:=nil;
  200. writeln('Error: Out of memory');
  201. end;
  202. end;
  203. { we cannot use current_filepos.file because all memory might have been
  204. freed already !
  205. But we can use global parser_current_file var }
  206. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  207. end;
  208. end;
  209. begin
  210. oldexit:=exitproc;
  211. exitproc:=@myexit;
  212. {$ifdef extheaptrc}
  213. keepreleased:=true;
  214. {$endif extheaptrc}
  215. { Call the compiler with empty command, so it will take the parameters }
  216. Halt(compiler.Compile(''));
  217. end.