pp.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. {$ifdef FPC}
  49. { exactly one target CPU must be defined }
  50. {$ifdef I386}
  51. {$ifdef CPUDEFINED}
  52. {$fatal ONLY one of the switches for the CPU type must be defined}
  53. {$endif CPUDEFINED}
  54. {$define CPUDEFINED}
  55. {$endif I386}
  56. {$ifdef x86_64}
  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 x86_64}
  62. {$ifdef M68K}
  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 M68K}
  68. {$ifdef vis}
  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}
  74. {$ifdef iA64}
  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 iA64}
  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 ALPHA}
  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 ALPHA}
  98. {$ifdef SPARC}
  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 SPARC}
  104. {$ifdef ARM}
  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 ARM}
  110. {$ifdef MIPS}
  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 MIPS}
  116. {$ifndef CPUDEFINED}
  117. {$fatal A CPU type switch must be defined}
  118. {$endif CPUDEFINED}
  119. {$ifdef support_mmx}
  120. {$ifndef i386}
  121. {$fatal I386 switch must be on for MMX support}
  122. {$endif i386}
  123. {$endif support_mmx}
  124. {$endif}
  125. uses
  126. {$ifdef cmem}
  127. cmem,
  128. {$endif cmem}
  129. {$ifdef FPC}
  130. {$ifdef profile}
  131. profile,
  132. {$endif profile}
  133. {$ifndef NOCATCH}
  134. {$ifdef Unix}
  135. catch,
  136. {$endif}
  137. {$ifdef go32v2}
  138. catch,
  139. {$endif}
  140. {$ifdef WATCOM}
  141. catch,
  142. {$endif}
  143. {$endif NOCATCH}
  144. {$endif FPC}
  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 aktfilepos.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,':',aktfilepos.line);
  183. end;
  184. end;
  185. begin
  186. oldexit:=exitproc;
  187. exitproc:=@myexit;
  188. {$ifdef extheaptrc}
  189. keepreleased:=true;
  190. {$endif extheaptrc}
  191. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  192. exOverflow, exUnderflow, exPrecision]);
  193. { Call the compiler with empty command, so it will take the parameters }
  194. Halt(compiler.Compile(''));
  195. end.