pp.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. {$ifndef CPUDEFINED}
  114. {$fatal A CPU type switch must be defined}
  115. {$endif CPUDEFINED}
  116. {$ifdef support_mmx}
  117. {$ifndef i386}
  118. {$fatal I386 switch must be on for MMX support}
  119. {$endif i386}
  120. {$endif support_mmx}
  121. {$endif}
  122. uses
  123. {$ifdef cmem}
  124. cmem,
  125. {$endif cmem}
  126. {$ifdef FPC}
  127. {$ifdef profile}
  128. profile,
  129. {$endif profile}
  130. {$ifndef NOCATCH}
  131. {$ifdef Unix}
  132. catch,
  133. {$endif}
  134. {$ifdef go32v2}
  135. catch,
  136. {$endif}
  137. {$ifdef WATCOM}
  138. catch,
  139. {$endif}
  140. {$endif NOCATCH}
  141. {$endif FPC}
  142. globals,compiler;
  143. var
  144. oldexit : pointer;
  145. procedure myexit;
  146. begin
  147. exitproc:=oldexit;
  148. {$ifdef nocatch}
  149. exit;
  150. {$endif nocatch}
  151. { Show Runtime error if there was an error }
  152. if (erroraddr<>nil) then
  153. begin
  154. case exitcode of
  155. 100:
  156. begin
  157. erroraddr:=nil;
  158. writeln('Error while reading file');
  159. end;
  160. 101:
  161. begin
  162. erroraddr:=nil;
  163. writeln('Error while writing file');
  164. end;
  165. 202:
  166. begin
  167. erroraddr:=nil;
  168. writeln('Error: Stack Overflow');
  169. end;
  170. 203:
  171. begin
  172. erroraddr:=nil;
  173. writeln('Error: Out of memory');
  174. end;
  175. end;
  176. { we cannot use aktfilepos.file because all memory might have been
  177. freed already !
  178. But we can use global parser_current_file var }
  179. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  180. end;
  181. end;
  182. begin
  183. oldexit:=exitproc;
  184. exitproc:=@myexit;
  185. {$ifdef extheaptrc}
  186. keepreleased:=true;
  187. {$endif extheaptrc}
  188. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  189. exOverflow, exUnderflow, exPrecision]);
  190. { Call the compiler with empty command, so it will take the parameters }
  191. Halt(compiler.Compile(''));
  192. end.
  193. {
  194. $Log$
  195. Revision 1.33 2004-06-20 08:55:30 florian
  196. * logs truncated
  197. Revision 1.32 2004/06/16 20:07:09 florian
  198. * dwarf branch merged
  199. Revision 1.31 2004/05/23 16:46:39 peter
  200. * checkmem remvoed
  201. Revision 1.30.2.1 2004/05/16 10:38:56 peter
  202. * checkmem removed
  203. Revision 1.30 2004/03/20 20:55:36 florian
  204. + implemented cdecl'd varargs on arm
  205. + -dCMEM supported by the compiler
  206. * label/goto asmsymbol type with -dextdebug fixed
  207. Revision 1.29 2004/01/26 17:39:12 florian
  208. * when compiled with -dnocatch, known rtes aren't translated anymore
  209. and a stack dump is written
  210. }