pp.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Commandline compiler for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. program pp;
  18. {
  19. possible compiler switches:
  20. -----------------------------------------------------------------
  21. CMEM use cmem unit for better memory debugging
  22. I386 generate a compiler for the Intel i386+
  23. x86_64 generate a compiler for the AMD x86-64 architecture
  24. M68K generate a compiler for the M68000
  25. SPARC generate a compiler for SPARC
  26. POWERPC generate a compiler for the PowerPC
  27. POWERPC64 generate a compiler for the PowerPC64 architecture
  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. TEST_GENERIC Test Generic version of code generator
  37. (uses generic RTL calls)
  38. -----------------------------------------------------------------
  39. cpuflags The target processor has status flags (on by default)
  40. cpufpemu The target compiler will also support emitting software
  41. floating point operations
  42. cpu64bit The target is a 64-bit processor
  43. -----------------------------------------------------------------
  44. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  45. I386
  46. }
  47. {$i fpcdefs.inc}
  48. {$ifdef FPC}
  49. { exactly one target CPU must be defined }
  50. {$ifdef I386}
  51. {$ifdef CPUDEFINED}
  52. {$fatal ONLY one of the switches for the CPU type must be defined}
  53. {$endif CPUDEFINED}
  54. {$define CPUDEFINED}
  55. {$endif I386}
  56. {$ifdef x86_64}
  57. {$ifdef CPUDEFINED}
  58. {$fatal ONLY one of the switches for the CPU type must be defined}
  59. {$endif CPUDEFINED}
  60. {$define CPUDEFINED}
  61. {$endif x86_64}
  62. {$ifdef M68K}
  63. {$ifdef CPUDEFINED}
  64. {$fatal ONLY one of the switches for the CPU type must be defined}
  65. {$endif CPUDEFINED}
  66. {$define CPUDEFINED}
  67. {$endif M68K}
  68. {$ifdef vis}
  69. {$ifdef CPUDEFINED}
  70. {$fatal ONLY one of the switches for the CPU type must be defined}
  71. {$endif CPUDEFINED}
  72. {$define CPUDEFINED}
  73. {$endif}
  74. {$ifdef iA64}
  75. {$ifdef CPUDEFINED}
  76. {$fatal ONLY one of the switches for the CPU type must be defined}
  77. {$endif CPUDEFINED}
  78. {$define CPUDEFINED}
  79. {$endif iA64}
  80. {$ifdef POWERPC}
  81. {$ifdef CPUDEFINED}
  82. {$fatal ONLY one of the switches for the CPU type must be defined}
  83. {$endif CPUDEFINED}
  84. {$define CPUDEFINED}
  85. {$endif POWERPC}
  86. {$ifdef POWERPC64}
  87. {$ifdef CPUDEFINED}
  88. {$fatal ONLY one of the switches for the CPU type must be defined}
  89. {$endif CPUDEFINED}
  90. {$define CPUDEFINED}
  91. {$endif POWERPC64}
  92. {$ifdef ALPHA}
  93. {$ifdef CPUDEFINED}
  94. {$fatal ONLY one of the switches for the CPU type must be defined}
  95. {$endif CPUDEFINED}
  96. {$define CPUDEFINED}
  97. {$endif ALPHA}
  98. {$ifdef SPARC}
  99. {$ifdef CPUDEFINED}
  100. {$fatal ONLY one of the switches for the CPU type must be defined}
  101. {$endif CPUDEFINED}
  102. {$define CPUDEFINED}
  103. {$endif SPARC}
  104. {$ifdef ARM}
  105. {$ifdef CPUDEFINED}
  106. {$fatal ONLY one of the switches for the CPU type must be defined}
  107. {$endif CPUDEFINED}
  108. {$define CPUDEFINED}
  109. {$endif ARM}
  110. {$ifdef MIPS}
  111. {$ifdef CPUDEFINED}
  112. {$fatal ONLY one of the switches for the CPU type must be defined}
  113. {$endif CPUDEFINED}
  114. {$define CPUDEFINED}
  115. {$endif MIPS}
  116. {$ifdef AVR}
  117. {$ifdef CPUDEFINED}
  118. {$fatal ONLY one of the switches for the CPU type must be defined}
  119. {$endif CPUDEFINED}
  120. {$define CPUDEFINED}
  121. {$endif AVR}
  122. {$ifndef CPUDEFINED}
  123. {$fatal A CPU type switch must be defined}
  124. {$endif CPUDEFINED}
  125. {$ifdef support_mmx}
  126. {$ifndef i386}
  127. {$fatal I386 switch must be on for MMX support}
  128. {$endif i386}
  129. {$endif support_mmx}
  130. {$endif}
  131. uses
  132. {$ifdef cmem}
  133. cmem,
  134. {$endif cmem}
  135. {$ifdef FPC}
  136. {$ifdef profile}
  137. profile,
  138. {$endif profile}
  139. {$ifndef NOCATCH}
  140. {$ifdef Unix}
  141. catch,
  142. {$endif}
  143. {$ifdef go32v2}
  144. catch,
  145. {$endif}
  146. {$ifdef WATCOM}
  147. catch,
  148. {$endif}
  149. {$endif NOCATCH}
  150. {$endif FPC}
  151. globals,compiler;
  152. var
  153. oldexit : pointer;
  154. procedure myexit;
  155. begin
  156. exitproc:=oldexit;
  157. {$ifdef nocatch}
  158. exit;
  159. {$endif nocatch}
  160. { Show Runtime error if there was an error }
  161. if (erroraddr<>nil) then
  162. begin
  163. case exitcode of
  164. 100:
  165. begin
  166. erroraddr:=nil;
  167. writeln('Error while reading file');
  168. end;
  169. 101:
  170. begin
  171. erroraddr:=nil;
  172. writeln('Error while writing file');
  173. end;
  174. 202:
  175. begin
  176. erroraddr:=nil;
  177. writeln('Error: Stack Overflow');
  178. end;
  179. 203:
  180. begin
  181. erroraddr:=nil;
  182. writeln('Error: Out of memory');
  183. end;
  184. end;
  185. { we cannot use aktfilepos.file because all memory might have been
  186. freed already !
  187. But we can use global parser_current_file var }
  188. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  189. end;
  190. end;
  191. begin
  192. oldexit:=exitproc;
  193. exitproc:=@myexit;
  194. {$ifdef extheaptrc}
  195. keepreleased:=true;
  196. {$endif extheaptrc}
  197. SetFPUExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
  198. exOverflow, exUnderflow, exPrecision]);
  199. { Call the compiler with empty command, so it will take the parameters }
  200. Halt(compiler.Compile(''));
  201. end.