ppu.pas 21 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Routines to read/write ppu files
  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. {$ifdef TP}
  19. {$N+,E+}
  20. {$endif}
  21. unit ppu;
  22. interface
  23. {$ifdef Test_Double_checksum}
  24. var
  25. CRCFile : text;
  26. const
  27. CRC_array_Size = 20000;
  28. type
  29. tcrc_array = array[0..crc_array_size] of longint;
  30. pcrc_array = ^tcrc_array;
  31. {$endif Test_Double_checksum}
  32. const
  33. {$ifndef Double_checksum}
  34. CurrentPPUVersion=15;
  35. {$else Double_checksum}
  36. CurrentPPUVersion=16;
  37. {$endif def Double_checksum}
  38. { buffer sizes }
  39. maxentrysize = 1024;
  40. {$ifdef TP}
  41. ppubufsize = 1024;
  42. {$else}
  43. ppubufsize = 16384;
  44. {$endif}
  45. {ppu entries}
  46. mainentryid = 1;
  47. subentryid = 2;
  48. {special}
  49. iberror = 0;
  50. ibstartdefs = 248;
  51. ibenddefs = 249;
  52. ibstartsyms = 250;
  53. ibendsyms = 251;
  54. ibendinterface = 252;
  55. ibendimplementation = 253;
  56. ibendbrowser = 254;
  57. ibend = 255;
  58. {general}
  59. ibmodulename = 1;
  60. ibsourcefiles = 2;
  61. ibloadunit = 3;
  62. ibinitunit = 5;
  63. iblinkofiles = 6;
  64. iblinksharedlibs = 7;
  65. iblinkstaticlibs = 8;
  66. ibdbxcount = 9;
  67. ibsymref = 10;
  68. ibdefref = 11;
  69. ibendsymtablebrowser = 12;
  70. ibbeginsymtablebrowser = 13;
  71. iblinkunitfiles = 14;
  72. {syms}
  73. ibtypesym = 20;
  74. ibprocsym = 21;
  75. ibvarsym = 22;
  76. ibconstsym = 23;
  77. ibenumsym = 24;
  78. ibtypedconstsym = 25;
  79. ibabsolutesym = 26;
  80. ibpropertysym = 27;
  81. ibvarsym_C = 28;
  82. ibunitsym = 29; { needed for browser }
  83. iblabelsym = 30;
  84. ibfuncretsym = 31;
  85. {definitions}
  86. iborddef = 40;
  87. ibpointerdef = 41;
  88. ibarraydef = 42;
  89. ibprocdef = 43;
  90. ibstringdef = 44;
  91. ibrecorddef = 45;
  92. ibfiledef = 46;
  93. ibformaldef = 47;
  94. ibobjectdef = 48;
  95. ibenumdef = 49;
  96. ibsetdef = 50;
  97. ibprocvardef = 51;
  98. ibfloatdef = 52;
  99. ibclassrefdef = 53;
  100. iblongstringdef = 54;
  101. ibansistringdef = 55;
  102. ibwidestringdef = 56;
  103. ibfarpointerdef = 57;
  104. { unit flags }
  105. uf_init = $1;
  106. uf_finalize = $2;
  107. uf_big_endian = $4;
  108. uf_has_dbx = $8;
  109. uf_has_browser = $10;
  110. uf_smartlink = $20; { the ppu is smartlinked }
  111. uf_in_library = $40; { is the file in another file than <ppufile>.* ? }
  112. uf_static_linked = $80; { the ppu is linked in a static library }
  113. uf_shared_linked = $100; { the ppu is linked in a shared library }
  114. uf_local_browser = $200;
  115. uf_obj_linked = $400; { the ppu is linked in a object file }
  116. type
  117. {$ifdef m68k}
  118. ppureal=single;
  119. {$else}
  120. ppureal=extended;
  121. {$endif}
  122. tppuerror=(ppuentrytoobig,ppuentryerror);
  123. tppuheader=packed record
  124. id : array[1..3] of char; { = 'PPU' }
  125. ver : array[1..3] of char;
  126. compiler : word;
  127. cpu : word;
  128. target : word;
  129. flags : longint;
  130. size : longint; { size of the ppufile without header }
  131. checksum : longint; { checksum for this ppufile }
  132. {$ifdef Double_checksum}
  133. interface_checksum : longint;
  134. {$endif def Double_checksum}
  135. end;
  136. tppuentry=packed record
  137. id : byte;
  138. nr : byte;
  139. size : longint;
  140. end;
  141. pppufile=^tppufile;
  142. tppufile=object
  143. f : file;
  144. mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
  145. error : boolean;
  146. fname : string;
  147. fsize : longint;
  148. header : tppuheader;
  149. size,crc : longint;
  150. {$ifdef Double_checksum}
  151. {$ifdef Test_Double_checksum}
  152. crcindex : longint;
  153. crc_index : longint;
  154. crc_test : pcrc_array;
  155. {$endif def Test_Double_checksum}
  156. interface_crc : longint;
  157. do_interface_crc : boolean;
  158. { used to calculate interface_crc
  159. before implementation }
  160. crc_only : boolean;
  161. {$endif def Double_checksum}
  162. do_crc,
  163. change_endian : boolean;
  164. buf : pchar;
  165. bufstart,
  166. bufsize,
  167. bufidx : longint;
  168. entrybufstart,
  169. entrystart,
  170. entryidx : longint;
  171. entry : tppuentry;
  172. entrytyp : byte;
  173. constructor init(fn:string);
  174. destructor done;
  175. procedure flush;
  176. procedure close;
  177. function CheckPPUId:boolean;
  178. function GetPPUVersion:longint;
  179. procedure NewHeader;
  180. procedure NewEntry;
  181. {read}
  182. function open:boolean;
  183. procedure reloadbuf;
  184. procedure readdata(var b;len:longint);
  185. procedure skipdata(len:longint);
  186. function readentry:byte;
  187. function EndOfEntry:boolean;
  188. procedure getdatabuf(var b;len:longint;var result:longint);
  189. procedure getdata(var b;len:longint);
  190. function getbyte:byte;
  191. function getword:word;
  192. function getlongint:longint;
  193. function getreal:ppureal;
  194. function getstring:string;
  195. function skipuntilentry(untilb:byte):boolean;
  196. {write}
  197. function create:boolean;
  198. procedure writeheader;
  199. procedure writebuf;
  200. procedure writedata(var b;len:longint);
  201. procedure writeentry(ibnr:byte);
  202. procedure putdata(var b;len:longint);
  203. procedure putbyte(b:byte);
  204. procedure putword(w:word);
  205. procedure putlongint(l:longint);
  206. procedure putreal(d:ppureal);
  207. procedure putstring(s:string);
  208. end;
  209. implementation
  210. {$ifdef Test_Double_checksum}
  211. uses
  212. comphook;
  213. {$endif def Test_Double_checksum}
  214. {*****************************************************************************
  215. Crc 32
  216. *****************************************************************************}
  217. var
  218. Crc32Tbl : array[0..255] of longint;
  219. procedure MakeCRC32Tbl;
  220. var
  221. crc : longint;
  222. i,n : byte;
  223. begin
  224. for i:=0 to 255 do
  225. begin
  226. crc:=i;
  227. for n:=1 to 8 do
  228. if odd(crc) then
  229. crc:=(crc shr 1) xor $edb88320
  230. else
  231. crc:=crc shr 1;
  232. Crc32Tbl[i]:=crc;
  233. end;
  234. end;
  235. {$ifopt R+}
  236. {$define Range_check_on}
  237. {$endif opt R+}
  238. {$R- needed here }
  239. {CRC 32}
  240. Function Crc32(Const HStr:String):longint;
  241. var
  242. i,InitCrc : longint;
  243. begin
  244. if Crc32Tbl[1]=0 then
  245. MakeCrc32Tbl;
  246. InitCrc:=$ffffffff;
  247. for i:=1to Length(Hstr) do
  248. InitCrc:=Crc32Tbl[byte(InitCrc) xor ord(Hstr[i])] xor (InitCrc shr 8);
  249. Crc32:=InitCrc;
  250. end;
  251. Function UpdateCrc32(InitCrc:longint;var InBuf;InLen:Longint):longint;
  252. var
  253. i : word;
  254. p : pchar;
  255. begin
  256. if Crc32Tbl[1]=0 then
  257. MakeCrc32Tbl;
  258. p:=@InBuf;
  259. for i:=1to InLen do
  260. begin
  261. InitCrc:=Crc32Tbl[byte(InitCrc) xor byte(p^)] xor (InitCrc shr 8);
  262. inc(longint(p));
  263. end;
  264. UpdateCrc32:=InitCrc;
  265. end;
  266. Function UpdCrc32(InitCrc:longint;b:byte):longint;
  267. begin
  268. if Crc32Tbl[1]=0 then
  269. MakeCrc32Tbl;
  270. UpdCrc32:=Crc32Tbl[byte(InitCrc) xor b] xor (InitCrc shr 8);
  271. end;
  272. {$ifdef Range_check_on}
  273. {$R+}
  274. {$undef Range_check_on}
  275. {$endif Range_check_on}
  276. {*****************************************************************************
  277. TPPUFile
  278. *****************************************************************************}
  279. constructor tppufile.init(fn:string);
  280. begin
  281. fname:=fn;
  282. change_endian:=false;
  283. {$ifdef Double_checksum}
  284. crc_only:=false;
  285. {$endif Double_checksum}
  286. Mode:=0;
  287. NewHeader;
  288. Error:=false;
  289. getmem(buf,ppubufsize);
  290. end;
  291. destructor tppufile.done;
  292. begin
  293. close;
  294. freemem(buf,ppubufsize);
  295. end;
  296. procedure tppufile.flush;
  297. begin
  298. if Mode=2 then
  299. writebuf;
  300. end;
  301. procedure tppufile.close;
  302. var
  303. i : word;
  304. begin
  305. if Mode<>0 then
  306. begin
  307. Flush;
  308. {$I-}
  309. system.close(f);
  310. {$I+}
  311. i:=ioresult;
  312. Mode:=0;
  313. end;
  314. end;
  315. function tppufile.CheckPPUId:boolean;
  316. begin
  317. CheckPPUId:=((Header.Id[1]='P') and (Header.Id[2]='P') and (Header.Id[3]='U'));
  318. end;
  319. function tppufile.GetPPUVersion:longint;
  320. var
  321. l : longint;
  322. code : word;
  323. begin
  324. Val(header.ver[1]+header.ver[2]+header.ver[3],l,code);
  325. if code=0 then
  326. GetPPUVersion:=l
  327. else
  328. GetPPUVersion:=0;
  329. end;
  330. procedure tppufile.NewHeader;
  331. begin
  332. fillchar(header,sizeof(tppuheader),0);
  333. with header do
  334. begin
  335. Id[1]:='P';
  336. Id[2]:='P';
  337. Id[3]:='U';
  338. Ver[1]:='0';
  339. Ver[2]:='1';
  340. {$ifndef Double_checksum}
  341. Ver[3]:='5';
  342. {$else Double_checksum}
  343. Ver[3]:='6';
  344. {$endif def Double_checksum}
  345. end;
  346. end;
  347. {*****************************************************************************
  348. TPPUFile Reading
  349. *****************************************************************************}
  350. function tppufile.open:boolean;
  351. var
  352. ofmode : byte;
  353. i : word;
  354. begin
  355. open:=false;
  356. assign(f,fname);
  357. ofmode:=filemode;
  358. filemode:=$0;
  359. {$I-}
  360. reset(f,1);
  361. {$I+}
  362. filemode:=ofmode;
  363. if ioresult<>0 then
  364. exit;
  365. {read ppuheader}
  366. fsize:=filesize(f);
  367. if fsize<sizeof(tppuheader) then
  368. exit;
  369. blockread(f,header,sizeof(tppuheader),i);
  370. {reset buffer}
  371. bufstart:=i;
  372. bufsize:=0;
  373. bufidx:=0;
  374. Mode:=1;
  375. FillChar(entry,sizeof(tppuentry),0);
  376. entryidx:=0;
  377. entrystart:=0;
  378. entrybufstart:=0;
  379. Error:=false;
  380. open:=true;
  381. end;
  382. procedure tppufile.reloadbuf;
  383. {$ifdef TP}
  384. var
  385. i : word;
  386. {$endif}
  387. begin
  388. inc(bufstart,bufsize);
  389. {$ifdef TP}
  390. blockread(f,buf^,ppubufsize,i);
  391. bufsize:=i;
  392. {$else}
  393. blockread(f,buf^,ppubufsize,bufsize);
  394. {$endif}
  395. bufidx:=0;
  396. end;
  397. procedure tppufile.readdata(var b;len:longint);
  398. var
  399. p : pchar;
  400. left,
  401. idx : longint;
  402. begin
  403. p:=pchar(@b);
  404. idx:=0;
  405. while len>0 do
  406. begin
  407. left:=bufsize-bufidx;
  408. if len>left then
  409. begin
  410. move(buf[bufidx],p[idx],left);
  411. dec(len,left);
  412. inc(idx,left);
  413. reloadbuf;
  414. if bufsize=0 then
  415. exit;
  416. end
  417. else
  418. begin
  419. move(buf[bufidx],p[idx],len);
  420. inc(bufidx,len);
  421. exit;
  422. end;
  423. end;
  424. end;
  425. procedure tppufile.skipdata(len:longint);
  426. var
  427. left : longint;
  428. begin
  429. while len>0 do
  430. begin
  431. left:=bufsize-bufidx;
  432. if len>left then
  433. begin
  434. dec(len,left);
  435. reloadbuf;
  436. if bufsize=0 then
  437. exit;
  438. end
  439. else
  440. begin
  441. inc(bufidx,len);
  442. exit;
  443. end;
  444. end;
  445. end;
  446. function tppufile.readentry:byte;
  447. begin
  448. if entryidx<entry.size then
  449. skipdata(entry.size-entryidx);
  450. readdata(entry,sizeof(tppuentry));
  451. entrystart:=bufstart+bufidx;
  452. entryidx:=0;
  453. if not(entry.id in [mainentryid,subentryid]) then
  454. begin
  455. readentry:=iberror;
  456. error:=true;
  457. exit;
  458. end;
  459. readentry:=entry.nr;
  460. end;
  461. function tppufile.endofentry:boolean;
  462. begin
  463. endofentry:=(entryidx>=entry.size);
  464. end;
  465. procedure tppufile.getdatabuf(var b;len:longint;var result:longint);
  466. begin
  467. if entryidx+len>entry.size then
  468. result:=entry.size-entryidx
  469. else
  470. result:=len;
  471. readdata(b,result);
  472. inc(entryidx,result);
  473. end;
  474. procedure tppufile.getdata(var b;len:longint);
  475. begin
  476. if entryidx+len>entry.size then
  477. begin
  478. error:=true;
  479. exit;
  480. end;
  481. readdata(b,len);
  482. inc(entryidx,len);
  483. end;
  484. function tppufile.getbyte:byte;
  485. var
  486. b : byte;
  487. begin
  488. if entryidx+1>entry.size then
  489. begin
  490. error:=true;
  491. getbyte:=0;
  492. exit;
  493. end;
  494. readdata(b,1);
  495. getbyte:=b;
  496. inc(entryidx);
  497. end;
  498. function tppufile.getword:word;
  499. type
  500. pword = ^word;
  501. var
  502. w : word;
  503. begin
  504. if entryidx+2>entry.size then
  505. begin
  506. error:=true;
  507. getword:=0;
  508. exit;
  509. end;
  510. readdata(w,2);
  511. if change_endian then
  512. getword:=swap(w)
  513. else
  514. getword:=w;
  515. inc(entryidx,2);
  516. end;
  517. function tppufile.getlongint:longint;
  518. type
  519. plongint = ^longint;
  520. var
  521. l : longint;
  522. begin
  523. if entryidx+4>entry.size then
  524. begin
  525. error:=true;
  526. getlongint:=0;
  527. exit;
  528. end;
  529. readdata(l,4);
  530. if change_endian then
  531. { someone added swap(l : longint) in system unit
  532. this broke the following code !! }
  533. getlongint:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16)
  534. else
  535. getlongint:=l;
  536. inc(entryidx,4);
  537. end;
  538. function tppufile.getreal:ppureal;
  539. type
  540. pppureal = ^ppureal;
  541. var
  542. d : ppureal;
  543. begin
  544. if entryidx+sizeof(ppureal)>entry.size then
  545. begin
  546. error:=true;
  547. getreal:=0;
  548. exit;
  549. end;
  550. readdata(d,sizeof(ppureal));
  551. getreal:=d;
  552. inc(entryidx,sizeof(ppureal));
  553. end;
  554. function tppufile.getstring:string;
  555. var
  556. s : string;
  557. begin
  558. {$ifndef TP}
  559. {$ifopt H+}
  560. setlength(s,getbyte);
  561. {$else}
  562. s[0]:=chr(getbyte);
  563. {$endif}
  564. {$else}
  565. s[0]:=chr(getbyte);
  566. {$endif}
  567. if entryidx+length(s)>entry.size then
  568. begin
  569. error:=true;
  570. exit;
  571. end;
  572. ReadData(s[1],length(s));
  573. getstring:=s;
  574. inc(entryidx,length(s));
  575. end;
  576. function tppufile.skipuntilentry(untilb:byte):boolean;
  577. var
  578. b : byte;
  579. begin
  580. repeat
  581. b:=readentry;
  582. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  583. skipuntilentry:=(b=untilb);
  584. end;
  585. {*****************************************************************************
  586. TPPUFile Writing
  587. *****************************************************************************}
  588. function tppufile.create:boolean;
  589. begin
  590. create:=false;
  591. assign(f,fname);
  592. {$I-}
  593. rewrite(f,1);
  594. {$I+}
  595. if ioresult<>0 then
  596. exit;
  597. Mode:=2;
  598. {write header for sure}
  599. blockwrite(f,header,sizeof(tppuheader));
  600. bufsize:=ppubufsize;
  601. bufstart:=sizeof(tppuheader);
  602. bufidx:=0;
  603. {reset}
  604. crc:=$ffffffff;
  605. {$ifdef Double_checksum}
  606. interface_crc:=$ffffffff;
  607. do_interface_crc:=true;
  608. {$endif def Double_checksum}
  609. Error:=false;
  610. do_crc:=true;
  611. size:=0;
  612. entrytyp:=mainentryid;
  613. {start}
  614. NewEntry;
  615. create:=true;
  616. end;
  617. procedure tppufile.writeheader;
  618. var
  619. opos : longint;
  620. begin
  621. { flush buffer }
  622. writebuf;
  623. { update size (w/o header!) in the header }
  624. header.size:=bufstart-sizeof(tppuheader);
  625. { write header and restore filepos after it }
  626. opos:=filepos(f);
  627. seek(f,0);
  628. blockwrite(f,header,sizeof(tppuheader));
  629. seek(f,opos);
  630. end;
  631. procedure tppufile.writebuf;
  632. begin
  633. blockwrite(f,buf^,bufidx);
  634. inc(bufstart,bufidx);
  635. bufidx:=0;
  636. end;
  637. procedure tppufile.writedata(var b;len:longint);
  638. var
  639. p : pchar;
  640. left,
  641. idx : longint;
  642. begin
  643. p:=pchar(@b);
  644. idx:=0;
  645. while len>0 do
  646. begin
  647. left:=bufsize-bufidx;
  648. if len>left then
  649. begin
  650. move(p[idx],buf[bufidx],left);
  651. dec(len,left);
  652. inc(idx,left);
  653. inc(bufidx,left);
  654. writebuf;
  655. end
  656. else
  657. begin
  658. move(p[idx],buf[bufidx],len);
  659. inc(bufidx,len);
  660. exit;
  661. end;
  662. end;
  663. end;
  664. procedure tppufile.NewEntry;
  665. begin
  666. with entry do
  667. begin
  668. id:=entrytyp;
  669. nr:=ibend;
  670. size:=0;
  671. end;
  672. {Reset Entry State}
  673. entryidx:=0;
  674. entrybufstart:=bufstart;
  675. entrystart:=bufstart+bufidx;
  676. {Alloc in buffer}
  677. writedata(entry,sizeof(tppuentry));
  678. end;
  679. procedure tppufile.writeentry(ibnr:byte);
  680. var
  681. opos : longint;
  682. begin
  683. {create entry}
  684. entry.id:=entrytyp;
  685. entry.nr:=ibnr;
  686. entry.size:=entryidx;
  687. {it's already been sent to disk ?}
  688. if entrybufstart<>bufstart then
  689. begin
  690. {flush to be sure}
  691. WriteBuf;
  692. {write entry}
  693. opos:=filepos(f);
  694. seek(f,entrystart);
  695. blockwrite(f,entry,sizeof(tppuentry));
  696. seek(f,opos);
  697. entrybufstart:=bufstart;
  698. end
  699. else
  700. move(entry,buf[entrystart-bufstart],sizeof(entry));
  701. {Add New Entry, which is ibend by default}
  702. entrystart:=bufstart+bufidx; {next entry position}
  703. NewEntry;
  704. end;
  705. procedure tppufile.putdata(var b;len:longint);
  706. begin
  707. if do_crc then
  708. begin
  709. crc:=UpdateCrc32(crc,b,len);
  710. {$ifdef Double_checksum}
  711. if do_interface_crc then
  712. begin
  713. interface_crc:=UpdateCrc32(interface_crc,b,len);
  714. {$ifdef Test_Double_checksum}
  715. if crc_only then
  716. begin
  717. crc_test^[crc_index]:=interface_crc;
  718. {$ifdef Test_Double_checksum_write}
  719. Writeln(CRCFile,interface_crc);
  720. {$endif Test_Double_checksum_write}
  721. if crc_index<crc_array_size then
  722. inc(crc_index);
  723. end
  724. else
  725. begin
  726. if (crcindex<crc_array_size) and (crcindex<crc_index) and
  727. (crc_test^[crcindex]<>interface_crc) then
  728. Def_comment(V_Warning,'CRC changed');
  729. {$ifdef Test_Double_checksum_write}
  730. Writeln(CRCFile,interface_crc);
  731. {$endif Test_Double_checksum_write}
  732. inc(crcindex);
  733. end;
  734. {$endif def Test_Double_checksum}
  735. end;
  736. end;
  737. if not crc_only then
  738. {$else not def Double_checksum}
  739. end;
  740. {$endif def Double_checksum}
  741. writedata(b,len);
  742. inc(entryidx,len);
  743. end;
  744. procedure tppufile.putbyte(b:byte);
  745. begin
  746. writedata(b,1);
  747. inc(entryidx);
  748. end;
  749. procedure tppufile.putword(w:word);
  750. begin
  751. if change_endian then
  752. w:=swap(w);
  753. putdata(w,2);
  754. end;
  755. procedure tppufile.putlongint(l:longint);
  756. begin
  757. if change_endian then
  758. { someone added swap(l : longint) in system unit
  759. this broke the following code !! }
  760. l:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16);
  761. putdata(l,4);
  762. end;
  763. procedure tppufile.putreal(d:ppureal);
  764. begin
  765. putdata(d,sizeof(ppureal));
  766. end;
  767. procedure tppufile.putstring(s:string);
  768. begin
  769. putdata(s,length(s)+1);
  770. end;
  771. end.
  772. {
  773. $Log$
  774. Revision 1.26 1999-04-07 15:39:31 pierre
  775. + double_checksum code added
  776. Revision 1.25 1999/03/02 13:49:18 peter
  777. * renamed loadunit_int -> loadunit
  778. Revision 1.24 1999/02/22 13:07:00 pierre
  779. + -b and -bl options work !
  780. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  781. is not enabled when quitting global section
  782. * local vars and procedures are not yet stored into PPU
  783. Revision 1.23 1999/02/16 00:48:24 peter
  784. * save in the ppu if linked with obj file instead of using the
  785. library flag, so the .inc files are also checked
  786. Revision 1.22 1999/02/05 08:54:29 pierre
  787. + linkofiles splitted inot linkofiles and linkunitfiles
  788. because linkofiles must be stored with directory
  789. to enabled linking of different objects with same name
  790. in a different directory
  791. Revision 1.21 1998/12/30 22:15:50 peter
  792. + farpointer type
  793. * absolutesym now also stores if its far
  794. Revision 1.20 1998/11/30 16:34:45 pierre
  795. * corrected problems with rangecheck
  796. + added needed code for no rangecheck in CRC32 functions in ppu unit
  797. * enumdef lso need its rangenr reset to zero
  798. when calling reset_global_defs
  799. Revision 1.19 1998/11/16 15:41:42 peter
  800. * tp7 didn't like my ifopt H+ :(
  801. Revision 1.18 1998/11/16 12:18:03 peter
  802. * H+ fixes
  803. Revision 1.17 1998/10/14 10:45:08 pierre
  804. * ppu problems for m68k fixed (at least in cross compiling)
  805. * one last memory leak for sysamiga fixed
  806. * the amiga RTL compiles now completely !!
  807. Revision 1.16 1998/09/24 23:49:14 peter
  808. + aktmodeswitches
  809. Revision 1.15 1998/09/23 15:39:10 pierre
  810. * browser bugfixes
  811. was adding a reference when looking for the symbol
  812. if -bSYM_NAME was used
  813. Revision 1.14 1998/09/21 10:00:07 peter
  814. * store number of defs in ppu file
  815. Revision 1.13 1998/09/21 08:45:18 pierre
  816. + added vmt_offset in tobjectdef.write for fututre use
  817. (first steps to have objects without vmt if no virtual !!)
  818. + added fpu_used field for tabstractprocdef :
  819. sets this level to 2 if the functions return with value in FPU
  820. (is then set to correct value at parsing of implementation)
  821. THIS MIGHT refuse some code with FPU expression too complex
  822. that were accepted before and even in some cases
  823. that don't overflow in fact
  824. ( like if f : float; is a forward that finally in implementation
  825. only uses one fpu register !!)
  826. Nevertheless I think that it will improve security on
  827. FPU operations !!
  828. * most other changes only for UseBrowser code
  829. (added symtable references for record and objects)
  830. local switch for refs to args and local of each function
  831. (static symtable still missing)
  832. UseBrowser still not stable and probably broken by
  833. the definition hash array !!
  834. Revision 1.12 1998/09/18 08:01:37 pierre
  835. + improvement on the usebrowser part
  836. (does not work correctly for now)
  837. Revision 1.11 1998/09/11 15:16:47 peter
  838. * merge fixes
  839. Revision 1.10.2.1 1998/09/11 15:15:04 peter
  840. * fixed not in [] bug
  841. Revision 1.10 1998/08/31 12:26:30 peter
  842. * m68k and palmos updates from surebugfixes
  843. Revision 1.9 1998/08/17 09:17:51 peter
  844. * static/shared linking updates
  845. Revision 1.8 1998/08/11 15:31:40 peter
  846. * write extended to ppu file
  847. * new version 0.99.7
  848. Revision 1.7 1998/06/25 10:51:01 pierre
  849. * removed a remaining ifndef NEWPPU
  850. replaced by ifdef OLDPPU
  851. * added uf_finalize to ppu unit
  852. Revision 1.6 1998/06/16 08:56:26 peter
  853. + targetcpu
  854. * cleaner pmodules for newppu
  855. Revision 1.5 1998/06/13 00:10:12 peter
  856. * working browser and newppu
  857. * some small fixes against crashes which occured in bp7 (but not in
  858. fpc?!)
  859. Revision 1.4 1998/06/09 16:01:48 pierre
  860. + added procedure directive parsing for procvars
  861. (accepted are popstack cdecl and pascal)
  862. + added C vars with the following syntax
  863. var C calias 'true_c_name';(can be followed by external)
  864. reason is that you must add the Cprefix
  865. which is target dependent
  866. Revision 1.3 1998/05/28 14:40:26 peter
  867. * fixes for newppu, remake3 works now with it
  868. Revision 1.2 1998/05/27 19:45:08 peter
  869. * symtable.pas splitted into includefiles
  870. * symtable adapted for $ifdef NEWPPU
  871. Revision 1.1 1998/05/12 10:56:07 peter
  872. + the ppufile object unit
  873. }