pp.pas 9.1 KB

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