pp.pas 13 KB

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