symppu.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. {$ifndef OLDPPU}
  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. {$ifndef OLDPPU}
  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. current_ppu^.do_interface_crc:=hp^.in_interface;
  149. current_ppu^.putstring(hp^.name^);
  150. { the checksum should not affect the crc of this unit ! (PFV) }
  151. current_ppu^.do_crc:=false;
  152. current_ppu^.putlongint(hp^.checksum);
  153. {$ifndef OLDPPU}
  154. current_ppu^.putlongint(hp^.interface_checksum);
  155. {$endif}
  156. current_ppu^.do_crc:=true;
  157. current_ppu^.putbyte(byte(hp^.in_interface));
  158. hp:=pused_unit(hp^.next);
  159. end;
  160. current_ppu^.do_interface_crc:=true;
  161. current_ppu^.writeentry(ibloadunit);
  162. end;
  163. procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
  164. begin
  165. Message1(unit_u_ppu_write,s);
  166. { create unit flags }
  167. with Current_Module^ do
  168. begin
  169. if (((cs_create_staticlib in aktmoduleswitches) or
  170. (cs_smartlink in aktmoduleswitches)) and
  171. (SplitName(ppufilename^)<>SplitName(staticlibfilename^))) or
  172. ((cs_create_sharedlib in aktmoduleswitches) and
  173. (SplitName(ppufilename^)<>SplitName(sharedlibfilename^))) then
  174. flags:=flags or uf_in_library;
  175. if cs_smartlink in aktmoduleswitches then
  176. flags:=flags or uf_smartlink;
  177. {$ifdef GDB}
  178. if cs_gdb_dbx in aktglobalswitches then
  179. flags:=flags or uf_has_dbx;
  180. {$endif GDB}
  181. if target_os.endian=endian_big then
  182. flags:=flags or uf_big_endian;
  183. if cs_browser in aktmoduleswitches then
  184. flags:=flags or uf_has_browser;
  185. if cs_local_browser in aktmoduleswitches then
  186. flags:=flags or uf_local_browser;
  187. end;
  188. {$ifdef Test_Double_checksum_write}
  189. If only_crc then
  190. Assign(CRCFile,s+'.INT')
  191. else
  192. Assign(CRCFile,s+'.IMP');
  193. Rewrite(CRCFile);
  194. {$endif def Test_Double_checksum_write}
  195. { open ppufile }
  196. current_ppu:=new(pppufile,init(s));
  197. if not current_ppu^.create then
  198. Message(unit_f_ppu_cannot_write);
  199. current_ppu^.crc_only:=only_crc;
  200. {$ifdef Test_Double_checksum}
  201. if only_crc then
  202. begin
  203. new(current_ppu^.crc_test);
  204. end
  205. else
  206. begin
  207. current_ppu^.crc_test:=Current_Module^.crc_array;
  208. current_ppu^.crc_index:=Current_Module^.crc_size;
  209. end;
  210. {$endif def Test_Double_checksum}
  211. current_ppu^.change_endian:=source_os.endian<>target_os.endian;
  212. { write symbols and definitions }
  213. unittable^.writeasunit;
  214. { flush to be sure }
  215. current_ppu^.flush;
  216. { create and write header }
  217. current_ppu^.header.size:=current_ppu^.size;
  218. current_ppu^.header.checksum:=current_ppu^.crc;
  219. {$ifndef OLDPPU}
  220. current_ppu^.header.interface_checksum:=current_ppu^.interface_crc;
  221. {$endif}
  222. current_ppu^.header.compiler:=wordversion;
  223. current_ppu^.header.cpu:=word(target_cpu);
  224. current_ppu^.header.target:=word(target_info.target);
  225. current_ppu^.header.flags:=current_module^.flags;
  226. current_ppu^.writeheader;
  227. { save crc in current_module also }
  228. current_module^.crc:=current_ppu^.crc;
  229. current_module^.interface_crc:=current_ppu^.interface_crc;
  230. if only_crc then
  231. begin
  232. {$ifdef Test_Double_checksum}
  233. Current_Module^.crc_array:=current_ppu^.crc_test;
  234. current_ppu^.crc_test:=nil;
  235. Current_Module^.crc_size:=current_ppu^.crc_index;
  236. {$endif def Test_Double_checksum}
  237. closecurrentppu;
  238. end;
  239. {$ifdef Test_Double_checksum_write}
  240. close(CRCFile);
  241. {$endif Test_Double_checksum_write}
  242. end;
  243. procedure closecurrentppu;
  244. begin
  245. {$ifdef Test_Double_checksum}
  246. if assigned(current_ppu^.crc_test) then
  247. dispose(current_ppu^.crc_test);
  248. {$endif Test_Double_checksum}
  249. { close }
  250. current_ppu^.close;
  251. dispose(current_ppu,done);
  252. current_ppu:=nil;
  253. end;
  254. {*****************************************************************************
  255. PPU Reading
  256. *****************************************************************************}
  257. function readbyte:byte;
  258. begin
  259. readbyte:=current_ppu^.getbyte;
  260. if current_ppu^.error then
  261. Message(unit_f_ppu_read_error);
  262. end;
  263. function readword:word;
  264. begin
  265. readword:=current_ppu^.getword;
  266. if current_ppu^.error then
  267. Message(unit_f_ppu_read_error);
  268. end;
  269. function readlong:longint;
  270. begin
  271. readlong:=current_ppu^.getlongint;
  272. if current_ppu^.error then
  273. Message(unit_f_ppu_read_error);
  274. end;
  275. function readreal : bestreal;
  276. begin
  277. readreal:=current_ppu^.getreal;
  278. if current_ppu^.error then
  279. Message(unit_f_ppu_read_error);
  280. end;
  281. function readstring : string;
  282. begin
  283. readstring:=current_ppu^.getstring;
  284. if current_ppu^.error then
  285. Message(unit_f_ppu_read_error);
  286. end;
  287. procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
  288. begin
  289. current_ppu^.getdata(s,sizeof(tnormalset));
  290. if current_ppu^.error then
  291. Message(unit_f_ppu_read_error);
  292. end;
  293. procedure readcontainer(var p:tstringcontainer);
  294. begin
  295. while not current_ppu^.endofentry do
  296. p.insert(current_ppu^.getstring);
  297. end;
  298. procedure readposinfo(var p:tfileposinfo);
  299. begin
  300. p.fileindex:=current_ppu^.getword;
  301. p.line:=current_ppu^.getlongint;
  302. p.column:=current_ppu^.getword;
  303. end;
  304. function readdefref : pdef;
  305. var
  306. hd : pdef;
  307. begin
  308. longint(hd):=current_ppu^.getword;
  309. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  310. readdefref:=hd;
  311. end;
  312. function readsymref : psym;
  313. var
  314. hd : psym;
  315. begin
  316. longint(hd):=current_ppu^.getword;
  317. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  318. readsymref:=hd;
  319. end;
  320. procedure readsourcefiles;
  321. var
  322. temp,hs : string;
  323. incfile_found : boolean;
  324. ppufiletime,
  325. source_time : longint;
  326. hp : pinputfile;
  327. begin
  328. ppufiletime:=getnamedfiletime(current_module^.ppufilename^);
  329. current_module^.sources_avail:=true;
  330. while not current_ppu^.endofentry do
  331. begin
  332. hs:=current_ppu^.getstring;
  333. temp:='';
  334. if (current_module^.flags and uf_in_library)<>0 then
  335. begin
  336. current_module^.sources_avail:=false;
  337. temp:=' library';
  338. end
  339. else if pos('Macro ',hs)=1 then
  340. begin
  341. { we don't want to find this file }
  342. { but there is a problem with file indexing !! }
  343. temp:='';
  344. end
  345. else
  346. begin
  347. { check the date of the source files }
  348. Source_Time:=GetNamedFileTime(current_module^.path^+hs);
  349. incfile_found:=false;
  350. if (Source_Time=-1) then
  351. begin
  352. temp:=search(hs,includesearchpath,incfile_found);
  353. if incfile_found then
  354. begin
  355. hs:=temp+hs;
  356. Source_Time:=GetNamedFileTime(hs);
  357. end
  358. end
  359. else
  360. hs:=current_module^.path^+hs;
  361. if Source_Time=-1 then
  362. begin
  363. current_module^.sources_avail:=false;
  364. temp:=' not found';
  365. end
  366. else
  367. begin
  368. { time newer? But only allow if the file is not searched
  369. in the include path (PFV), else you've problems with
  370. units which use the same includefile names }
  371. if incfile_found then
  372. temp:=' found'
  373. else
  374. begin
  375. temp:=' time '+filetimestring(source_time);
  376. if (source_time>ppufiletime) then
  377. begin
  378. current_module^.do_compile:=true;
  379. temp:=temp+' *'
  380. end;
  381. end;
  382. end;
  383. new(hp,init(hs));
  384. { the indexing is wrong here PM }
  385. current_module^.sourcefiles^.register_file(hp);
  386. end;
  387. Message1(unit_u_ppu_source,hs+temp);
  388. end;
  389. { main source is always the last }
  390. stringdispose(current_module^.mainsource);
  391. current_module^.mainsource:=stringdup(hs);
  392. { the indexing is corrected here PM }
  393. current_module^.sourcefiles^.inverse_register_indexes;
  394. { check if we want to rebuild every unit, only if the sources are
  395. available }
  396. if do_build and current_module^.sources_avail then
  397. current_module^.do_compile:=true;
  398. end;
  399. procedure readloadunit;
  400. var
  401. hs : string;
  402. intfchecksum,
  403. checksum : longint;
  404. in_interface : boolean;
  405. begin
  406. while not current_ppu^.endofentry do
  407. begin
  408. hs:=current_ppu^.getstring;
  409. checksum:=current_ppu^.getlongint;
  410. {$ifndef OLDPPU}
  411. intfchecksum:=current_ppu^.getlongint;
  412. {$else}
  413. intfchecksum:=0;
  414. {$endif}
  415. in_interface:=(current_ppu^.getbyte<>0);
  416. current_module^.used_units.concat(new(pused_unit,init_to_load(hs,checksum,intfchecksum,in_interface)));
  417. end;
  418. end;
  419. procedure load_interface;
  420. var
  421. b : byte;
  422. begin
  423. { read interface part }
  424. repeat
  425. b:=current_ppu^.readentry;
  426. case b of
  427. ibmodulename : begin
  428. stringdispose(current_module^.modulename);
  429. current_module^.modulename:=stringdup(current_ppu^.getstring);
  430. end;
  431. ibsourcefiles : readsourcefiles;
  432. ibloadunit : readloadunit;
  433. iblinksharedlibs : readcontainer(current_module^.LinkSharedLibs);
  434. iblinkstaticlibs : readcontainer(current_module^.LinkStaticLibs);
  435. iblinkunitfiles : readcontainer(current_module^.LinkUnitFiles);
  436. iblinkofiles : readcontainer(current_module^.LinkOFiles);
  437. ibendinterface : break;
  438. else
  439. Message1(unit_f_ppu_invalid_entry,tostr(b));
  440. end;
  441. until false;
  442. end;
  443. {
  444. $Log$
  445. Revision 1.38 1999-04-26 13:31:51 peter
  446. * release storenumber,double_checksum
  447. Revision 1.37 1999/04/21 09:43:53 peter
  448. * storenumber works
  449. * fixed some typos in double_checksum
  450. + incompatible types type1 and type2 message (with storenumber)
  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. }