pp.pas 10 KB

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