pp.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. {$ifndef CPUDEFINED}
  130. {$fatal A CPU type switch must be defined}
  131. {$endif CPUDEFINED}
  132. {$ifdef support_mmx}
  133. {$ifndef i386}
  134. {$fatal I386 switch must be on for MMX support}
  135. {$endif i386}
  136. {$endif support_mmx}
  137. { Don't care about minstacksize or maxstacksize not beeing supported by current OS }
  138. {$WARN 2077 OFF}
  139. {$WARN 2078 OFF}
  140. {$ifdef win32}
  141. { 256 MB stack }
  142. { under windows the stack can't grow }
  143. {$MAXSTACKSIZE 256000000}
  144. {$else win32}
  145. {$ifdef win64}
  146. { 512 MB stack }
  147. { under windows the stack can't grow }
  148. {$MAXSTACKSIZE 512000000}
  149. {$else win64}
  150. { 1 MB stack }
  151. {$MINSTACKSIZE 1000000}
  152. {$endif win64}
  153. {$endif win32}
  154. uses
  155. {$ifdef cmem}
  156. cmem,
  157. {$endif cmem}
  158. {$ifdef profile}
  159. profile,
  160. {$endif profile}
  161. {$ifndef NOCATCH}
  162. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  163. catch,
  164. {$endif}
  165. {$endif NOCATCH}
  166. globals,compiler;
  167. var
  168. oldexit : pointer;
  169. procedure myexit;
  170. begin
  171. exitproc:=oldexit;
  172. {$ifdef nocatch}
  173. exit;
  174. {$endif nocatch}
  175. { Show Runtime error if there was an error }
  176. if (erroraddr<>nil) then
  177. begin
  178. case exitcode of
  179. 100:
  180. begin
  181. erroraddr:=nil;
  182. writeln('Error while reading file');
  183. end;
  184. 101:
  185. begin
  186. erroraddr:=nil;
  187. writeln('Error while writing file');
  188. end;
  189. 202:
  190. begin
  191. erroraddr:=nil;
  192. writeln('Error: Stack Overflow');
  193. end;
  194. 203:
  195. begin
  196. erroraddr:=nil;
  197. writeln('Error: Out of memory');
  198. end;
  199. end;
  200. { we cannot use current_filepos.file because all memory might have been
  201. freed already !
  202. But we can use global parser_current_file var }
  203. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  204. end;
  205. end;
  206. begin
  207. oldexit:=exitproc;
  208. exitproc:=@myexit;
  209. {$ifdef extheaptrc}
  210. keepreleased:=true;
  211. {$endif extheaptrc}
  212. { Call the compiler with empty command, so it will take the parameters }
  213. Halt(compiler.Compile(''));
  214. end.