pp.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. {$ifdef nocatch}
  148. exit;
  149. {$endif nocatch}
  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. {$ifdef extheaptrc}
  185. keepreleased:=true;
  186. {$endif extheaptrc}
  187. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  188. exOverflow, exUnderflow, exPrecision]);
  189. { Call the compiler with empty command, so it will take the parameters }
  190. Halt(compiler.Compile(''));
  191. end.
  192. {
  193. $Log$
  194. Revision 1.29 2004-01-26 17:39:12 florian
  195. * when compiled with -dnocatch, known rtes aren't translated anymore
  196. and a stack dump is written
  197. Revision 1.28 2003/12/06 01:15:22 florian
  198. * reverted Peter's alloctemp patch; hopefully properly
  199. Revision 1.27 2003/09/06 16:47:24 florian
  200. + support of NaN and Inf in the compiler as values of real constants
  201. Revision 1.26 2003/09/05 17:41:12 florian
  202. * merged Wiktor's Watcom patches in 1.1
  203. Revision 1.25 2003/09/03 11:18:37 florian
  204. * fixed arm concatcopy
  205. + arm support in the common compiler sources added
  206. * moved some generic cg code around
  207. + tfputype added
  208. * ...
  209. Revision 1.24 2003/07/07 19:59:41 peter
  210. * Fix halt() call
  211. Revision 1.23 2003/07/06 15:31:21 daniel
  212. * Fixed register allocator. *Lots* of fixes.
  213. Revision 1.22 2003/04/22 14:33:38 peter
  214. * removed some notes/hints
  215. Revision 1.21 2003/02/15 22:25:50 carl
  216. + give more information on some new defines
  217. Revision 1.20 2003/02/02 19:25:54 carl
  218. * Several bugfixes for m68k target (register alloc., opcode emission)
  219. + VIS target
  220. + Generic add more complete (still not verified)
  221. Revision 1.19 2002/11/15 01:58:53 peter
  222. * merged changes from 1.0.7 up to 04-11
  223. - -V option for generating bug report tracing
  224. - more tracing for option parsing
  225. - errors for cdecl and high()
  226. - win32 import stabs
  227. - win32 records<=8 are returned in eax:edx (turned off by default)
  228. - heaptrc update
  229. - more info for temp management in .s file with EXTDEBUG
  230. Revision 1.18 2002/10/30 21:45:02 peter
  231. * do not include catch unit when compiling with NOCATCH
  232. Revision 1.17 2002/10/15 18:16:44 peter
  233. * GDB switch is not required
  234. Revision 1.16 2002/08/23 13:17:59 mazen
  235. *** empty log message ***
  236. Revision 1.15 2002/07/04 20:43:01 florian
  237. * first x86-64 patches
  238. Revision 1.14 2002/05/22 19:02:16 carl
  239. + generic FPC_HELP_FAIL
  240. + generic FPC_HELP_DESTRUCTOR instated (original from Pierre)
  241. + generic FPC_DISPOSE_CLASS
  242. + TEST_GENERIC define
  243. Revision 1.13 2002/05/18 13:34:13 peter
  244. * readded missing revisions
  245. Revision 1.12 2002/05/16 19:46:43 carl
  246. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  247. + try to fix temp allocation (still in ifdef)
  248. + generic constructor calls
  249. + start of tassembler / tmodulebase class cleanup
  250. Revision 1.10 2002/03/24 19:06:29 carl
  251. + patch for SPARC from Mazen NEIFER
  252. }