pp.pas 11 KB

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