symppu.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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: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. current_ppu^.putstring(s);
  66. if hold then
  67. hcontainer.insert(s);
  68. end;
  69. current_ppu^.writeentry(id);
  70. if hold then
  71. p:=hcontainer;
  72. end;
  73. procedure writeposinfo(const p:tfileposinfo);
  74. begin
  75. current_ppu^.putword(p.fileindex);
  76. current_ppu^.putlongint(p.line);
  77. current_ppu^.putword(p.column);
  78. end;
  79. procedure writedefref(p : pdef);
  80. begin
  81. if p=nil then
  82. current_ppu^.putlongint($ffffffff)
  83. else
  84. begin
  85. if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
  86. current_ppu^.putword($ffff)
  87. else
  88. current_ppu^.putword(p^.owner^.unitid);
  89. current_ppu^.putword(p^.indexnb);
  90. end;
  91. end;
  92. procedure writesymref(p : psym);
  93. begin
  94. if p=nil then
  95. current_ppu^.putlongint($ffffffff)
  96. else
  97. begin
  98. if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
  99. current_ppu^.putword($ffff)
  100. else
  101. current_ppu^.putword(p^.owner^.unitid);
  102. current_ppu^.putword(p^.indexnb);
  103. end;
  104. end;
  105. procedure writesourcefiles;
  106. var
  107. hp : pinputfile;
  108. index : longint;
  109. begin
  110. { second write the used source files }
  111. hp:=current_module^.sourcefiles.files;
  112. index:=current_module^.sourcefiles.last_ref_index;
  113. while assigned(hp) do
  114. begin
  115. { only name and extension }
  116. current_ppu^.putstring(hp^.name^);
  117. { index in that order }
  118. hp^.ref_index:=index;
  119. dec(index);
  120. hp:=hp^.ref_next;
  121. end;
  122. current_ppu^.writeentry(ibsourcefiles);
  123. end;
  124. procedure writeusedunit;
  125. var
  126. hp : pused_unit;
  127. begin
  128. numberunits;
  129. hp:=pused_unit(current_module^.used_units.first);
  130. while assigned(hp) do
  131. begin
  132. current_ppu^.putstring(hp^.name^);
  133. { the checksum should not affect the crc of this unit ! (PFV) }
  134. current_ppu^.do_crc:=false;
  135. current_ppu^.putlongint(hp^.checksum);
  136. current_ppu^.do_crc:=true;
  137. current_ppu^.putbyte(byte(hp^.in_interface));
  138. hp:=pused_unit(hp^.next);
  139. end;
  140. current_ppu^.writeentry(ibloadunit_int);
  141. end;
  142. procedure writeunitas(const s : string;unittable : punitsymtable);
  143. begin
  144. Message1(unit_u_ppu_write,s);
  145. { create unit flags }
  146. with Current_Module^ do
  147. begin
  148. if cs_create_staticlib in aktmoduleswitches then
  149. begin
  150. flags:=flags or uf_static_linked;
  151. if SplitName(ppufilename^)<>SplitName(staticlibfilename^) then
  152. flags:=flags or uf_in_library;
  153. end;
  154. if cs_create_sharedlib in aktmoduleswitches then
  155. begin
  156. flags:=flags or uf_shared_linked;
  157. if SplitName(ppufilename^)<>SplitName(sharedlibfilename^) then
  158. flags:=flags or uf_in_library;
  159. end;
  160. if cs_smartlink in aktmoduleswitches then
  161. flags:=flags or uf_smartlink;
  162. if use_dbx then
  163. flags:=flags or uf_has_dbx;
  164. if target_os.endian=en_big_endian then
  165. flags:=flags or uf_big_endian;
  166. {$ifdef UseBrowser}
  167. if cs_browser in aktmoduleswitches then
  168. flags:=flags or uf_has_browser;
  169. {$endif UseBrowser}
  170. end;
  171. { open ppufile }
  172. current_ppu:=new(pppufile,init(s));
  173. current_ppu^.change_endian:=source_os.endian<>target_os.endian;
  174. if not current_ppu^.create then
  175. Message(unit_f_ppu_cannot_write);
  176. { write symbols and definitions }
  177. unittable^.writeasunit;
  178. { flush to be sure }
  179. current_ppu^.flush;
  180. { create and write header }
  181. current_ppu^.header.size:=current_ppu^.size;
  182. current_ppu^.header.checksum:=current_ppu^.crc;
  183. current_ppu^.header.compiler:=wordversion;
  184. current_ppu^.header.cpu:=word(target_cpu);
  185. current_ppu^.header.target:=word(target_info.target);
  186. current_ppu^.header.flags:=current_module^.flags;
  187. current_ppu^.writeheader;
  188. { save crc in current_module also }
  189. current_module^.crc:=current_ppu^.crc;
  190. { close }
  191. current_ppu^.close;
  192. dispose(current_ppu,done);
  193. end;
  194. {*****************************************************************************
  195. PPU Reading
  196. *****************************************************************************}
  197. function readbyte:byte;
  198. begin
  199. readbyte:=current_ppu^.getbyte;
  200. if current_ppu^.error then
  201. Message(unit_f_ppu_read_error);
  202. end;
  203. function readword:word;
  204. begin
  205. readword:=current_ppu^.getword;
  206. if current_ppu^.error then
  207. Message(unit_f_ppu_read_error);
  208. end;
  209. function readlong:longint;
  210. begin
  211. readlong:=current_ppu^.getlongint;
  212. if current_ppu^.error then
  213. Message(unit_f_ppu_read_error);
  214. end;
  215. function readreal : bestreal;
  216. begin
  217. readreal:=current_ppu^.getreal;
  218. if current_ppu^.error then
  219. Message(unit_f_ppu_read_error);
  220. end;
  221. function readstring : string;
  222. begin
  223. readstring:=current_ppu^.getstring;
  224. if current_ppu^.error then
  225. Message(unit_f_ppu_read_error);
  226. end;
  227. procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
  228. begin
  229. current_ppu^.getdata(s,sizeof(tnormalset));
  230. if current_ppu^.error then
  231. Message(unit_f_ppu_read_error);
  232. end;
  233. procedure readcontainer(var p:tstringcontainer);
  234. begin
  235. while not current_ppu^.endofentry do
  236. p.insert(current_ppu^.getstring);
  237. end;
  238. procedure readposinfo(var p:tfileposinfo);
  239. begin
  240. p.fileindex:=current_ppu^.getword;
  241. p.line:=current_ppu^.getlongint;
  242. p.column:=current_ppu^.getword;
  243. end;
  244. function readdefref : pdef;
  245. var
  246. hd : pdef;
  247. begin
  248. longint(hd):=current_ppu^.getword;
  249. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  250. readdefref:=hd;
  251. end;
  252. {$ifdef UseBrowser}
  253. function readsymref : psym;
  254. var
  255. hd : psym;
  256. begin
  257. longint(hd):=current_ppu^.getword;
  258. longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
  259. readsymref:=hd;
  260. end;
  261. {$endif}
  262. procedure readsourcefiles;
  263. var
  264. temp,hs : string;
  265. incfile_found : boolean;
  266. ppufiletime,
  267. source_time : longint;
  268. {$ifdef UseBrowser}
  269. hp : pinputfile;
  270. {$endif UseBrowser}
  271. begin
  272. ppufiletime:=getnamedfiletime(current_module^.ppufilename^);
  273. current_module^.sources_avail:=true;
  274. while not current_ppu^.endofentry do
  275. begin
  276. hs:=current_ppu^.getstring;
  277. temp:='';
  278. if (current_module^.flags and uf_in_library)<>0 then
  279. begin
  280. current_module^.sources_avail:=false;
  281. temp:=' library';
  282. end
  283. else if pos('Macro ',hs)=1 then
  284. begin
  285. { we don't want to find this file }
  286. { but there is a problem with file indexing !! }
  287. temp:='';
  288. end
  289. else
  290. begin
  291. { check the date of the source files }
  292. Source_Time:=GetNamedFileTime(current_module^.path^+hs);
  293. { search for include files in the includepathlist, this
  294. can't be done, becuase a .inc file with the same name as
  295. used by a unit will cause the unit to recompile which is
  296. not the intention (PFV) }
  297. { OK but then only the last filename
  298. should not be searched in include files (PM)}
  299. if (Source_Time=-1) and not current_ppu^.endofentry then
  300. begin
  301. temp:=search(hs,includesearchpath,incfile_found);
  302. if incfile_found then
  303. begin
  304. hs:=temp+hs;
  305. Source_Time:=GetNamedFileTime(hs);
  306. end;
  307. end
  308. else
  309. hs:=current_module^.path^+hs;
  310. if Source_Time=-1 then
  311. begin
  312. current_module^.sources_avail:=false;
  313. temp:=' not found';
  314. end
  315. else
  316. begin
  317. temp:=' time '+filetimestring(source_time);
  318. if (source_time>ppufiletime) then
  319. begin
  320. current_module^.do_compile:=true;
  321. temp:=temp+' *'
  322. end;
  323. end;
  324. end;
  325. Message1(unit_t_ppu_source,hs+temp);
  326. {$ifdef UseBrowser}
  327. new(hp,init(hs));
  328. { the indexing should match what is done in writeasunit }
  329. current_module^.sourcefiles.register_file(hp);
  330. {$endif UseBrowser}
  331. end;
  332. { main source is always the last }
  333. stringdispose(current_module^.mainsource);
  334. current_module^.mainsource:=stringdup(hs);
  335. { check if we want to rebuild every unit, only if the sources are
  336. available }
  337. if do_build and current_module^.sources_avail then
  338. current_module^.do_compile:=true;
  339. end;
  340. procedure readloadunit;
  341. var
  342. hs : string;
  343. checksum : longint;
  344. in_interface : boolean;
  345. begin
  346. while not current_ppu^.endofentry do
  347. begin
  348. hs:=current_ppu^.getstring;
  349. checksum:=current_ppu^.getlongint;
  350. in_interface:=(current_ppu^.getbyte<>0);
  351. current_module^.used_units.concat(new(pused_unit,init_to_load(hs,checksum,in_interface)));
  352. end;
  353. end;
  354. procedure load_interface;
  355. var
  356. b : byte;
  357. begin
  358. { read interface part }
  359. repeat
  360. b:=current_ppu^.readentry;
  361. case b of
  362. { ibinitunit : usedunits^.insert(readstring); }
  363. ibmodulename : begin
  364. stringdispose(current_module^.modulename);
  365. current_module^.modulename:=stringdup(current_ppu^.getstring);
  366. end;
  367. ibsourcefiles : readsourcefiles;
  368. ibloadunit_int : readloadunit;
  369. iblinksharedlibs : readcontainer(current_module^.LinkSharedLibs);
  370. iblinkstaticlibs : readcontainer(current_module^.LinkStaticLibs);
  371. iblinkofiles : readcontainer(current_module^.LinkOFiles);
  372. ibendinterface : break;
  373. else
  374. Message1(unit_f_ppu_invalid_entry,tostr(b));
  375. end;
  376. until false;
  377. end;
  378. {
  379. $Log$
  380. Revision 1.14 1998-09-01 07:54:24 pierre
  381. * UseBrowser a little updated (might still be buggy !!)
  382. * bug in psub.pas in function specifier removed
  383. * stdcall allowed in interface and in implementation
  384. (FPC will not yet complain if it is missing in either part
  385. because stdcall is only a dummy !!)
  386. Revision 1.13 1998/08/17 10:10:11 peter
  387. - removed OLDPPU
  388. Revision 1.12 1998/08/17 09:17:53 peter
  389. * static/shared linking updates
  390. Revision 1.11 1998/08/16 20:32:49 peter
  391. * crcs of used units are not important for the current crc, reduces the
  392. amount of recompiles
  393. Revision 1.10 1998/08/13 10:57:30 peter
  394. * constant sets are now written correctly to the ppufile
  395. Revision 1.9 1998/08/11 15:31:41 peter
  396. * write extended to ppu file
  397. * new version 0.99.7
  398. Revision 1.8 1998/08/10 14:50:29 peter
  399. + localswitches, moduleswitches, globalswitches splitting
  400. Revision 1.7 1998/07/14 14:47:07 peter
  401. * released NEWINPUT
  402. Revision 1.6 1998/07/07 11:20:14 peter
  403. + NEWINPUT for a better inputfile and scanner object
  404. Revision 1.5 1998/06/24 14:48:39 peter
  405. * ifdef newppu -> ifndef oldppu
  406. Revision 1.4 1998/06/16 08:56:32 peter
  407. + targetcpu
  408. * cleaner pmodules for newppu
  409. Revision 1.3 1998/06/13 00:10:17 peter
  410. * working browser and newppu
  411. * some small fixes against crashes which occured in bp7 (but not in
  412. fpc?!)
  413. Revision 1.2 1998/05/28 14:40:28 peter
  414. * fixes for newppu, remake3 works now with it
  415. Revision 1.1 1998/05/27 19:45:09 peter
  416. * symtable.pas splitted into includefiles
  417. * symtable adapted for $ifdef NEWPPU
  418. }