pp.pas 8.4 KB

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