pp.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. cpu64bitaddr Generate code for a 64-bit address space
  43. cpu64bitalu The target cpu has 64-bit registers and a 64 bit alu
  44. (required for cpu64bitaddr; optional with 32 bit addr space)
  45. -----------------------------------------------------------------
  46. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  47. I386
  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. uses
  138. {$ifdef cmem}
  139. cmem,
  140. {$endif cmem}
  141. {$ifdef profile}
  142. profile,
  143. {$endif profile}
  144. {$ifndef NOCATCH}
  145. {$if defined(Unix) or defined(Go32v2) or defined(Watcom)}
  146. catch,
  147. {$endif}
  148. {$endif NOCATCH}
  149. globals,compiler;
  150. var
  151. oldexit : pointer;
  152. procedure myexit;
  153. begin
  154. exitproc:=oldexit;
  155. {$ifdef nocatch}
  156. exit;
  157. {$endif nocatch}
  158. { Show Runtime error if there was an error }
  159. if (erroraddr<>nil) then
  160. begin
  161. case exitcode of
  162. 100:
  163. begin
  164. erroraddr:=nil;
  165. writeln('Error while reading file');
  166. end;
  167. 101:
  168. begin
  169. erroraddr:=nil;
  170. writeln('Error while writing file');
  171. end;
  172. 202:
  173. begin
  174. erroraddr:=nil;
  175. writeln('Error: Stack Overflow');
  176. end;
  177. 203:
  178. begin
  179. erroraddr:=nil;
  180. writeln('Error: Out of memory');
  181. end;
  182. end;
  183. { we cannot use current_filepos.file because all memory might have been
  184. freed already !
  185. But we can use global parser_current_file var }
  186. Writeln('Compilation aborted ',parser_current_file,':',current_filepos.line);
  187. end;
  188. end;
  189. begin
  190. oldexit:=exitproc;
  191. exitproc:=@myexit;
  192. {$ifdef extheaptrc}
  193. keepreleased:=true;
  194. {$endif extheaptrc}
  195. { Call the compiler with empty command, so it will take the parameters }
  196. Halt(compiler.Compile(''));
  197. end.