pp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. {$fatal One of the switches I386 or M68K must be defined}
  52. {$endif M68K}
  53. {$endif I386}
  54. {$ifdef I386}
  55. {$ifdef M68K}
  56. {$fatal 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. {$fatal 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 24000,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 pbase}
  140. {$O pdecl}
  141. {$O pexports}
  142. {$O pexpr}
  143. {$O pmodules}
  144. {$O pstatmnt}
  145. {$O psub}
  146. {$O psystem}
  147. {$O ptconst}
  148. {$O script}
  149. {$O switches}
  150. {$O temp_gen}
  151. {$O verb_def}
  152. {$O dos}
  153. {$O scanner}
  154. {$O symtable}
  155. {$O objects}
  156. {$O aasm}
  157. {$O link}
  158. {$O assemble}
  159. {$O messages}
  160. {$O gendef}
  161. {$O import}
  162. {$O os2_targ}
  163. {$O win_targ}
  164. {$O asmutils}
  165. {$ifdef gdb}
  166. {$O gdb}
  167. {$endif gdb}
  168. {$ifdef i386}
  169. {$O opts386}
  170. {$O cgi386}
  171. {$O cg386add}
  172. {$O cg386cal}
  173. {$O cg386cnv}
  174. {$O cg386con}
  175. {$O cg386flw}
  176. {$O cg386ld}
  177. {$O cg386mat}
  178. {$O cg386set}
  179. {$O aopt386}
  180. {$O cgai386}
  181. {$O i386}
  182. {$O ra386dir}
  183. {$O ra386int}
  184. {$O ra386att}
  185. {$O tgeni386}
  186. {$O ag386int}
  187. {$O ag386att}
  188. {$O ag386nsm}
  189. {$endif}
  190. {$ifdef m68k}
  191. {$O opts68k}
  192. {$O cg68k}
  193. {$O ra68kmot}
  194. {$O ag68kgas}
  195. {$O ag68kmot}
  196. {$O ag68kmit}
  197. {$endif}
  198. {$endif useoverlay}
  199. function getrealtime : real;
  200. var
  201. h,m,s,s100 : word;
  202. begin
  203. dos.gettime(h,m,s,s100);
  204. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  205. end;
  206. var
  207. oldexit : pointer;
  208. procedure myexit;{$ifndef FPC}far;{$endif}
  209. begin
  210. exitproc:=oldexit;
  211. {$ifdef tp}
  212. if use_big then
  213. symbolstream.done;
  214. {$endif}
  215. if (erroraddr<>nil) then
  216. begin
  217. case exitcode of
  218. 202 : begin
  219. erroraddr:=nil;
  220. Writeln('Error: Stack Overflow');
  221. end;
  222. 203 : begin
  223. erroraddr:=nil;
  224. Writeln('Error: Out of memory');
  225. end;
  226. end;
  227. {when the module is assigned, then the messagefile is also loaded}
  228. {$ifdef NEWINPUT}
  229. Writeln('Compilation aborted at line ',aktfilepos.line);
  230. {$else}
  231. if assigned(current_module) and assigned(current_module^.current_inputfile) then
  232. Writeln('Compilation aborted at line ',current_module^.current_inputfile^.line_no);
  233. {$endif}
  234. end;
  235. end;
  236. {$ifdef tp}
  237. procedure do_streamerror;
  238. begin
  239. if symbolstream.status=-2 then
  240. WriteLn('Error: Not enough EMS memory')
  241. else
  242. WriteLn('Error: EMS Error ',symbolstream.status);
  243. {$ifndef MULLER}
  244. halt(1);
  245. {$else MULLER}
  246. runerror(190);
  247. {$endif MULLER}
  248. end;
  249. {$ifdef USEOVERLAY}
  250. function _heaperror(size:word):integer;far;
  251. type
  252. heaprecord=record
  253. next:pointer;
  254. values:longint;
  255. end;
  256. var
  257. l,m:longint;
  258. begin
  259. l:=ovrgetbuf-ovrminsize;
  260. if (size>maxavail) and (l>=size) then
  261. begin
  262. m:=((longint(size)+$3fff) and $ffffc000);
  263. {Clear the overlay buffer.}
  264. ovrclearbuf;
  265. {Shrink it.}
  266. ovrheapend:=ovrheapend-m shr 4;
  267. heaprecord(ptr(ovrheapend,0)^).next:=freelist;
  268. heaprecord(ptr(ovrheapend,0)^).values:=m shl 12;
  269. heaporg:=ptr(ovrheapend,0);
  270. freelist:=heaporg;
  271. Writeln('Warning: Overlay buffer shrinked, because of memory shortage');
  272. _heaperror:=2;
  273. end
  274. else
  275. _heaperror:=0;
  276. end;
  277. {$endif USEOVERLAY}
  278. {$endif TP}
  279. var
  280. start : real;
  281. {$IfDef Extdebug}
  282. EntryMemAvail : longint;
  283. {$EndIf}
  284. begin
  285. oldexit:=exitproc;
  286. exitproc:=@myexit;
  287. {$ifdef linux}
  288. heapblocks:=true;
  289. {$else}
  290. {$ifdef go32v2}
  291. heapblocks:=true;
  292. {$endif}
  293. {$endif}
  294. {$ifdef EXTDEBUG}
  295. EntryMemAvail:=MemAvail;
  296. {$endif}
  297. {$ifdef MULLER}
  298. {$ifdef DPMI}
  299. HeapBlock:=$ff00;
  300. {$endif DPMI}
  301. {$endif MULLER}
  302. {$ifdef TP}
  303. {$IFDEF USEOVERLAY}
  304. heaperror:=@_heaperror;
  305. {$ENDIF USEOVERLAY}
  306. if use_big then
  307. begin
  308. streamerror:=@do_streamerror;
  309. { symbolstream.init('TMPFILE',stcreate,16000); }
  310. {$ifndef dpmi}
  311. symbolstream.init(10000,4000000); {using ems streams}
  312. {$else}
  313. symbolstream.init(1000000,16000); {using memory streams}
  314. {$endif}
  315. if symbolstream.errorinfo=stiniterror then
  316. do_streamerror;
  317. { write something, because pos 0 means nil pointer }
  318. symbolstream.writestr(@inputfile);
  319. end;
  320. {$endif tp}
  321. { inits which need to be done before the arguments are parsed }
  322. get_exepath;
  323. init_tree;
  324. globalsinit;
  325. init_symtable;
  326. linker.init;
  327. { read the arguments }
  328. read_arguments;
  329. { inits which depend on arguments }
  330. initparser;
  331. initimport;
  332. {show some info}
  333. Message1(general_i_compilername,FixFileName(paramstr(0)));
  334. Message1(general_i_unitsearchpath,unitsearchpath);
  335. Message1(general_d_sourceos,source_os.name);
  336. Message1(general_i_targetos,target_os.name);
  337. Message1(general_u_exepath,exepath);
  338. {$ifdef linux}
  339. Message1(general_u_gcclibpath,Linker.librarysearchpath);
  340. {$endif}
  341. {$ifdef TP}
  342. Comment(V_Info,'Memory: '+tostr(MemAvail)+' Bytes Free');
  343. {$endif}
  344. start:=getrealtime;
  345. compile(inputdir+inputfile+inputextension,false);
  346. if status.errorcount=0 then
  347. begin
  348. start:=getrealtime-start;
  349. Message2(general_i_abslines_compiled,tostr(status.compiledlines),tostr(trunc(start))+'.'+tostr(trunc(frac(start)*10)));
  350. end;
  351. {***Obsolete
  352. clearnodes;
  353. ***}
  354. done_symtable;
  355. {$ifdef TP}
  356. Comment(V_Info,'Memory: '+tostr(MemAvail)+' Bytes Free');
  357. {$endif}
  358. {$ifdef EXTDEBUG}
  359. Comment(V_Info,'Memory lost = '+tostr(EntryMemAvail-MemAvail));
  360. {$endif EXTDEBUG}
  361. { exits with error 1 if no codegeneration }
  362. if status.errorcount=0 then
  363. halt(0)
  364. else
  365. halt(1);
  366. end.
  367. {
  368. $Log$
  369. Revision 1.19 1998-07-07 11:20:04 peter
  370. + NEWINPUT for a better inputfile and scanner object
  371. Revision 1.18 1998/06/24 14:06:33 peter
  372. * fixed the name changes
  373. Revision 1.17 1998/06/23 08:59:22 daniel
  374. * Recommitted.
  375. Revision 1.16 1998/06/17 14:10:17 peter
  376. * small os2 fixes
  377. * fixed interdependent units with newppu (remake3 under linux works now)
  378. Revision 1.15 1998/06/16 11:32:18 peter
  379. * small cosmetic fixes
  380. Revision 1.14 1998/06/15 13:43:45 daniel
  381. * Updated overlays.
  382. Revision 1.12 1998/05/23 01:21:23 peter
  383. + aktasmmode, aktoptprocessor, aktoutputformat
  384. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  385. + $LIBNAME to set the library name where the unit will be put in
  386. * splitted cgi386 a bit (codeseg to large for bp7)
  387. * nasm, tasm works again. nasm moved to ag386nsm.pas
  388. Revision 1.11 1998/05/20 09:42:35 pierre
  389. + UseTokenInfo now default
  390. * unit in interface uses and implementation uses gives error now
  391. * only one error for unknown symbol (uses lastsymknown boolean)
  392. the problem came from the label code !
  393. + first inlined procedures and function work
  394. (warning there might be allowed cases were the result is still wrong !!)
  395. * UseBrower updated gives a global list of all position of all used symbols
  396. with switch -gb
  397. Revision 1.10 1998/05/12 10:47:00 peter
  398. * moved printstatus to verb_def
  399. + V_Normal which is between V_Error and V_Warning and doesn't have a
  400. prefix like error: warning: and is included in V_Default
  401. * fixed some messages
  402. * first time parameter scan is only for -v and -T
  403. - removed old style messages
  404. Revision 1.9 1998/05/11 13:07:56 peter
  405. + $ifdef NEWPPU for the new ppuformat
  406. + $define GDB not longer required
  407. * removed all warnings and stripped some log comments
  408. * no findfirst/findnext anymore to remove smartlink *.o files
  409. Revision 1.8 1998/05/08 09:21:57 michael
  410. + Librarysearchpath is now a linker object field;
  411. Revision 1.7 1998/05/04 17:54:28 peter
  412. + smartlinking works (only case jumptable left todo)
  413. * redesign of systems.pas to support assemblers and linkers
  414. + Unitname is now also in the PPU-file, increased version to 14
  415. Revision 1.6 1998/04/29 13:40:23 peter
  416. + heapblocks:=true
  417. Revision 1.5 1998/04/29 10:33:59 pierre
  418. + added some code for ansistring (not complete nor working yet)
  419. * corrected operator overloading
  420. * corrected nasm output
  421. + started inline procedures
  422. + added starstarn : use ** for exponentiation (^ gave problems)
  423. + started UseTokenInfo cond to get accurate positions
  424. Revision 1.3 1998/04/21 10:16:48 peter
  425. * patches from strasbourg
  426. * objects is not used anymore in the fpc compiled version
  427. Revision 1.2 1998/04/07 13:19:47 pierre
  428. * bugfixes for reset_gdb_info
  429. in MEM parsing for go32v2
  430. better external symbol creation
  431. support for rhgdb.exe (lowercase file names)
  432. }