pp.pas 6.8 KB

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