pp.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 (* marks a currently required switch):
  20. -----------------------------------------------------------------
  21. GDB* support of the GNU Debugger
  22. CMEM use cmem unit for better memory debugging
  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. 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. NOAG386INT no Intel Assembler output
  37. NOAG386NSM no NASM output
  38. NOAG386BIN leaves out the binary writer, default for TP
  39. NORA386DIR No direct i386 assembler reader
  40. TEST_GENERIC Test Generic version of code generator
  41. (uses generic RTL calls)
  42. -----------------------------------------------------------------
  43. cpuflags The target processor has status flags (on by default)
  44. cpufpemu The target compiler will also support emitting software
  45. floating point operations
  46. cpu64bit The target is a 64-bit processor
  47. -----------------------------------------------------------------
  48. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  49. GDB;I386
  50. }
  51. {$i fpcdefs.inc}
  52. {$ifdef FPC}
  53. {$ifndef GDB}
  54. { people can try to compile without GDB }
  55. { $error The compiler switch GDB must be defined}
  56. {$endif GDB}
  57. { exactly one target CPU must be defined }
  58. {$ifdef I386}
  59. {$ifdef CPUDEFINED}
  60. {$fatal ONLY one of the switches for the CPU type must be defined}
  61. {$endif CPUDEFINED}
  62. {$define CPUDEFINED}
  63. {$endif I386}
  64. {$ifdef x86_64}
  65. {$ifdef CPUDEFINED}
  66. {$fatal ONLY one of the switches for the CPU type must be defined}
  67. {$endif CPUDEFINED}
  68. {$define CPUDEFINED}
  69. {$endif x86_64}
  70. {$ifdef M68K}
  71. {$ifdef CPUDEFINED}
  72. {$fatal ONLY one of the switches for the CPU type must be defined}
  73. {$endif CPUDEFINED}
  74. {$define CPUDEFINED}
  75. {$endif M68K}
  76. {$ifdef vis}
  77. {$ifdef CPUDEFINED}
  78. {$fatal ONLY one of the switches for the CPU type must be defined}
  79. {$endif CPUDEFINED}
  80. {$define CPUDEFINED}
  81. {$endif}
  82. {$ifdef iA64}
  83. {$ifdef CPUDEFINED}
  84. {$fatal ONLY one of the switches for the CPU type must be defined}
  85. {$endif CPUDEFINED}
  86. {$define CPUDEFINED}
  87. {$endif iA64}
  88. {$ifdef POWERPC}
  89. {$ifdef CPUDEFINED}
  90. {$fatal ONLY one of the switches for the CPU type must be defined}
  91. {$endif CPUDEFINED}
  92. {$define CPUDEFINED}
  93. {$endif POWERPC}
  94. {$ifdef ALPHA}
  95. {$ifdef CPUDEFINED}
  96. {$fatal ONLY one of the switches for the CPU type must be defined}
  97. {$endif CPUDEFINED}
  98. {$define CPUDEFINED}
  99. {$endif ALPHA}
  100. {$ifdef SPARC}
  101. {$ifdef CPUDEFINED}
  102. {$fatal ONLY one of the switches for the CPU type must be defined}
  103. {$endif CPUDEFINED}
  104. {$define CPUDEFINED}
  105. {$endif SPARC}
  106. {$ifdef ARM}
  107. {$ifdef CPUDEFINED}
  108. {$fatal ONLY one of the switches for the CPU type must be defined}
  109. {$endif CPUDEFINED}
  110. {$define CPUDEFINED}
  111. {$endif ARM}
  112. {$ifdef MIPS}
  113. {$ifdef CPUDEFINED}
  114. {$fatal ONLY one of the switches for the CPU type must be defined}
  115. {$endif CPUDEFINED}
  116. {$define CPUDEFINED}
  117. {$endif MIPS}
  118. {$ifndef CPUDEFINED}
  119. {$fatal A CPU type switch must be defined}
  120. {$endif CPUDEFINED}
  121. {$ifdef support_mmx}
  122. {$ifndef i386}
  123. {$fatal I386 switch must be on for MMX support}
  124. {$endif i386}
  125. {$endif support_mmx}
  126. {$endif}
  127. uses
  128. {$ifdef cmem}
  129. cmem,
  130. {$endif cmem}
  131. {$ifdef FPC}
  132. {$ifdef profile}
  133. profile,
  134. {$endif profile}
  135. {$ifndef NOCATCH}
  136. {$ifdef Unix}
  137. catch,
  138. {$endif}
  139. {$ifdef go32v2}
  140. catch,
  141. {$endif}
  142. {$ifdef WATCOM}
  143. catch,
  144. {$endif}
  145. {$endif NOCATCH}
  146. {$endif FPC}
  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 aktfilepos.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,':',aktfilepos.line);
  185. end;
  186. end;
  187. begin
  188. oldexit:=exitproc;
  189. exitproc:=@myexit;
  190. {$ifdef extheaptrc}
  191. keepreleased:=true;
  192. {$endif extheaptrc}
  193. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  194. exOverflow, exUnderflow, exPrecision]);
  195. { Call the compiler with empty command, so it will take the parameters }
  196. Halt(compiler.Compile(''));
  197. end.