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. FPC_ARMHF create an armhf (eabi vfp variant) compiler
  41. -----------------------------------------------------------------
  42. cpuflags The target processor has status flags (on by default)
  43. cpufpemu The target compiler will also support emitting software
  44. floating point operations
  45. cpu64bitaddr Generate code for a 64-bit address space
  46. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  47. (required for cpu64bitaddr; optional with 32 bit addr space)
  48. -----------------------------------------------------------------
  49. }
  50. {$i fpcdefs.inc}
  51. { Require at least 2.0.2 }
  52. {$ifdef VER2_0}
  53. {$if FPC_PATCH<2}
  54. {$fatal At least FPC 2.0.2 is required to compile the compiler}
  55. {$endif}
  56. {$endif VER2_0}
  57. { exactly one target CPU must be defined }
  58. {$ifdef I386}
  59. {$ifdef CPUDEFINED}
  60. {$fatal ONLY one of the switches for the CPU type must be defined}
  61. {$endif CPUDEFINED}
  62. {$define CPUDEFINED}
  63. {$endif I386}
  64. {$ifdef x86_64}
  65. {$ifdef CPUDEFINED}
  66. {$fatal ONLY one of the switches for the CPU type must be defined}
  67. {$endif CPUDEFINED}
  68. {$define CPUDEFINED}
  69. {$endif x86_64}
  70. {$ifdef M68K}
  71. {$ifdef CPUDEFINED}
  72. {$fatal ONLY one of the switches for the CPU type must be defined}
  73. {$endif CPUDEFINED}
  74. {$define CPUDEFINED}
  75. {$endif M68K}
  76. {$ifdef vis}
  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}
  82. {$ifdef iA64}
  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 iA64}
  88. {$ifdef POWERPC}
  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 POWERPC}
  94. {$ifdef POWERPC64}
  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 POWERPC64}
  100. {$ifdef ALPHA}
  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 ALPHA}
  106. {$ifdef SPARC}
  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 SPARC}
  112. {$ifdef ARM}
  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 ARM}
  118. {$ifdef MIPS}
  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 MIPS}
  124. {$ifdef AVR}
  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 AVR}
  130. {$ifndef CPUDEFINED}
  131. {$fatal A CPU type switch must be defined}
  132. {$endif CPUDEFINED}
  133. {$ifdef support_mmx}
  134. {$ifndef i386}
  135. {$fatal I386 switch must be on for MMX support}
  136. {$endif i386}
  137. {$endif support_mmx}
  138. { Don't care about minstacksize or maxstacksize not beeing supported by current OS }
  139. {$WARN 2077 OFF}
  140. {$WARN 2078 OFF}
  141. {$ifdef win32}
  142. { 256 MB stack }
  143. { under windows the stack can't grow }
  144. {$MAXSTACKSIZE 256000000}
  145. {$else win32}
  146. {$ifdef win64}
  147. { 512 MB stack }
  148. { under windows the stack can't grow }
  149. {$MAXSTACKSIZE 512000000}
  150. {$else win64}
  151. { 1 MB stack }
  152. {$MINSTACKSIZE 1000000}
  153. {$endif win64}
  154. {$endif win32}
  155. uses
  156. {$ifdef cmem}
  157. cmem,
  158. {$endif cmem}
  159. {$ifdef profile}
  160. profile,
  161. {$endif profile}
  162. {$ifndef NOCATCH}
  163. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  164. catch,
  165. {$endif}
  166. {$endif NOCATCH}
  167. globals,compiler;
  168. var
  169. oldexit : pointer;
  170. procedure myexit;
  171. begin
  172. exitproc:=oldexit;
  173. {$ifdef nocatch}
  174. exit;
  175. {$endif nocatch}
  176. { Show Runtime error if there was an error }
  177. if (erroraddr<>nil) then
  178. begin
  179. case exitcode of
  180. 100:
  181. begin
  182. erroraddr:=nil;
  183. writeln('Error while reading file');
  184. end;
  185. 101:
  186. begin
  187. erroraddr:=nil;
  188. writeln('Error while writing file');
  189. end;
  190. 202:
  191. begin
  192. erroraddr:=nil;
  193. writeln('Error: Stack Overflow');
  194. end;
  195. 203:
  196. begin
  197. erroraddr:=nil;
  198. writeln('Error: Out of memory');
  199. end;
  200. end;
  201. { we cannot use current_filepos.file because all memory might have been
  202. freed already !
  203. But we can use global parser_current_file var }
  204. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  205. end;
  206. end;
  207. begin
  208. oldexit:=exitproc;
  209. exitproc:=@myexit;
  210. {$ifdef extheaptrc}
  211. keepreleased:=true;
  212. {$endif extheaptrc}
  213. { Call the compiler with empty command, so it will take the parameters }
  214. Halt(compiler.Compile(''));
  215. end.