pp.pas 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. 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. {$ifndef CPUDEFINED}
  113. {$fatal A CPU type switch must be defined}
  114. {$endif CPUDEFINED}
  115. {$ifdef support_mmx}
  116. {$ifndef i386}
  117. {$fatal I386 switch must be on for MMX support}
  118. {$endif i386}
  119. {$endif support_mmx}
  120. {$endif}
  121. uses
  122. {$ifdef FPC}
  123. {$ifdef profile}
  124. profile,
  125. {$endif profile}
  126. {$ifdef EXTDEBUG}
  127. checkmem,
  128. {$endif EXTDEBUG}
  129. {$ifndef NOCATCH}
  130. {$ifdef Unix}
  131. catch,
  132. {$endif}
  133. {$ifdef go32v2}
  134. catch,
  135. {$endif}
  136. {$ifdef WATCOM}
  137. catch,
  138. {$endif}
  139. {$endif NOCATCH}
  140. {$endif FPC}
  141. globals,compiler;
  142. var
  143. oldexit : pointer;
  144. procedure myexit;
  145. begin
  146. exitproc:=oldexit;
  147. { Show Runtime error if there was an error }
  148. if (erroraddr<>nil) then
  149. begin
  150. case exitcode of
  151. 100:
  152. begin
  153. erroraddr:=nil;
  154. writeln('Error while reading file');
  155. end;
  156. 101:
  157. begin
  158. erroraddr:=nil;
  159. writeln('Error while writing file');
  160. end;
  161. 202:
  162. begin
  163. erroraddr:=nil;
  164. writeln('Error: Stack Overflow');
  165. end;
  166. 203:
  167. begin
  168. erroraddr:=nil;
  169. writeln('Error: Out of memory');
  170. end;
  171. end;
  172. { we cannot use aktfilepos.file because all memory might have been
  173. freed already !
  174. But we can use global parser_current_file var }
  175. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  176. end;
  177. end;
  178. begin
  179. oldexit:=exitproc;
  180. exitproc:=@myexit;
  181. {$ifdef extheaptrc}
  182. keepreleased:=true;
  183. {$endif extheaptrc}
  184. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  185. exOverflow, exUnderflow, exPrecision]);
  186. { Call the compiler with empty command, so it will take the parameters }
  187. Halt(compiler.Compile(''));
  188. end.
  189. {
  190. $Log$
  191. Revision 1.28 2003-12-06 01:15:22 florian
  192. * reverted Peter's alloctemp patch; hopefully properly
  193. Revision 1.27 2003/09/06 16:47:24 florian
  194. + support of NaN and Inf in the compiler as values of real constants
  195. Revision 1.26 2003/09/05 17:41:12 florian
  196. * merged Wiktor's Watcom patches in 1.1
  197. Revision 1.25 2003/09/03 11:18:37 florian
  198. * fixed arm concatcopy
  199. + arm support in the common compiler sources added
  200. * moved some generic cg code around
  201. + tfputype added
  202. * ...
  203. Revision 1.24 2003/07/07 19:59:41 peter
  204. * Fix halt() call
  205. Revision 1.23 2003/07/06 15:31:21 daniel
  206. * Fixed register allocator. *Lots* of fixes.
  207. Revision 1.22 2003/04/22 14:33:38 peter
  208. * removed some notes/hints
  209. Revision 1.21 2003/02/15 22:25:50 carl
  210. + give more information on some new defines
  211. Revision 1.20 2003/02/02 19:25:54 carl
  212. * Several bugfixes for m68k target (register alloc., opcode emission)
  213. + VIS target
  214. + Generic add more complete (still not verified)
  215. Revision 1.19 2002/11/15 01:58:53 peter
  216. * merged changes from 1.0.7 up to 04-11
  217. - -V option for generating bug report tracing
  218. - more tracing for option parsing
  219. - errors for cdecl and high()
  220. - win32 import stabs
  221. - win32 records<=8 are returned in eax:edx (turned off by default)
  222. - heaptrc update
  223. - more info for temp management in .s file with EXTDEBUG
  224. Revision 1.18 2002/10/30 21:45:02 peter
  225. * do not include catch unit when compiling with NOCATCH
  226. Revision 1.17 2002/10/15 18:16:44 peter
  227. * GDB switch is not required
  228. Revision 1.16 2002/08/23 13:17:59 mazen
  229. *** empty log message ***
  230. Revision 1.15 2002/07/04 20:43:01 florian
  231. * first x86-64 patches
  232. Revision 1.14 2002/05/22 19:02:16 carl
  233. + generic FPC_HELP_FAIL
  234. + generic FPC_HELP_DESTRUCTOR instated (original from Pierre)
  235. + generic FPC_DISPOSE_CLASS
  236. + TEST_GENERIC define
  237. Revision 1.13 2002/05/18 13:34:13 peter
  238. * readded missing revisions
  239. Revision 1.12 2002/05/16 19:46:43 carl
  240. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  241. + try to fix temp allocation (still in ifdef)
  242. + generic constructor calls
  243. + start of tassembler / tmodulebase class cleanup
  244. Revision 1.10 2002/03/24 19:06:29 carl
  245. + patch for SPARC from Mazen NEIFER
  246. }