pp.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  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. possible compiler switches (* marks a currently required switch):
  18. -----------------------------------------------------------------
  19. USE_RHIDE generates errors and warning in an format recognized
  20. by rhide
  21. TP to compile the compiler with Turbo or Borland Pascal
  22. GDB* support of the GNU Debugger
  23. I386 generate a compiler for the Intel i386+
  24. M68K generate a compiler for the M68000
  25. MULLER release special debug code of Pierre Muller
  26. (needs some extra units)
  27. USEOVERLAY compiles a TP version which uses overlays
  28. EXTDEBUG some extra debug code is executed
  29. SUPPORT_MMX only i386: releases the compiler switch
  30. MMX which allows the compiler to generate
  31. MMX instructions
  32. EXTERN_MSG Don't compile the msgfiles in the compiler, always
  33. use external messagefiles
  34. -----------------------------------------------------------------
  35. Required switches for a i386 compiler be compiled by Free Pascal Compiler:
  36. GDB;I386
  37. Required switches for a i386 compiler be compiled by Turbo Pascal:
  38. GDB;I386;TP
  39. Required switches for a 68000 compiler be compiled by Turbo Pascal:
  40. GDB;M68k;TP
  41. }
  42. {$ifdef FPC}
  43. {$ifndef GDB}
  44. { people can try to compile without GDB }
  45. {$error The compiler switch GDB must be defined}
  46. {$endif GDB}
  47. { but I386 or M68K must be defined }
  48. { and only one of the two }
  49. {$ifndef I386}
  50. {$ifndef M68K}
  51. {$fatalerror One of the switches I386 or M68K must be defined}
  52. {$endif M68K}
  53. {$endif I386}
  54. {$ifdef I386}
  55. {$ifdef M68K}
  56. {$fatalerror ONLY one of the switches I386 or M68K must be defined}
  57. {$endif M68K}
  58. {$endif I386}
  59. {$ifdef support_mmx}
  60. {$ifndef i386}
  61. {$fatalerror I386 switch must be on for MMX support}
  62. {$endif i386}
  63. {$endif support_mmx}
  64. {$endif}
  65. {$ifdef TP}
  66. {$IFNDEF DPMI}
  67. {$M 24576,0,655360}
  68. {$ELSE}
  69. {$M 65000}
  70. {$ENDIF DPMI}
  71. {$E+,N+,F+,S-,R-}
  72. {$endif TP}
  73. program pp;
  74. {$IFDEF TP}
  75. {$UNDEF PROFILE}
  76. {$IFDEF DPMI}
  77. {$UNDEF USEOVERLAY}
  78. {$ENDIF}
  79. {$ENDIF}
  80. {$ifdef FPC}
  81. {$UNDEF USEOVERLAY}
  82. {$UNDEF USEPMD}
  83. {$ENDIF}
  84. uses
  85. {$ifdef fpc}
  86. {$ifdef GO32V2}
  87. emu387,
  88. dpmiexcp,
  89. {$endif GO32V2}
  90. {$endif}
  91. {$ifdef useoverlay}
  92. {$ifopt o+}
  93. Overlay,ppovin,
  94. {$else}
  95. { warn when not $O+ is used }
  96. - You must compile with the $O+ switch
  97. {$endif}
  98. {$endif useoverlay}
  99. {$ifdef lock}
  100. lock,
  101. {$endif lock}
  102. {$ifdef profile}
  103. profile,
  104. {$endif profile}
  105. {$ifdef muller}
  106. openfile,
  107. {$ifdef usepmd}
  108. usepmd,
  109. {$endif usepmd}
  110. {$endif}
  111. {$ifdef LINUX}
  112. catch,
  113. {$endif LINUX}
  114. {$IfDef PMD}
  115. OpenFile,
  116. BBError,
  117. ObjMemory,
  118. PMD, MemCheck,
  119. {$EndIf}
  120. {$ifdef TP}
  121. objects,
  122. {$endif}
  123. dos,cobjects,
  124. globals,parser,systems,tree,symtable,options,link,import,files,
  125. verb_def,verbose;
  126. {$ifdef useoverlay}
  127. {$O files}
  128. {$O globals}
  129. {$O hcodegen}
  130. {$O pass_1}
  131. {$O tree}
  132. {$O types}
  133. {$O objects}
  134. {$O options}
  135. {$O cobjects}
  136. {$O globals}
  137. {$O systems}
  138. {$O parser}
  139. {$O dos}
  140. {$O scanner}
  141. {$O symtable}
  142. {$O objects}
  143. {$O aasm}
  144. {$ifdef gdb}
  145. {$O gdb}
  146. {$endif gdb}
  147. {$ifdef i386}
  148. {$O opts386}
  149. {$O cgi386}
  150. {$O aopt386}
  151. {$O cgai386}
  152. {$O i386}
  153. {$O radi386}
  154. {$O rai386}
  155. {$O ratti386}
  156. {$O tgeni386}
  157. {$endif}
  158. {$ifdef m68k}
  159. {$O opts68k}
  160. {$O cg68k}
  161. {$O ra68k}
  162. {$O ag68kgas}
  163. {$endif}
  164. {$endif useoverlay}
  165. function print_status(const status : tcompilestatus) : boolean;
  166. begin
  167. print_status:=false;
  168. if (abslines=1) then
  169. Message1(general_i_kb_free,tostr(memavail shr 10));
  170. if (status.currentline mod 100=0) then
  171. Message2(general_l_lines_and_free,tostr(status.currentline),tostr(memavail shr 10));
  172. {$ifdef tp}
  173. if (use_big) then
  174. begin
  175. {$ifdef dpmi}
  176. Message1(general_i_stream_kb_free,tostr(symbolstream.getsize shr 10));
  177. {$else}
  178. Message1(general_i_ems_kb_free,tostr(symbolstream.getsize shr 10));
  179. {$endif}
  180. end;
  181. {$endif}
  182. end;
  183. function getrealtime : real;
  184. var
  185. h,m,s,s100 : word;
  186. begin
  187. dos.gettime(h,m,s,s100);
  188. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  189. end;
  190. var
  191. oldexit : pointer;
  192. procedure myexit;{$ifndef FPC}far;{$endif}
  193. begin
  194. exitproc:=oldexit;
  195. {$ifdef tp}
  196. if use_big then
  197. symbolstream.done;
  198. {$endif}
  199. if (erroraddr<>nil) then
  200. begin
  201. case exitcode of
  202. 202 : begin
  203. erroraddr:=nil;
  204. Writeln('Error: Stack Overflow');
  205. end;
  206. 203 : begin
  207. erroraddr:=nil;
  208. Writeln('Error: Out of memory');
  209. end;
  210. end;
  211. {when the module is assigned, then the messagefile is also loaded}
  212. if assigned(current_module) and assigned(current_module^.current_inputfile) then
  213. Writeln('Compilation aborted at line ',current_module^.current_inputfile^.line_no);
  214. end;
  215. end;
  216. {$ifdef tp}
  217. procedure do_streamerror;
  218. begin
  219. if symbolstream.status=-2 then
  220. WriteLn('Error: Not enough EMS memory')
  221. else
  222. WriteLn('Error: EMS Error ',symbolstream.status);
  223. {$ifndef MULLER}
  224. halt(1);
  225. {$else MULLER}
  226. runerror(190);
  227. {$endif MULLER}
  228. end;
  229. {$ifdef USEOVERLAY}
  230. function _heaperror(size:word):integer;far;
  231. type
  232. heaprecord=record
  233. next:pointer;
  234. values:longint;
  235. end;
  236. var
  237. l,m:longint;
  238. begin
  239. l:=ovrgetbuf-ovrminsize;
  240. if (size>maxavail) and (l>=size) then
  241. begin
  242. m:=((longint(size)+$3fff) and $ffffc000);
  243. {Clear the overlay buffer.}
  244. ovrclearbuf;
  245. {Shrink it.}
  246. ovrheapend:=ovrheapend-m shr 4;
  247. heaprecord(ptr(ovrheapend,0)^).next:=freelist;
  248. heaprecord(ptr(ovrheapend,0)^).values:=m shl 12;
  249. heaporg:=ptr(ovrheapend,0);
  250. freelist:=heaporg;
  251. Writeln('Warning: Overlay buffer shrinked, because of memory shortage');
  252. _heaperror:=2;
  253. end
  254. else
  255. _heaperror:=0;
  256. end;
  257. {$endif USEOVERLAY}
  258. {$endif TP}
  259. var
  260. start : real;
  261. {$IfDef Extdebug}
  262. EntryMemAvail : longint;
  263. {$EndIf}
  264. begin
  265. oldexit:=exitproc;
  266. exitproc:=@myexit;
  267. {$ifdef linux}
  268. heapblocks:=true;
  269. {$else}
  270. {$ifdef go32v2}
  271. heapblocks:=true;
  272. {$endif}
  273. {$endif}
  274. {$ifdef EXTDEBUG}
  275. EntryMemAvail:=MemAvail;
  276. {$endif}
  277. {$ifdef MULLER}
  278. {$ifdef DPMI}
  279. HeapBlock:=$ff00;
  280. {$endif DPMI}
  281. {$endif MULLER}
  282. {$ifdef TP}
  283. {$IFDEF USEOVERLAY}
  284. heaperror:=@_heaperror;
  285. {$ENDIF USEOVERLAY}
  286. if use_big then
  287. begin
  288. streamerror:=@do_streamerror;
  289. { symbolstream.init('TMPFILE',stcreate,16000); }
  290. {$ifndef dpmi}
  291. symbolstream.init(10000,4000000); {using ems streams}
  292. {$else}
  293. symbolstream.init(1000000,16000); {using memory streams}
  294. {$endif}
  295. if symbolstream.errorinfo=stiniterror then
  296. do_streamerror;
  297. { write something, because pos 0 means nil pointer }
  298. symbolstream.writestr(@inputfile);
  299. end;
  300. {$endif tp}
  301. {$ifndef TP}
  302. compilestatusproc:=@print_status;
  303. {$else}
  304. compilestatusproc:=print_status;
  305. {$endif}
  306. { inits which need to be done before the arguments are parsed }
  307. get_exepath;
  308. init_tree;
  309. globalsinit;
  310. init_symtable;
  311. linker.init;
  312. { read the arguments }
  313. read_arguments;
  314. { inits which depend on arguments }
  315. initparser;
  316. initimport;
  317. {show some info}
  318. Message1(general_i_compilername,FixFileName(paramstr(0)));
  319. Message1(general_i_unitsearchpath,unitsearchpath);
  320. Message1(general_d_sourceos,source_info.source_name);
  321. Message1(general_i_targetos,target_info.target_name);
  322. Message1(general_u_exepath,exepath);
  323. {$ifdef linux}
  324. Message1(general_u_gcclibpath,Linker.gcclibrarypath);
  325. {$endif}
  326. start:=getrealtime;
  327. compile(inputdir+inputfile+inputextension,false);
  328. if errorcount=0 then
  329. begin
  330. start:=getrealtime-start;
  331. Message2(general_i_abslines_compiled,tostr(abslines),tostr(trunc(start))+'.'+tostr(trunc(frac(start)*10)));
  332. end;
  333. clearnodes;
  334. done_symtable;
  335. {$ifdef EXTDEBUG}
  336. Comment(V_Info,'Memory lost = '+tostr(EntryMemAvail-MemAvail));
  337. {$endif EXTDEBUG}
  338. { exits with error 1 if no codegeneration }
  339. if errorcount=0 then
  340. halt(0)
  341. else
  342. halt(1);
  343. end.
  344. {
  345. $Log$
  346. Revision 1.6 1998-04-29 13:40:23 peter
  347. + heapblocks:=true
  348. Revision 1.5 1998/04/29 10:33:59 pierre
  349. + added some code for ansistring (not complete nor working yet)
  350. * corrected operator overloading
  351. * corrected nasm output
  352. + started inline procedures
  353. + added starstarn : use ** for exponentiation (^ gave problems)
  354. + started UseTokenInfo cond to get accurate positions
  355. Revision 1.3 1998/04/21 10:16:48 peter
  356. * patches from strasbourg
  357. * objects is not used anymore in the fpc compiled version
  358. Revision 1.2 1998/04/07 13:19:47 pierre
  359. * bugfixes for reset_gdb_info
  360. in MEM parsing for go32v2
  361. better external symbol creation
  362. support for rhgdb.exe (lowercase file names)
  363. Revision 1.1.1.1 1998/03/25 11:18:14 root
  364. * Restored version
  365. Revision 1.40 1998/03/16 22:42:21 florian
  366. * some fixes of Peter applied:
  367. ofs problem, profiler support
  368. Revision 1.39 1998/03/10 15:20:30 carl
  369. * bugfix of spelling mistake
  370. * make it compile under TP with overlays
  371. Revision 1.38 1998/03/10 13:23:00 florian
  372. * small win32 problems fixed
  373. Revision 1.37 1998/03/10 01:17:24 peter
  374. * all files have the same header
  375. * messages are fully implemented, EXTDEBUG uses Comment()
  376. + AG... files for the Assembler generation
  377. Revision 1.36 1998/03/06 00:52:46 peter
  378. * replaced all old messages from errore.msg, only ExtDebug and some
  379. Comment() calls are left
  380. * fixed options.pas
  381. Revision 1.35 1998/03/05 02:44:16 peter
  382. * options cleanup and use of .msg file
  383. Revision 1.34 1998/03/04 17:33:52 michael
  384. + Changed ifdef FPK to ifdef FPC
  385. Revision 1.33 1998/03/02 23:08:42 florian
  386. * the concatcopy bug removed (solves problems when compilg sysatari!)
  387. Revision 1.32 1998/03/02 16:02:04 peter
  388. * new style messages for pp.pas
  389. * cleanup of pp.pas
  390. Revision 1.31 1998/03/02 13:38:49 peter
  391. + importlib object
  392. * doesn't crash on a systemunit anymore
  393. * updated makefile and depend
  394. Revision 1.30 1998/03/02 01:49:05 peter
  395. * renamed target_DOS to target_GO32V1
  396. + new verbose system, merged old errors and verbose units into one new
  397. verbose.pas, so errors.pas is obsolete
  398. Revision 1.29 1998/02/25 14:31:28 jonas
  399. * added $d- for TP compiling (disable strict var checking) and removed a duplicate $M statement
  400. Revision 1.28 1998/02/22 23:03:29 peter
  401. * renamed msource->mainsource and name->unitname
  402. * optimized filename handling, filename is not seperate anymore with
  403. path+name+ext, this saves stackspace and a lot of fsplit()'s
  404. * recompiling of some units in libraries fixed
  405. * shared libraries are working again
  406. + $LINKLIB <lib> to support automatic linking to libraries
  407. + libraries are saved/read from the ppufile, also allows more libraries
  408. per ppufile
  409. Revision 1.27 1998/02/16 14:19:15 florian
  410. *** empty log message ***
  411. Revision 1.26 1998/02/16 13:46:43 michael
  412. + Further integration of linker object:
  413. - all options pertaining to linking go directly to linker object
  414. - removed redundant variables/procedures, especially in OS_TARG...
  415. Revision 1.25 1998/02/16 12:51:40 michael
  416. + Implemented linker object
  417. Revision 1.24 1998/02/14 05:04:49 carl
  418. + more overlay stuff for m68k target
  419. Revision 1.23 1998/02/14 01:45:30 peter
  420. * more fixes
  421. - pmode target is removed
  422. - search_as_ld is removed, this is done in the link.pas/assemble.pas
  423. + findexe() to search for an executable (linker,assembler,binder)
  424. Revision 1.22 1998/02/13 22:26:39 peter
  425. * fixed a few SigSegv's
  426. * INIT$$ was not written for linux!
  427. * assembling and linking works again for linux and dos
  428. + assembler object, only attasmi3 supported yet
  429. * restore pp.pas with AddPath etc.
  430. Revision 1.18 1998/02/03 22:13:34 florian
  431. * clean up
  432. Revision 1.17 1998/02/02 00:55:33 peter
  433. * defdatei -> deffile and some german comments to english
  434. * search() accepts : as seperater under linux
  435. * search for ppc.cfg doesn't open a file (and let it open)
  436. * reorganize the reading of parameters/file a bit
  437. * all the PPC_ environments are now for all platforms
  438. Revision 1.16 1998/01/27 10:48:19 florian
  439. * dpmiexcp is now always used by a go32v2 compiler executable
  440. Revision 1.15 1998/01/25 18:45:50 peter
  441. + Search for as and ld at startup
  442. + source_info works the same as target_info
  443. + externlink allows only external linking
  444. Revision 1.14 1998/01/23 10:46:42 florian
  445. * small problems with FCL object model fixed, objpas?.inc is compilable
  446. Revision 1.13 1998/01/18 21:34:29 florian
  447. *** empty log message ***
  448. Revision 1.12 1998/01/16 12:52:10 michael
  449. + Path treatment and file searching should now be more or less in their
  450. definite form:
  451. - Using now modified AddPathToList everywhere.
  452. - File Searching mechanism is uniform for all files.
  453. - Include path is working now !!
  454. All fixes by Peter Vreman. Tested with remake3 target.
  455. Revision 1.11 1998/01/07 00:17:04 michael
  456. Restored released version (plus fixes) as current
  457. Revision 1.10 1997/12/12 13:28:39 florian
  458. + version 0.99.0
  459. * all WASM options changed into MASM
  460. + -O2 for Pentium II optimizations
  461. Revision 1.9 1997/12/09 13:57:21 carl
  462. * bugfix when compiling using overlays
  463. Revision 1.8 1997/12/05 14:38:39 carl
  464. * equivalent to version 1.5 (otherwise would not compile)
  465. Revision 1.5 1997/12/03 14:36:14 carl
  466. * bugfix of my bug with $ifdef support_mxx
  467. Revision 1.4 1997/12/03 13:41:37 carl
  468. + checks that i386 is defined if with mmx_support switch.
  469. Revision 1.3 1997/11/29 15:40:10 florian
  470. + myexit is now executed
  471. Revision 1.2 1997/11/28 18:14:43 pierre
  472. working version with several bug fixes
  473. Revision 1.1.1.1 1997/11/27 08:33:00 michael
  474. FPC Compiler CVS start
  475. Pre-CVS log:
  476. FK Florian Klaempfl
  477. + feature added
  478. - removed
  479. * bug fixed or changed
  480. History (started at 19th september 1997):
  481. 19th september 1997:
  482. + informations about ccompiler switches added (FK)
  483. 2nd october 1997:
  484. *- removed ifndef dpmi for stream init, tmemorystream is used if
  485. in dpmi everywhere else if use_big on. (CEC)
  486. 6th november 1997:
  487. - crt unit to allow output redirection (FK)
  488. }