pp.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Commandline compiler for Free Pascal
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. program pp;
  19. {
  20. possible compiler switches (* marks a currently required switch):
  21. -----------------------------------------------------------------
  22. GDB* support of the GNU Debugger
  23. CMEM use cmem unit for better memory debugging
  24. I386 generate a compiler for the Intel i386+
  25. x86_64 generate a compiler for the AMD x86-64 architecture
  26. M68K generate a compiler for the M68000
  27. SPARC generate a compiler for SPARC
  28. POWERPC generate a compiler for the PowerPC
  29. VIS generate a compile for the VIS
  30. DEBUG version with debug code is generated
  31. EXTDEBUG some extra debug code is executed
  32. SUPPORT_MMX only i386: releases the compiler switch
  33. MMX which allows the compiler to generate
  34. MMX instructions
  35. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  36. use external messagefiles, default for TP
  37. NOAG386INT no Intel Assembler output
  38. NOAG386NSM no NASM output
  39. NOAG386BIN leaves out the binary writer, default for TP
  40. NORA386DIR No direct i386 assembler reader
  41. TEST_GENERIC Test Generic version of code generator
  42. (uses generic RTL calls)
  43. -----------------------------------------------------------------
  44. cpuflags The target processor has status flags (on by default)
  45. cpufpemu The target compiler will also support emitting software
  46. floating point operations
  47. cpu64bit The target is a 64-bit processor
  48. -----------------------------------------------------------------
  49. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  50. GDB;I386
  51. }
  52. {$i fpcdefs.inc}
  53. {$ifdef FPC}
  54. {$ifndef GDB}
  55. { people can try to compile without GDB }
  56. { $error The compiler switch GDB must be defined}
  57. {$endif GDB}
  58. { exactly one target CPU must be defined }
  59. {$ifdef I386}
  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 I386}
  65. {$ifdef x86_64}
  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 x86_64}
  71. {$ifdef M68K}
  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 M68K}
  77. {$ifdef vis}
  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}
  83. {$ifdef iA64}
  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 iA64}
  89. {$ifdef POWERPC}
  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 POWERPC}
  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. {$ifndef CPUDEFINED}
  120. {$fatal A CPU type switch must be defined}
  121. {$endif CPUDEFINED}
  122. {$ifdef support_mmx}
  123. {$ifndef i386}
  124. {$fatal I386 switch must be on for MMX support}
  125. {$endif i386}
  126. {$endif support_mmx}
  127. {$endif}
  128. uses
  129. {$ifdef cmem}
  130. cmem,
  131. {$endif cmem}
  132. {$ifdef FPC}
  133. {$ifdef profile}
  134. profile,
  135. {$endif profile}
  136. {$ifndef NOCATCH}
  137. {$ifdef Unix}
  138. catch,
  139. {$endif}
  140. {$ifdef go32v2}
  141. catch,
  142. {$endif}
  143. {$ifdef WATCOM}
  144. catch,
  145. {$endif}
  146. {$endif NOCATCH}
  147. {$endif FPC}
  148. globals,compiler;
  149. var
  150. oldexit : pointer;
  151. procedure myexit;
  152. begin
  153. exitproc:=oldexit;
  154. {$ifdef nocatch}
  155. exit;
  156. {$endif nocatch}
  157. { Show Runtime error if there was an error }
  158. if (erroraddr<>nil) then
  159. begin
  160. case exitcode of
  161. 100:
  162. begin
  163. erroraddr:=nil;
  164. writeln('Error while reading file');
  165. end;
  166. 101:
  167. begin
  168. erroraddr:=nil;
  169. writeln('Error while writing file');
  170. end;
  171. 202:
  172. begin
  173. erroraddr:=nil;
  174. writeln('Error: Stack Overflow');
  175. end;
  176. 203:
  177. begin
  178. erroraddr:=nil;
  179. writeln('Error: Out of memory');
  180. end;
  181. end;
  182. { we cannot use aktfilepos.file because all memory might have been
  183. freed already !
  184. But we can use global parser_current_file var }
  185. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  186. end;
  187. end;
  188. begin
  189. oldexit:=exitproc;
  190. exitproc:=@myexit;
  191. {$ifdef extheaptrc}
  192. keepreleased:=true;
  193. {$endif extheaptrc}
  194. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  195. exOverflow, exUnderflow, exPrecision]);
  196. { Call the compiler with empty command, so it will take the parameters }
  197. Halt(compiler.Compile(''));
  198. end.
  199. {
  200. $Log$
  201. Revision 1.35 2005-02-14 17:13:07 peter
  202. * truncate log
  203. Revision 1.34 2005/02/13 18:55:19 florian
  204. + overflow checking for the arm
  205. }