symppu.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
  4. Implementation of the reading of PPU Files for the symtable
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. const
  19. {$ifdef FPC}
  20. ppubufsize=32768;
  21. {$ELSE}
  22. {$IFDEF USEOVERLAY}
  23. ppubufsize=512;
  24. {$ELSE}
  25. ppubufsize=4096;
  26. {$ENDIF}
  27. {$ENDIF}
  28. {*****************************************************************************
  29. PPU Writing
  30. *****************************************************************************}
  31. procedure writebyte(b:byte);
  32. begin
  33. current_ppu^.putbyte(b);
  34. end;
  35. procedure writeword(w:word);
  36. begin
  37. current_ppu^.putword(w);
  38. end;
  39. procedure writelong(l:longint);
  40. begin
  41. current_ppu^.putlongint(l);
  42. end;
  43. procedure writereal(d:bestreal);
  44. begin
  45. current_ppu^.putreal(d);
  46. end;
  47. procedure writestring(const s:string);
  48. begin
  49. current_ppu^.putstring(s);
  50. end;
  51. procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
  52. begin
  53. current_ppu^.putdata(s,sizeof(tnormalset));
  54. end;
  55. procedure writecontainer(var p:tstringcontainer;id:byte;hold,strippath:boolean);
  56. var
  57. hcontainer : tstringcontainer;
  58. s : string;
  59. begin
  60. if hold then
  61. hcontainer.init;
  62. while not p.empty do
  63. begin
  64. s:=p.get;
  65. if strippath then
  66. current_ppu^.putstring(SplitFileName(s))
  67. else
  68. current_ppu^.putstring(s);
  69. if hold then
  70. hcontainer.insert(s);
  71. end;
  72. current_ppu^.writeentry(id);
  73. if hold then
  74. p:=hcontainer;
  75. end;
  76. procedure writeposinfo(const p:tfileposinfo);
  77. begin
  78. current_ppu^.putword(p.fileindex);
  79. current_ppu^.putlongint(p.line);
  80. current_ppu^.putword(p.column);
  81. end;
  82. procedure writedefref(p : pdef);
  83. begin
  84. if p=nil then
  85. current_ppu^.putlongint($ffffffff)
  86. else
  87. begin
  88. if p^.owner^.symtabletype=staticsymtable then
  89. current_ppu^.putword($fffe)
  90. else if (p^.owner=aktrecordsymtable) then
  91. current_ppu^.putword($ffff)
  92. else if p^.owner^.unitid>$8000 then
  93. current_ppu^.putword(p^.owner^.unitid)
  94. else
  95. current_ppu^.putword(p^.owner^.unitid);
  96. {$ifdef STORENUMBER}
  97. current_ppu^.putword(p^.indexnr);
  98. {$else}
  99. current_ppu^.putword(p^.indexnb);
  100. {$endif}
  101. end;
  102. end;
  103. procedure writesymref(p : psym);
  104. begin
  105. if p=nil then
  106. current_ppu^.putlongint($ffffffff)
  107. else
  108. begin
  109. if p^.owner^.symtabletype=staticsymtable then
  110. current_ppu^.putword($fffe)
  111. else if (p^.owner=aktrecordsymtable) then
  112. current_ppu^.putword($ffff)
  113. else if p^.owner^.unitid>$8000 then
  114. current_ppu^.putword(p^.owner^.unitid)
  115. else
  116. current_ppu^.putword(p^.owner^.unitid);
  117. {$ifdef STORENUMBER}
  118. current_ppu^.putword(p^.indexnr);
  119. {$else}
  120. current_ppu^.putword(p^.indexnb);
  121. {$endif}
  122. end;
  123. end;
  124. procedure writesourcefiles;
  125. var
  126. hp : pinputfile;
  127. begin
  128. { second write the used source files }
  129. current_ppu^.do_crc:=false;
  130. hp:=current_module^.sourcefiles^.files;
  131. while assigned(hp) do
  132. begin
  133. { only name and extension }
  134. current_ppu^.putstring(hp^.name^);
  135. hp:=hp^.ref_next;
  136. end;
  137. current_ppu^.writeentry(ibsourcefiles);
  138. current_ppu^.do_crc:=true;
  139. end;
  140. procedure writeusedunit;
  141. var
  142. hp : pused_unit;
  143. begin
  144. numberunits;
  145. hp:=pused_unit(current_module^.used_units.first);
  146. while assigned(hp) do
  147. begin
  148. {$ifdef Double_checksum}
  149. current_ppu^.do_interface_crc:=hp^.in_interface;
  150. {$endif Double_checksum}
  151. current_ppu^.putstring(hp^.name^);
  152. current_ppu^.do_crc:=false;
  153. {$ifndef Double_checksum}
  154. { the checksum should not affect the crc of this unit ! (PFV) }
  155. current_ppu^.putlongint(hp^.checksum);
  156. {$else Double_checksum}
  157. if hp^.in_interface then
  158. current_ppu^.putlongint(hp^.checksum)
  159. else
  160. current_ppu^.putlongint(hp^.interface_checksum);
  161. {$endif def Double_checksum}
  162. current_ppu^.do_crc:=true;
  163. current_ppu^.putbyte(byte(hp^.in_interface));
  164. hp:=pused_unit(hp^.next);
  165. end;
  166. {$ifdef Double_checksum}
  167. current_ppu^.do_interface_crc:=true;
  168. {$endif Double_checksum}
  169. current_ppu^.writeentry(ibloadunit);
  170. end;
  171. procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
  172. begin
  173. Message1(unit_u_ppu_write,s);
  174. { create unit flags }
  175. with Current_Module^ do
  176. begin
  177. if (((cs_create_staticlib in aktmoduleswitches) or
  178. (cs_smartlink in aktmoduleswitches)) and
  179. (SplitName(ppufilename^)<>SplitName(staticlibfilename^))) or
  180. ((cs_create_sharedlib in aktmoduleswitches) and
  181. (SplitName(ppufilename^)<>SplitName(sharedlibfilename^))) then
  182. flags:=flags or uf_in_library;
  183. if cs_smartlink in aktmoduleswitches then
  184. flags:=flags or uf_smartlink;
  185. {$ifdef GDB}
  186. if cs_gdb_dbx in aktglobalswitches then
  187. flags:=flags or uf_has_dbx;
  188. {$endif GDB}
  189. if target_os.endian=endian_big then
  190. flags:=flags or uf_big_endian;
  191. if cs_browser in aktmoduleswitches then
  192. flags:=flags or uf_has_browser;
  193. if cs_local_browser in aktmoduleswitches then
  194. flags:=flags or uf_local_browser;
  195. end;
  196. {$ifdef Test_Double_checksum_write}
  197. If only_crc then
  198. Assign(CRCFile,s+'.INT')
  199. else
  200. Assign(CRCFile,s+'.IMP');
  201. Rewrite(CRCFile);
  202. {$endif def Test_Double_checksum_write}
  203. { open ppufile }
  204. current_ppu:=new(pppufile,init(s));
  205. if not current_ppu^.create then
  206. Message(unit_f_ppu_cannot_write);
  207. {$ifdef Double_checksum}
  208. current_ppu^.crc_only:=only_crc;
  209. {$ifdef Test_Double_checksum}
  210. if only_crc then
  211. begin
  212. new(current_ppu^.crc_test);
  213. end
  214. else
  215. begin
  216. current_ppu^.crc_test:=Current_Module^.crc_array;
  217. current_ppu^.crc_index:=Current_Module^.crc_size;
  218. end;
  219. {$endif def Test_Double_checksum}
  220. {$endif Double_checksum}
  221. current_ppu^.change_endian:=source_os.endian<>target_os.endian;
  222. { write symbols and definitions }
  223. unittable^.writeasunit;
  224. { flush to be sure }
  225. current_ppu^.flush;
  226. { create and write header }
  227. current_ppu^.header.size:=current_ppu^.size;
  228. current_ppu^.header.checksum:=current_ppu^.crc;
  229. {$ifdef Double_checksum}
  230. current_module^.interface_crc:=current_ppu^.interface_crc;
  231. {$endif def Double_checksum}
  232. current_ppu^.header.compiler:=wordversion;
  233. current_ppu^.header.cpu:=word(target_cpu);
  234. current_ppu^.header.target:=word(target_info.target);
  235. current_ppu^.header.flags:=current_module^.flags;
  236. current_ppu^.writeheader;
  237. { save crc in current_module also }
  238. current_module^.crc:=current_ppu^.crc;
  239. {$ifdef Double_checksum}
  240. current_module^.interface_crc:=current_ppu^.interface_crc;
  241. if only_crc then
  242. begin
  243. {$ifdef Test_Double_checksum}
  244. Current_Module^.crc_array:=current_ppu^.crc_test;
  245. current_ppu^.crc_test:=nil;
  246. Current_Module^.crc_size:=current_ppu^.crc_index;
  247. {$endif def Test_Double_checksum}
  248. closecurrentppu;
  249. end;
  250. {$ifdef Test_Double_checksum_write}
  251. close(CRCFile);
  252. {$endif Test_Double_checksum_write}
  253. {$endif def Double_checksum}
  254. end;
  255. procedure closecurrentppu;
  256. begin
  257. {$ifdef Test_Double_checksum}
  258. if assigned(current_ppu^.crc_test) then
  259. dispose(current_ppu^.crc_test);
  260. {$endif Test_Double_checksum}
  261. { close }
  262. current_ppu^.close;
  263. dispose(current_ppu,done);
  264. current_ppu:=nil;
  265. end;
  266. {*****************************************************************************
  267. PPU Reading
  268. *****************************************************************************}
  269. function readbyte:byte;
  270. begin
  271. readbyte:=current_ppu^.getbyte;
  272. if current_ppu^.error then
  273. Message(unit_f_ppu_read_error);
  274. end;
  275. function readword:word;
  276. begin
  277. readword:=current_ppu^.getword;
  278. if current_ppu^.error then
  279. Message(unit_f_ppu_read_error);
  280. end;
  281. function readlong:longint;
  282. begin
  283. readlong:=current_ppu^.getlongint;
  284. if current_ppu^.error then
  285. Message(unit_f_ppu_read_error);
  286. end;
  287. function readreal : bestreal;
  288. begin
  289. readreal:=current_ppu^.getreal;
  290. if current_ppu^.error then
  291. Message(unit_f_ppu_read_error);
  292. end;
  293. function readstring : string;
  294. begin
  295. readstring:=current_ppu^.getstring;
  296. if current_ppu^.error then
  297. Message(unit_f_ppu_read_error);
  298. end;
  299. procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
  300. begin
  301. current_ppu^.getdata(s,sizeof(tnormalset));
  302. if current_ppu^.error then
  303. Message(unit_f_ppu_read_error);
  304. end;
  305. procedure readcontainer(var p:tstringcontainer);
  306. begin
  307. while not current_ppu^.endofentry do
  308. p.insert(current_ppu^.getstring);
  309. end;
  310. procedure readposinfo(var p:tfileposinfo);
  311. begin
  312. p.fileindex:=current_ppu^.getword;
  313. p.line:=current_ppu^.getlongint;
  314. p.column:=current_ppu^.getword;
  315. end;
  316. function readdefref : pdef;
  317. var
  318. hd : pdef;
  319. begin
  320. longint(hd):=current_ppu^.getword;
  321. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  322. readdefref:=hd;
  323. end;
  324. function readsymref : psym;
  325. var
  326. hd : psym;
  327. begin
  328. longint(hd):=current_ppu^.getword;
  329. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  330. readsymref:=hd;
  331. end;
  332. procedure readsourcefiles;
  333. var
  334. temp,hs : string;
  335. incfile_found : boolean;
  336. ppufiletime,
  337. source_time : longint;
  338. hp : pinputfile;
  339. begin
  340. ppufiletime:=getnamedfiletime(current_module^.ppufilename^);
  341. current_module^.sources_avail:=true;
  342. while not current_ppu^.endofentry do
  343. begin
  344. hs:=current_ppu^.getstring;
  345. temp:='';
  346. if (current_module^.flags and uf_in_library)<>0 then
  347. begin
  348. current_module^.sources_avail:=false;
  349. temp:=' library';
  350. end
  351. else if pos('Macro ',hs)=1 then
  352. begin
  353. { we don't want to find this file }
  354. { but there is a problem with file indexing !! }
  355. temp:='';
  356. end
  357. else
  358. begin
  359. { check the date of the source files }
  360. Source_Time:=GetNamedFileTime(current_module^.path^+hs);
  361. incfile_found:=false;
  362. if (Source_Time=-1) then
  363. begin
  364. temp:=search(hs,includesearchpath,incfile_found);
  365. if incfile_found then
  366. begin
  367. hs:=temp+hs;
  368. Source_Time:=GetNamedFileTime(hs);
  369. end
  370. end
  371. else
  372. hs:=current_module^.path^+hs;
  373. if Source_Time=-1 then
  374. begin
  375. current_module^.sources_avail:=false;
  376. temp:=' not found';
  377. end
  378. else
  379. begin
  380. { time newer? But only allow if the file is not searched
  381. in the include path (PFV), else you've problems with
  382. units which use the same includefile names }
  383. if incfile_found then
  384. temp:=' found'
  385. else
  386. begin
  387. temp:=' time '+filetimestring(source_time);
  388. if (source_time>ppufiletime) then
  389. begin
  390. current_module^.do_compile:=true;
  391. temp:=temp+' *'
  392. end;
  393. end;
  394. end;
  395. new(hp,init(hs));
  396. { the indexing is wrong here PM }
  397. current_module^.sourcefiles^.register_file(hp);
  398. end;
  399. Message1(unit_u_ppu_source,hs+temp);
  400. end;
  401. { main source is always the last }
  402. stringdispose(current_module^.mainsource);
  403. current_module^.mainsource:=stringdup(hs);
  404. { the indexing is corrected here PM }
  405. current_module^.sourcefiles^.inverse_register_indexes;
  406. { check if we want to rebuild every unit, only if the sources are
  407. available }
  408. if do_build and current_module^.sources_avail then
  409. current_module^.do_compile:=true;
  410. end;
  411. procedure readloadunit;
  412. var
  413. hs : string;
  414. checksum : longint;
  415. in_interface : boolean;
  416. begin
  417. while not current_ppu^.endofentry do
  418. begin
  419. hs:=current_ppu^.getstring;
  420. checksum:=current_ppu^.getlongint;
  421. in_interface:=(current_ppu^.getbyte<>0);
  422. current_module^.used_units.concat(new(pused_unit,init_to_load(hs,checksum,in_interface)));
  423. end;
  424. end;
  425. procedure load_interface;
  426. var
  427. b : byte;
  428. begin
  429. { read interface part }
  430. repeat
  431. b:=current_ppu^.readentry;
  432. case b of
  433. ibmodulename : begin
  434. stringdispose(current_module^.modulename);
  435. current_module^.modulename:=stringdup(current_ppu^.getstring);
  436. end;
  437. ibsourcefiles : readsourcefiles;
  438. ibloadunit : readloadunit;
  439. iblinksharedlibs : readcontainer(current_module^.LinkSharedLibs);
  440. iblinkstaticlibs : readcontainer(current_module^.LinkStaticLibs);
  441. iblinkunitfiles : readcontainer(current_module^.LinkUnitFiles);
  442. iblinkofiles : readcontainer(current_module^.LinkOFiles);
  443. ibendinterface : break;
  444. else
  445. Message1(unit_f_ppu_invalid_entry,tostr(b));
  446. end;
  447. until false;
  448. end;
  449. {
  450. $Log$
  451. Revision 1.36 1999-04-14 09:15:01 peter
  452. * first things to store the symbol/def number in the ppu
  453. Revision 1.35 1999/04/07 15:39:35 pierre
  454. + double_checksum code added
  455. Revision 1.34 1999/03/02 13:49:19 peter
  456. * renamed loadunit_int -> loadunit
  457. Revision 1.33 1999/02/23 18:29:25 pierre
  458. * win32 compilation error fix
  459. + some work for local browser (not cl=omplete yet)
  460. Revision 1.32 1999/02/22 13:07:08 pierre
  461. + -b and -bl options work !
  462. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  463. is not enabled when quitting global section
  464. * local vars and procedures are not yet stored into PPU
  465. Revision 1.31 1999/02/16 00:48:25 peter
  466. * save in the ppu if linked with obj file instead of using the
  467. library flag, so the .inc files are also checked
  468. Revision 1.30 1999/02/05 08:54:30 pierre
  469. + linkofiles splitted inot linkofiles and linkunitfiles
  470. because linkofiles must be stored with directory
  471. to enabled linking of different objects with same name
  472. in a different directory
  473. Revision 1.29 1999/01/20 10:16:46 peter
  474. * don't update crc when writing objs,libs and sources
  475. Revision 1.28 1999/01/12 14:25:35 peter
  476. + BrowserLog for browser.log generation
  477. + BrowserCol for browser info in TCollections
  478. * released all other UseBrowser
  479. Revision 1.27 1998/12/08 10:18:14 peter
  480. + -gh for heaptrc unit
  481. Revision 1.26 1998/11/26 14:36:02 peter
  482. * set also library flag if smartlinking and outputname is different
  483. Revision 1.25 1998/10/26 09:35:47 peter
  484. * don't count includefiles which are found in the includepath for a
  485. recompile.
  486. Revision 1.24 1998/10/20 08:06:59 pierre
  487. * several memory corruptions due to double freemem solved
  488. => never use p^.loc.location:=p^.left^.loc.location;
  489. + finally I added now by default
  490. that ra386dir translates global and unit symbols
  491. + added a first field in tsymtable and
  492. a nextsym field in tsym
  493. (this allows to obtain ordered type info for
  494. records and objects in gdb !)
  495. Revision 1.23 1998/10/16 13:37:24 florian
  496. + switch -FD added to specify the path for utilities
  497. Revision 1.22 1998/10/14 13:38:24 peter
  498. * fixed path with staticlib/objects in ppufiles
  499. Revision 1.21 1998/10/14 10:45:10 pierre
  500. * ppu problems for m68k fixed (at least in cross compiling)
  501. * one last memory leak for sysamiga fixed
  502. * the amiga RTL compiles now completely !!
  503. Revision 1.20 1998/10/13 13:10:30 peter
  504. * new style for m68k/i386 infos and enums
  505. Revision 1.19 1998/10/08 23:29:07 peter
  506. * -vu shows unit info, -vt shows tried/used files
  507. Revision 1.18 1998/09/28 16:57:27 pierre
  508. * changed all length(p^.value_str^) into str_length(p)
  509. to get it work with and without ansistrings
  510. * changed sourcefiles field of tmodule to a pointer
  511. Revision 1.17 1998/09/22 17:13:53 pierre
  512. + browsing updated and developed
  513. records and objects fields are also stored
  514. Revision 1.16 1998/09/22 15:40:56 peter
  515. * some extra ifdef GDB
  516. Revision 1.15 1998/09/21 08:45:23 pierre
  517. + added vmt_offset in tobjectdef.write for fututre use
  518. (first steps to have objects without vmt if no virtual !!)
  519. + added fpu_used field for tabstractprocdef :
  520. sets this level to 2 if the functions return with value in FPU
  521. (is then set to correct value at parsing of implementation)
  522. THIS MIGHT refuse some code with FPU expression too complex
  523. that were accepted before and even in some cases
  524. that don't overflow in fact
  525. ( like if f : float; is a forward that finally in implementation
  526. only uses one fpu register !!)
  527. Nevertheless I think that it will improve security on
  528. FPU operations !!
  529. * most other changes only for UseBrowser code
  530. (added symtable references for record and objects)
  531. local switch for refs to args and local of each function
  532. (static symtable still missing)
  533. UseBrowser still not stable and probably broken by
  534. the definition hash array !!
  535. Revision 1.14 1998/09/01 07:54:24 pierre
  536. * UseBrowser a little updated (might still be buggy !!)
  537. * bug in psub.pas in function specifier removed
  538. * stdcall allowed in interface and in implementation
  539. (FPC will not yet complain if it is missing in either part
  540. because stdcall is only a dummy !!)
  541. Revision 1.13 1998/08/17 10:10:11 peter
  542. - removed OLDPPU
  543. Revision 1.12 1998/08/17 09:17:53 peter
  544. * static/shared linking updates
  545. Revision 1.11 1998/08/16 20:32:49 peter
  546. * crcs of used units are not important for the current crc, reduces the
  547. amount of recompiles
  548. Revision 1.10 1998/08/13 10:57:30 peter
  549. * constant sets are now written correctly to the ppufile
  550. Revision 1.9 1998/08/11 15:31:41 peter
  551. * write extended to ppu file
  552. * new version 0.99.7
  553. Revision 1.8 1998/08/10 14:50:29 peter
  554. + localswitches, moduleswitches, globalswitches splitting
  555. Revision 1.7 1998/07/14 14:47:07 peter
  556. * released NEWINPUT
  557. Revision 1.6 1998/07/07 11:20:14 peter
  558. + NEWINPUT for a better inputfile and scanner object
  559. Revision 1.5 1998/06/24 14:48:39 peter
  560. * ifdef newppu -> ifndef oldppu
  561. Revision 1.4 1998/06/16 08:56:32 peter
  562. + targetcpu
  563. * cleaner pmodules for newppu
  564. Revision 1.3 1998/06/13 00:10:17 peter
  565. * working browser and newppu
  566. * some small fixes against crashes which occured in bp7 (but not in
  567. fpc?!)
  568. Revision 1.2 1998/05/28 14:40:28 peter
  569. * fixes for newppu, remake3 works now with it
  570. Revision 1.1 1998/05/27 19:45:09 peter
  571. * symtable.pas splitted into includefiles
  572. * symtable adapted for $ifdef NEWPPU
  573. }