pp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. if assigned(current_module) and assigned(current_module^.current_inputfile) then
  229. Writeln('Compilation aborted at line ',current_module^.current_inputfile^.line_no);
  230. end;
  231. end;
  232. {$ifdef tp}
  233. procedure do_streamerror;
  234. begin
  235. if symbolstream.status=-2 then
  236. WriteLn('Error: Not enough EMS memory')
  237. else
  238. WriteLn('Error: EMS Error ',symbolstream.status);
  239. {$ifndef MULLER}
  240. halt(1);
  241. {$else MULLER}
  242. runerror(190);
  243. {$endif MULLER}
  244. end;
  245. {$ifdef USEOVERLAY}
  246. function _heaperror(size:word):integer;far;
  247. type
  248. heaprecord=record
  249. next:pointer;
  250. values:longint;
  251. end;
  252. var
  253. l,m:longint;
  254. begin
  255. l:=ovrgetbuf-ovrminsize;
  256. if (size>maxavail) and (l>=size) then
  257. begin
  258. m:=((longint(size)+$3fff) and $ffffc000);
  259. {Clear the overlay buffer.}
  260. ovrclearbuf;
  261. {Shrink it.}
  262. ovrheapend:=ovrheapend-m shr 4;
  263. heaprecord(ptr(ovrheapend,0)^).next:=freelist;
  264. heaprecord(ptr(ovrheapend,0)^).values:=m shl 12;
  265. heaporg:=ptr(ovrheapend,0);
  266. freelist:=heaporg;
  267. Writeln('Warning: Overlay buffer shrinked, because of memory shortage');
  268. _heaperror:=2;
  269. end
  270. else
  271. _heaperror:=0;
  272. end;
  273. {$endif USEOVERLAY}
  274. {$endif TP}
  275. var
  276. start : real;
  277. {$IfDef Extdebug}
  278. EntryMemAvail : longint;
  279. {$EndIf}
  280. begin
  281. oldexit:=exitproc;
  282. exitproc:=@myexit;
  283. {$ifdef linux}
  284. heapblocks:=true;
  285. {$else}
  286. {$ifdef go32v2}
  287. heapblocks:=true;
  288. {$endif}
  289. {$endif}
  290. {$ifdef EXTDEBUG}
  291. EntryMemAvail:=MemAvail;
  292. {$endif}
  293. {$ifdef MULLER}
  294. {$ifdef DPMI}
  295. HeapBlock:=$ff00;
  296. {$endif DPMI}
  297. {$endif MULLER}
  298. {$ifdef TP}
  299. {$IFDEF USEOVERLAY}
  300. heaperror:=@_heaperror;
  301. {$ENDIF USEOVERLAY}
  302. if use_big then
  303. begin
  304. streamerror:=@do_streamerror;
  305. { symbolstream.init('TMPFILE',stcreate,16000); }
  306. {$ifndef dpmi}
  307. symbolstream.init(10000,4000000); {using ems streams}
  308. {$else}
  309. symbolstream.init(1000000,16000); {using memory streams}
  310. {$endif}
  311. if symbolstream.errorinfo=stiniterror then
  312. do_streamerror;
  313. { write something, because pos 0 means nil pointer }
  314. symbolstream.writestr(@inputfile);
  315. end;
  316. {$endif tp}
  317. { inits which need to be done before the arguments are parsed }
  318. get_exepath;
  319. init_tree;
  320. globalsinit;
  321. init_symtable;
  322. linker.init;
  323. { read the arguments }
  324. read_arguments;
  325. { inits which depend on arguments }
  326. initparser;
  327. initimport;
  328. {show some info}
  329. Message1(general_i_compilername,FixFileName(paramstr(0)));
  330. Message1(general_i_unitsearchpath,unitsearchpath);
  331. Message1(general_d_sourceos,source_os.name);
  332. Message1(general_i_targetos,target_os.name);
  333. Message1(general_u_exepath,exepath);
  334. {$ifdef linux}
  335. Message1(general_u_gcclibpath,Linker.librarysearchpath);
  336. {$endif}
  337. {$ifdef TP}
  338. Comment(V_Info,'Memory: '+tostr(MemAvail)+' Bytes Free');
  339. {$endif}
  340. start:=getrealtime;
  341. compile(inputdir+inputfile+inputextension,false);
  342. if status.errorcount=0 then
  343. begin
  344. start:=getrealtime-start;
  345. Message2(general_i_abslines_compiled,tostr(status.compiledlines),tostr(trunc(start))+'.'+tostr(trunc(frac(start)*10)));
  346. end;
  347. {***Obsolete
  348. clearnodes;
  349. ***}
  350. done_symtable;
  351. {$ifdef TP}
  352. Comment(V_Info,'Memory: '+tostr(MemAvail)+' Bytes Free');
  353. {$endif}
  354. {$ifdef EXTDEBUG}
  355. Comment(V_Info,'Memory lost = '+tostr(EntryMemAvail-MemAvail));
  356. {$endif EXTDEBUG}
  357. { exits with error 1 if no codegeneration }
  358. if status.errorcount=0 then
  359. halt(0)
  360. else
  361. halt(1);
  362. end.
  363. {
  364. $Log$
  365. Revision 1.18 1998-06-24 14:06:33 peter
  366. * fixed the name changes
  367. Revision 1.17 1998/06/23 08:59:22 daniel
  368. * Recommitted.
  369. Revision 1.16 1998/06/17 14:10:17 peter
  370. * small os2 fixes
  371. * fixed interdependent units with newppu (remake3 under linux works now)
  372. Revision 1.15 1998/06/16 11:32:18 peter
  373. * small cosmetic fixes
  374. Revision 1.14 1998/06/15 13:43:45 daniel
  375. * Updated overlays.
  376. Revision 1.12 1998/05/23 01:21:23 peter
  377. + aktasmmode, aktoptprocessor, aktoutputformat
  378. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  379. + $LIBNAME to set the library name where the unit will be put in
  380. * splitted cgi386 a bit (codeseg to large for bp7)
  381. * nasm, tasm works again. nasm moved to ag386nsm.pas
  382. Revision 1.11 1998/05/20 09:42:35 pierre
  383. + UseTokenInfo now default
  384. * unit in interface uses and implementation uses gives error now
  385. * only one error for unknown symbol (uses lastsymknown boolean)
  386. the problem came from the label code !
  387. + first inlined procedures and function work
  388. (warning there might be allowed cases were the result is still wrong !!)
  389. * UseBrower updated gives a global list of all position of all used symbols
  390. with switch -gb
  391. Revision 1.10 1998/05/12 10:47:00 peter
  392. * moved printstatus to verb_def
  393. + V_Normal which is between V_Error and V_Warning and doesn't have a
  394. prefix like error: warning: and is included in V_Default
  395. * fixed some messages
  396. * first time parameter scan is only for -v and -T
  397. - removed old style messages
  398. Revision 1.9 1998/05/11 13:07:56 peter
  399. + $ifdef NEWPPU for the new ppuformat
  400. + $define GDB not longer required
  401. * removed all warnings and stripped some log comments
  402. * no findfirst/findnext anymore to remove smartlink *.o files
  403. Revision 1.8 1998/05/08 09:21:57 michael
  404. + Librarysearchpath is now a linker object field;
  405. Revision 1.7 1998/05/04 17:54:28 peter
  406. + smartlinking works (only case jumptable left todo)
  407. * redesign of systems.pas to support assemblers and linkers
  408. + Unitname is now also in the PPU-file, increased version to 14
  409. Revision 1.6 1998/04/29 13:40:23 peter
  410. + heapblocks:=true
  411. Revision 1.5 1998/04/29 10:33:59 pierre
  412. + added some code for ansistring (not complete nor working yet)
  413. * corrected operator overloading
  414. * corrected nasm output
  415. + started inline procedures
  416. + added starstarn : use ** for exponentiation (^ gave problems)
  417. + started UseTokenInfo cond to get accurate positions
  418. Revision 1.3 1998/04/21 10:16:48 peter
  419. * patches from strasbourg
  420. * objects is not used anymore in the fpc compiled version
  421. Revision 1.2 1998/04/07 13:19:47 pierre
  422. * bugfixes for reset_gdb_info
  423. in MEM parsing for go32v2
  424. better external symbol creation
  425. support for rhgdb.exe (lowercase file names)
  426. }