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