pp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. possible compiler switches (* marks a currently required switch):
  19. -----------------------------------------------------------------
  20. USE_RHIDE generates errors and warning in an format recognized
  21. by rhide
  22. TP to compile the compiler with Turbo or Borland Pascal
  23. GDB* support of the GNU Debugger
  24. I386 generate a compiler for the Intel i386+
  25. M68K generate a compiler for the M68000
  26. USEOVERLAY compiles a TP version which uses overlays
  27. EXTDEBUG some extra debug code is executed
  28. SUPPORT_MMX only i386: releases the compiler switch
  29. MMX which allows the compiler to generate
  30. MMX instructions
  31. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  32. use external messagefiles, default for TP
  33. NOAG386INT no Intel Assembler output
  34. NOAG386NSM no NASM output
  35. NOAG386BIN leaves out the binary writer
  36. -----------------------------------------------------------------
  37. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  38. GDB;I386
  39. Required switches for a i386 compiler be compiled by Turbo Pascal:
  40. GDB;I386;TP
  41. Required switches for a 68000 compiler be compiled by Turbo Pascal:
  42. GDB;M68k;TP
  43. }
  44. {$ifdef FPC}
  45. {$ifndef GDB}
  46. { people can try to compile without GDB }
  47. { $error The compiler switch GDB must be defined}
  48. {$endif GDB}
  49. { but I386 or M68K must be defined }
  50. { and only one of the two }
  51. {$ifndef I386}
  52. {$ifndef M68K}
  53. {$fatal One of the switches I386 or M68K must be defined}
  54. {$endif M68K}
  55. {$endif I386}
  56. {$ifdef I386}
  57. {$ifdef M68K}
  58. {$fatal ONLY one of the switches I386 or M68K must be defined}
  59. {$endif M68K}
  60. {$endif I386}
  61. {$ifdef support_mmx}
  62. {$ifndef i386}
  63. {$fatal I386 switch must be on for MMX support}
  64. {$endif i386}
  65. {$endif support_mmx}
  66. {$endif}
  67. {$ifdef TP}
  68. {$IFNDEF DPMI}
  69. {$M 24000,0,655360}
  70. {$ELSE}
  71. {$M 65000}
  72. {$ENDIF DPMI}
  73. {$E+,N+,F+,S-,R-}
  74. {$endif TP}
  75. program pp;
  76. {$IFDEF TP}
  77. {$UNDEF PROFILE}
  78. {$IFDEF DPMI}
  79. {$UNDEF USEOVERLAY}
  80. {$ENDIF}
  81. {$ENDIF}
  82. {$ifdef FPC}
  83. {$UNDEF USEOVERLAY}
  84. {$ENDIF}
  85. uses
  86. {$ifdef useoverlay}
  87. {$ifopt o+}
  88. Overlay,ppovin,
  89. {$else}
  90. {$error You must compile with the $O+ switch}
  91. {$endif}
  92. {$endif useoverlay}
  93. {$ifdef profile}
  94. profile,
  95. {$endif profile}
  96. {$ifdef FPC}
  97. {$ifdef heaptrc}
  98. ppheap,
  99. {$endif heaptrc}
  100. {$ifdef linux}
  101. catch,
  102. {$endif}
  103. {$endif FPC}
  104. globals,compiler
  105. ;
  106. {$ifdef useoverlay}
  107. {$O files}
  108. {$O globals}
  109. {$O hcodegen}
  110. {$O pass_1}
  111. {$O pass_2}
  112. {$O tree}
  113. {$O types}
  114. {$O objects}
  115. {$O options}
  116. {$O cobjects}
  117. {$O globals}
  118. {$O systems}
  119. {$O parser}
  120. {$O pbase}
  121. {$O pdecl}
  122. {$O pexports}
  123. {$O pexpr}
  124. {$O pmodules}
  125. {$O pstatmnt}
  126. {$O psub}
  127. {$O psystem}
  128. {$O ptconst}
  129. {$O script}
  130. {$O switches}
  131. {$O temp_gen}
  132. {$O comphook}
  133. {$O dos}
  134. {$O scanner}
  135. {$O symtable}
  136. {$O objects}
  137. {$O aasm}
  138. {$O link}
  139. {$O assemble}
  140. {$O messages}
  141. {$O gendef}
  142. {$O import}
  143. {$ifdef i386}
  144. {$O os2_targ}
  145. {$O win_targ}
  146. {$endif i386}
  147. {$ifdef gdb}
  148. {$O gdb}
  149. {$endif gdb}
  150. {$ifdef i386}
  151. {$O opts386}
  152. {$O i386base}
  153. {$O cgai386}
  154. {$O tgeni386}
  155. {$O cg386add}
  156. {$O cg386cal}
  157. {$O cg386cnv}
  158. {$O cg386con}
  159. {$O cg386flw}
  160. {$O cg386ld}
  161. {$O cg386inl}
  162. {$O cg386mat}
  163. {$O cg386set}
  164. {$ifndef NOOPT}
  165. {$O aopt386}
  166. {$endif}
  167. {$IfNDef Nora386dir}
  168. {$O ra386dir}
  169. {$endif}
  170. {$IfNDef Nora386int}
  171. {$O ra386int}
  172. {$endif}
  173. {$IfNDef Nora386att}
  174. {$O ra386att}
  175. {$endif}
  176. {$ifndef NoAg386Int}
  177. {$O ag386int}
  178. {$endif}
  179. {$ifndef NoAg386Att}
  180. {$O ag386att}
  181. {$endif}
  182. {$ifndef NoAg386Nsm}
  183. {$O ag386nsm}
  184. {$endif}
  185. {$endif}
  186. {$ifdef m68k}
  187. {$O opts68k}
  188. {$O m68k}
  189. {$O cga68k}
  190. {$O tgen68k}
  191. {$O cg68kadd}
  192. {$O cg68kcal}
  193. {$O cg68kcnv}
  194. {$O cg68kcon}
  195. {$O cg68kflw}
  196. {$O cg68kld}
  197. {$O cg68kinl}
  198. {$O cg68kmat}
  199. {$O cg68kset}
  200. {$IfNDef Nora68kMot}
  201. {$O ra68kmot}
  202. {$endif}
  203. {$IfNDef Noag68kGas}
  204. {$O ag68kgas}
  205. {$endif}
  206. {$IfNDef Noag68kMot}
  207. {$O ag68kmot}
  208. {$endif}
  209. {$IfNDef Noag68kMit}
  210. {$O ag68kmit}
  211. {$endif}
  212. {$endif}
  213. {$endif useoverlay}
  214. var
  215. oldexit : pointer;
  216. procedure myexit;{$ifndef FPC}far;{$endif}
  217. begin
  218. exitproc:=oldexit;
  219. { Show Runtime error if there was an error }
  220. if (erroraddr<>nil) then
  221. begin
  222. case exitcode of
  223. 202 : begin
  224. erroraddr:=nil;
  225. Writeln('Error: Stack Overflow');
  226. end;
  227. 203 : begin
  228. erroraddr:=nil;
  229. Writeln('Error: Out of memory');
  230. end;
  231. end;
  232. { we cannot use aktfilepos.file because all memory might have been
  233. freed already !
  234. But we can use global parser_current_file var }
  235. Writeln('Compilation aborted ',parser_current_file,':',aktfilepos.line);
  236. end;
  237. end;
  238. begin
  239. oldexit:=exitproc;
  240. exitproc:=@myexit;
  241. {$ifdef fpc}
  242. heapblocks:=true;
  243. {$endif}
  244. {$ifdef UseOverlay}
  245. InitOverlay;
  246. {$endif}
  247. { Call the compiler with empty command, so it will take the parameters }
  248. Halt(compiler.Compile(''));
  249. end.
  250. {
  251. $Log$
  252. Revision 1.42 1999-05-12 22:36:11 florian
  253. * override isn't allowed in objects!
  254. Revision 1.41 1999/05/02 09:35:45 florian
  255. + method message handlers which contain an explicit self can't be called
  256. directly anymore
  257. + self is now loaded at the start of the an message handler with an explicit
  258. self
  259. + $useoverlay fixed: i386 was renamed to i386base
  260. Revision 1.40 1999/01/27 13:05:41 pierre
  261. * give include file name on error
  262. Revision 1.39 1999/01/22 12:19:30 pierre
  263. + currently compiled file name added on errors
  264. Revision 1.38 1999/01/19 10:19:03 florian
  265. * bug with mul. of dwords fixed, reported by Alexander Stohr
  266. * some changes to compile with TP
  267. + small enhancements for the new code generator
  268. Revision 1.37 1998/12/16 00:27:21 peter
  269. * removed some obsolete version checks
  270. Revision 1.36 1998/11/27 22:54:52 michael
  271. + Added catch unit again
  272. Revision 1.35 1998/11/05 12:02:53 peter
  273. * released useansistring
  274. * removed -Sv, its now available in fpc modes
  275. Revision 1.34 1998/10/14 11:28:24 florian
  276. * emitpushreferenceaddress gets now the asmlist as parameter
  277. * m68k version compiles with -duseansistrings
  278. Revision 1.33 1998/10/08 17:17:26 pierre
  279. * current_module old scanner tagged as invalid if unit is recompiled
  280. + added ppheap for better info on tracegetmem of heaptrc
  281. (adds line column and file index)
  282. * several memory leaks removed ith help of heaptrc !!
  283. Revision 1.32 1998/10/02 17:03:51 peter
  284. * ifdef heaptrc for heaptrc
  285. Revision 1.31 1998/09/28 16:57:23 pierre
  286. * changed all length(p^.value_str^) into str_length(p)
  287. to get it work with and without ansistrings
  288. * changed sourcefiles field of tmodule to a pointer
  289. Revision 1.30 1998/09/24 23:49:13 peter
  290. + aktmodeswitches
  291. Revision 1.29 1998/09/17 09:42:41 peter
  292. + pass_2 for cg386
  293. * Message() -> CGMessage() for pass_1/pass_2
  294. Revision 1.28 1998/08/26 15:31:17 peter
  295. * heapblocks for >0.99.5
  296. Revision 1.27 1998/08/11 00:00:00 peter
  297. * fixed dup log
  298. Revision 1.26 1998/08/10 15:49:40 peter
  299. * small fixes for 0.99.5
  300. Revision 1.25 1998/08/10 14:50:16 peter
  301. + localswitches, moduleswitches, globalswitches splitting
  302. Revision 1.24 1998/08/10 10:18:32 peter
  303. + Compiler,Comphook unit which are the new interface units to the
  304. compiler
  305. Revision 1.23 1998/08/05 16:00:16 florian
  306. * some fixes for ansi strings
  307. Revision 1.22 1998/08/04 16:28:40 jonas
  308. * added support for NoRa386* in the $O ... section
  309. Revision 1.21 1998/07/18 17:11:12 florian
  310. + ansi string constants fixed
  311. + switch $H partial implemented
  312. Revision 1.20 1998/07/14 14:46:55 peter
  313. * released NEWINPUT
  314. Revision 1.19 1998/07/07 11:20:04 peter
  315. + NEWINPUT for a better inputfile and scanner object
  316. Revision 1.18 1998/06/24 14:06:33 peter
  317. * fixed the name changes
  318. Revision 1.17 1998/06/23 08:59:22 daniel
  319. * Recommitted.
  320. Revision 1.16 1998/06/17 14:10:17 peter
  321. * small os2 fixes
  322. * fixed interdependent units with newppu (remake3 under linux works now)
  323. Revision 1.15 1998/06/16 11:32:18 peter
  324. * small cosmetic fixes
  325. Revision 1.14 1998/06/15 13:43:45 daniel
  326. * Updated overlays.
  327. Revision 1.12 1998/05/23 01:21:23 peter
  328. + aktasmmode, aktoptprocessor, aktoutputformat
  329. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  330. + $LIBNAME to set the library name where the unit will be put in
  331. * splitted cgi386 a bit (codeseg to large for bp7)
  332. * nasm, tasm works again. nasm moved to ag386nsm.pas
  333. Revision 1.11 1998/05/20 09:42:35 pierre
  334. + UseTokenInfo now default
  335. * unit in interface uses and implementation uses gives error now
  336. * only one error for unknown symbol (uses lastsymknown boolean)
  337. the problem came from the label code !
  338. + first inlined procedures and function work
  339. (warning there might be allowed cases were the result is still wrong !!)
  340. * UseBrower updated gives a global list of all position of all used symbols
  341. with switch -gb
  342. Revision 1.10 1998/05/12 10:47:00 peter
  343. * moved printstatus to verb_def
  344. + V_Normal which is between V_Error and V_Warning and doesn't have a
  345. prefix like error: warning: and is included in V_Default
  346. * fixed some messages
  347. * first time parameter scan is only for -v and -T
  348. - removed old style messages
  349. Revision 1.9 1998/05/11 13:07:56 peter
  350. + $ifdef NEWPPU for the new ppuformat
  351. + $define GDB not longer required
  352. * removed all warnings and stripped some log comments
  353. * no findfirst/findnext anymore to remove smartlink *.o files
  354. Revision 1.8 1998/05/08 09:21:57 michael
  355. + Librarysearchpath is now a linker object field;
  356. Revision 1.7 1998/05/04 17:54:28 peter
  357. + smartlinking works (only case jumptable left todo)
  358. * redesign of systems.pas to support assemblers and linkers
  359. + Unitname is now also in the PPU-file, increased version to 14
  360. Revision 1.6 1998/04/29 13:40:23 peter
  361. + heapblocks:=true
  362. Revision 1.5 1998/04/29 10:33:59 pierre
  363. + added some code for ansistring (not complete nor working yet)
  364. * corrected operator overloading
  365. * corrected nasm output
  366. + started inline procedures
  367. + added starstarn : use ** for exponentiation (^ gave problems)
  368. + started UseTokenInfo cond to get accurate positions
  369. Revision 1.3 1998/04/21 10:16:48 peter
  370. * patches from strasbourg
  371. * objects is not used anymore in the fpc compiled version
  372. Revision 1.2 1998/04/07 13:19:47 pierre
  373. * bugfixes for reset_gdb_info
  374. in MEM parsing for go32v2
  375. better external symbol creation
  376. support for rhgdb.exe (lowercase file names)
  377. }