pp.pas 14 KB

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