pp.pas 6.1 KB

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