pp.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. {$ifndef CPUDEFINED}
  107. {$fatal A CPU type switch must be defined}
  108. {$endif CPUDEFINED}
  109. {$ifdef support_mmx}
  110. {$ifndef i386}
  111. {$fatal I386 switch must be on for MMX support}
  112. {$endif i386}
  113. {$endif support_mmx}
  114. {$endif}
  115. uses
  116. {$ifdef FPC}
  117. {$ifdef profile}
  118. profile,
  119. {$endif profile}
  120. {$ifdef heaptrc}
  121. ppheap,
  122. {$endif heaptrc}
  123. {$ifdef EXTDEBUG}
  124. checkmem,
  125. {$endif EXTDEBUG}
  126. {$ifndef NOCATCH}
  127. {$ifdef Unix}
  128. catch,
  129. {$endif}
  130. {$ifdef go32v2}
  131. catch,
  132. {$endif}
  133. {$endif NOCATCH}
  134. {$endif FPC}
  135. globals,compiler;
  136. var
  137. oldexit : pointer;
  138. procedure myexit;
  139. begin
  140. exitproc:=oldexit;
  141. { Show Runtime error if there was an error }
  142. if (erroraddr<>nil) then
  143. begin
  144. case exitcode of
  145. 100:
  146. begin
  147. erroraddr:=nil;
  148. writeln('Error while reading file');
  149. end;
  150. 101:
  151. begin
  152. erroraddr:=nil;
  153. writeln('Error while writing file');
  154. end;
  155. 202:
  156. begin
  157. erroraddr:=nil;
  158. writeln('Error: Stack Overflow');
  159. end;
  160. 203:
  161. begin
  162. erroraddr:=nil;
  163. writeln('Error: Out of memory');
  164. end;
  165. end;
  166. { we cannot use aktfilepos.file because all memory might have been
  167. freed already !
  168. But we can use global parser_current_file var }
  169. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  170. end;
  171. end;
  172. begin
  173. oldexit:=exitproc;
  174. exitproc:=@myexit;
  175. { Call the compiler with empty command, so it will take the parameters }
  176. Halt(compiler.Compile(''));
  177. end.
  178. {
  179. $Log$
  180. Revision 1.21 2003-02-15 22:25:50 carl
  181. + give more information on some new defines
  182. Revision 1.20 2003/02/02 19:25:54 carl
  183. * Several bugfixes for m68k target (register alloc., opcode emission)
  184. + VIS target
  185. + Generic add more complete (still not verified)
  186. Revision 1.19 2002/11/15 01:58:53 peter
  187. * merged changes from 1.0.7 up to 04-11
  188. - -V option for generating bug report tracing
  189. - more tracing for option parsing
  190. - errors for cdecl and high()
  191. - win32 import stabs
  192. - win32 records<=8 are returned in eax:edx (turned off by default)
  193. - heaptrc update
  194. - more info for temp management in .s file with EXTDEBUG
  195. Revision 1.18 2002/10/30 21:45:02 peter
  196. * do not include catch unit when compiling with NOCATCH
  197. Revision 1.17 2002/10/15 18:16:44 peter
  198. * GDB switch is not required
  199. Revision 1.16 2002/08/23 13:17:59 mazen
  200. *** empty log message ***
  201. Revision 1.15 2002/07/04 20:43:01 florian
  202. * first x86-64 patches
  203. Revision 1.14 2002/05/22 19:02:16 carl
  204. + generic FPC_HELP_FAIL
  205. + generic FPC_HELP_DESTRUCTOR instated (original from Pierre)
  206. + generic FPC_DISPOSE_CLASS
  207. + TEST_GENERIC define
  208. Revision 1.13 2002/05/18 13:34:13 peter
  209. * readded missing revisions
  210. Revision 1.12 2002/05/16 19:46:43 carl
  211. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  212. + try to fix temp allocation (still in ifdef)
  213. + generic constructor calls
  214. + start of tassembler / tmodulebase class cleanup
  215. Revision 1.10 2002/03/24 19:06:29 carl
  216. + patch for SPARC from Mazen NEIFER
  217. }