pp.pas 15 KB

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