pp.pas 12 KB

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