pp.pas 6.1 KB

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