pp.pas 15 KB

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