pp.pas 9.0 KB

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