pp.pas 7.0 KB

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