pp.pas 6.7 KB

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