entfile.pas 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  1. {
  2. Copyright (c) 1998-2013 by Free Pascal development team
  3. Routines to read/write entry based files (ppu, pcp)
  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. unit entfile;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. systems,globtype,constexp,cstreams;
  22. const
  23. { buffer sizes }
  24. maxentrysize = 1024;
  25. // Unused, and wrong as there are entries that are larger then 1024 bytes
  26. {$ifdef CHECK_INPUTPOINTER_LIMITS}
  27. default_entryfilebufsize = 16384;
  28. {$else not CHECK_INPUTPOINTER_LIMITS}
  29. entryfilebufsize = 16384;
  30. {$endif CHECK_INPUTPOINTER_LIMITS}
  31. {ppu entries}
  32. mainentryid = 1;
  33. subentryid = 2;
  34. {special}
  35. iberror = 0;
  36. ibextraheader = 242;
  37. ibpputable = 243;
  38. ibstartrequireds = 244;
  39. ibendrequireds = 245;
  40. ibstartcontained = 246;
  41. ibendcontained = 247;
  42. ibstartdefs = 248;
  43. ibenddefs = 249;
  44. ibstartsyms = 250;
  45. ibendsyms = 251;
  46. ibendinterface = 252;
  47. ibendimplementation = 253;
  48. // ibendbrowser = 254;
  49. ibend = 255;
  50. {general}
  51. ibmodulename = 1;
  52. ibsourcefiles = 2;
  53. ibloadunit = 3;
  54. ibinitunit = 4;
  55. iblinkunitofiles = 5;
  56. iblinkunitstaticlibs = 6;
  57. iblinkunitsharedlibs = 7;
  58. iblinkotherofiles = 8;
  59. iblinkotherstaticlibs = 9;
  60. iblinkothersharedlibs = 10;
  61. ibImportSymbols = 11;
  62. ibsymref = 12;
  63. ibdefref = 13;
  64. ibfeatures = 14;
  65. {$IFDEF MACRO_DIFF_HINT}
  66. ibusedmacros = 16;
  67. {$ENDIF}
  68. ibderefdata = 17;
  69. ibexportedmacros = 18;
  70. ibderefmap = 19;
  71. {syms}
  72. ibtypesym = 20;
  73. ibprocsym = 21;
  74. ibstaticvarsym = 22;
  75. ibconstsym = 23;
  76. ibenumsym = 24;
  77. // ibtypedconstsym = 25;
  78. ibabsolutevarsym = 26;
  79. ibpropertysym = 27;
  80. ibfieldvarsym = 28;
  81. ibunitsym = 29;
  82. iblabelsym = 30;
  83. ibsyssym = 31;
  84. ibnamespacesym = 32;
  85. iblocalvarsym = 33;
  86. ibparavarsym = 34;
  87. ibmacrosym = 35;
  88. {definitions}
  89. iborddef = 40;
  90. ibpointerdef = 41;
  91. ibarraydef = 42;
  92. ibprocdef = 43;
  93. ibshortstringdef = 44;
  94. ibrecorddef = 45;
  95. ibfiledef = 46;
  96. ibformaldef = 47;
  97. ibobjectdef = 48;
  98. ibenumdef = 49;
  99. ibsetdef = 50;
  100. ibprocvardef = 51;
  101. ibfloatdef = 52;
  102. ibclassrefdef = 53;
  103. iblongstringdef = 54;
  104. ibansistringdef = 55;
  105. ibwidestringdef = 56;
  106. ibvariantdef = 57;
  107. ibundefineddef = 58;
  108. ibunicodestringdef = 59;
  109. {implementation/ObjData}
  110. ibnodetree = 80;
  111. ibasmsymbols = 81;
  112. ibresources = 82;
  113. ibcreatedobjtypes = 83;
  114. ibwpofile = 84;
  115. ibmoduleoptions = 85;
  116. ibunitimportsyms = 86;
  117. iborderedsymbols = 87;
  118. ibmainname = 90;
  119. ibsymtableoptions = 91;
  120. ibpackagefiles = 92;
  121. ibpackagename = 93;
  122. ibrecsymtableoptions = 94;
  123. { target-specific things }
  124. iblinkotherframeworks = 100;
  125. ibjvmnamespace = 101;
  126. {$ifdef generic_cpu}
  127. { We need to use the correct size of aint and pint for
  128. the target CPU }
  129. const
  130. CpuAddrBitSize : array[tsystemcpu] of longint =
  131. (
  132. { 0 } 32 {'none'},
  133. { 1 } 32 {'i386'},
  134. { 2 } 32 {'m68k'},
  135. { 3 } 32 {'alpha'},
  136. { 4 } 32 {'powerpc'},
  137. { 5 } 32 {'sparc'},
  138. { 6 } 32 {'vis'},
  139. { 7 } 64 {'ia64'},
  140. { 8 } 64 {'x86_64'},
  141. { 9 } 32 {'mipseb'},
  142. { 10 } 32 {'arm'},
  143. { 11 } 64 {'powerpc64'},
  144. { 12 } 16 {'avr'},
  145. { 13 } 32 {'mipsel'},
  146. { 14 } 32 {'jvm'},
  147. { 15 } 16 {'i8086'},
  148. { 16 } 64 {'aarch64'},
  149. { 17 } 32 {'wasm32'},
  150. { 18 } 64 {'sparc64'},
  151. { 19 } 32 {'riscv32'},
  152. { 20 } 64 {'riscv64'},
  153. { 21 } 32 {'xtensa'},
  154. { 22 } 16 {'z80'},
  155. { 23 } 64 {'mips64'},
  156. { 24 } 64 {'mips64el'},
  157. { 25 } 64 {'loongarch64'},
  158. { 26 } 16 {'mos6502'}
  159. );
  160. CpuAluBitSize : array[tsystemcpu] of longint =
  161. (
  162. { 0 } 32 {'none'},
  163. { 1 } 32 {'i386'},
  164. { 2 } 32 {'m68k'},
  165. { 3 } 32 {'alpha'},
  166. { 4 } 32 {'powerpc'},
  167. { 5 } 32 {'sparc'},
  168. { 6 } 32 {'vis'},
  169. { 7 } 64 {'ia64'},
  170. { 8 } 64 {'x86_64'},
  171. { 9 } 32 {'mipseb'},
  172. { 10 } 32 {'arm'},
  173. { 11 } 64 {'powerpc64'},
  174. { 12 } 8 {'avr'},
  175. { 13 } 32 {'mipsel'},
  176. { 14 } 64 {'jvm'},
  177. { 15 } 16 {'i8086'},
  178. { 16 } 64 {'aarch64'},
  179. { 17 } 64 {'wasm32'},
  180. { 18 } 64 {'sparc64'},
  181. { 19 } 32 {'riscv32'},
  182. { 20 } 64 {'riscv64'},
  183. { 21 } 32 {'xtensa'},
  184. { 22 } 8 {'z80'},
  185. { 23 } 64 {'mips64'},
  186. { 24 } 64 {'mips64el'},
  187. { 25 } 64 {'loongarch64'},
  188. { 26 } 8 {'mos6502'}
  189. );
  190. {$endif generic_cpu}
  191. type
  192. { bestreal is defined based on the target architecture }
  193. entryreal=bestreal;
  194. { common part of the header for all kinds of entry files }
  195. tentryheader=record
  196. id : array[1..3] of char;
  197. ver : array[1..3] of char;
  198. compiler : word;
  199. cpu : word;
  200. target : word;
  201. flags : dword;
  202. size : dword; { size of the ppufile without header }
  203. end;
  204. pentryheader=^tentryheader;
  205. tentry=packed record
  206. size : longint;
  207. id : byte;
  208. nr : byte;
  209. end;
  210. tentryfile=class
  211. private
  212. function getposition:longint;
  213. procedure setposition(value:longint);
  214. protected
  215. buf : pchar;
  216. bufstart,
  217. bufsize,
  218. bufidx : integer;
  219. entrybufstart,
  220. entrystart,
  221. entryidx : integer;
  222. entry : tentry;
  223. closed,
  224. tempclosed : boolean;
  225. closepos : integer;
  226. protected
  227. f : TCStream;
  228. {$ifdef DEBUG_PPU}
  229. flog : text;
  230. flog_open : boolean;
  231. ppu_log_level : longint;
  232. ppu_log_idx : integer;
  233. {$endif}
  234. {$ifdef CHECK_INPUTPOINTER_LIMITS}
  235. entryfilebufsize :longint;
  236. {$endif CHECK_INPUTPOINTER_LIMITS}
  237. mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
  238. fisfile : boolean;
  239. fname : string;
  240. fsize : integer;
  241. procedure newheader;virtual;abstract;
  242. function readheader:longint;virtual;abstract;
  243. function outputallowed:boolean;virtual;
  244. procedure resetfile;virtual;abstract;
  245. function getheadersize:longint;virtual;abstract;
  246. function getheaderaddr:pentryheader;virtual;abstract;
  247. procedure RaiseAssertion(Code: Longint); virtual;
  248. public
  249. entrytyp : byte;
  250. size : integer;
  251. change_endian : boolean; { Used in ppudump util }
  252. {$ifdef generic_cpu}
  253. has_more,
  254. {$endif not generic_cpu}
  255. error : boolean;
  256. constructor create(const fn:string
  257. {$ifdef CHECK_INPUTPOINTER_LIMITS}
  258. ;aentryfilebufsize : longint = default_entryfilebufsize
  259. {$endif CHECK_INPUTPOINTER_LIMITS}
  260. );
  261. destructor destroy;override;
  262. function getversion:integer;
  263. procedure flush; {$ifdef USEINLINE}inline;{$endif}
  264. procedure closefile;virtual;
  265. procedure newentry;
  266. property position:longint read getposition write setposition;
  267. { Warning: don't keep the stream open during a tempclose! }
  268. function substream(ofs,len:longint):TCStream;
  269. { Warning: don't use the put* or write* functions anymore when writing through this }
  270. property stream:TCStream read f;
  271. {$ifdef DEBUG_PPU}
  272. procedure ppu_log(st :string);virtual;
  273. procedure ppu_log_val(st :string);virtual;
  274. procedure inc_log_level;
  275. procedure dec_log_level;
  276. {$endif}
  277. {read}
  278. function openfile:boolean;
  279. function openstream(strm:TCStream):boolean;
  280. procedure reloadbuf;
  281. procedure readdata(out b;len:integer);
  282. procedure readdata(const b : TByteDynArray);
  283. procedure readdata(const b : TAnsiCharDynArray);
  284. procedure skipdata(len:integer);
  285. function readentry:byte;
  286. function EndOfEntry:boolean; {$ifdef USEINLINE}inline;{$endif}
  287. function entrysize:longint; {$ifdef USEINLINE}inline;{$endif}
  288. function entryleft:longint; {$ifdef USEINLINE}inline;{$endif}
  289. procedure getdatabuf(out b;len:integer;out res:integer);
  290. procedure getdata(out b;len:integer);
  291. procedure getdata(b : TByteDynArray);
  292. procedure getdata(b : TAnsiCharDynArray);
  293. function getbyte:byte;
  294. function getword:word;
  295. function getdword:dword;
  296. function getlongint:longint;
  297. function getint64:int64;
  298. function getqword:qword;
  299. function getaint:{$ifdef generic_cpu}int64{$else}aint{$ifdef USEINLINE}; inline{$endif}{$endif};
  300. function getasizeint:{$ifdef generic_cpu}int64{$else}asizeint{$ifdef USEINLINE}; inline{$endif}{$endif};
  301. function getpuint:{$ifdef generic_cpu}qword{$else}puint{$ifdef USEINLINE}; inline{$endif}{$endif};
  302. function getptruint:{$ifdef generic_cpu}qword{$else}TConstPtrUInt{$ifdef USEINLINE}; inline{$endif}{$endif};
  303. function getaword:{$ifdef generic_cpu}qword{$else}aword{$ifdef USEINLINE}; inline{$endif}{$endif};
  304. function getreal:entryreal;
  305. function getrealsize(sizeofreal : longint):entryreal;
  306. function getboolean:boolean; {$ifdef USEINLINE}inline;{$endif}
  307. function getstring:string;
  308. function getpshortstring:pshortstring;
  309. function getansistring:ansistring;
  310. procedure getset(out arr: array of byte);
  311. function skipuntilentry(untilb:byte):boolean;
  312. {write}
  313. function createfile:boolean;virtual;
  314. function createstream(strm:TCStream):boolean;
  315. procedure writeheader;virtual;abstract;
  316. procedure writebuf;
  317. procedure writedata(const b;len:integer);
  318. procedure writeentry(ibnr:byte);
  319. procedure putdata(const b;len:integer);virtual;
  320. procedure putbyte(b:byte); {$ifdef USEINLINE}inline;{$endif}
  321. procedure putword(w:word); {$ifdef USEINLINE}inline;{$endif}
  322. procedure putdword(w:dword); {$ifdef USEINLINE}inline;{$endif}
  323. procedure putlongint(l:longint); {$ifdef USEINLINE}inline;{$endif}
  324. procedure putint64(i:int64); {$ifdef USEINLINE}inline;{$endif}
  325. procedure putqword(q:qword); {$ifdef USEINLINE}inline;{$endif}
  326. procedure putaint(i:aint); {$ifdef USEINLINE}inline;{$endif}
  327. procedure putasizeint(i:asizeint); {$ifdef USEINLINE}inline;{$endif}
  328. procedure putpuint(i:puint); {$ifdef USEINLINE}inline;{$endif}
  329. procedure putptruint(v:TConstPtrUInt); {$ifdef USEINLINE}inline;{$endif}
  330. procedure putaword(i:aword); {$ifdef USEINLINE}inline;{$endif}
  331. procedure putreal(d:entryreal);
  332. procedure putboolean(b:boolean); {$ifdef USEINLINE}inline;{$endif}
  333. procedure putstring(const s:string); {$ifdef USEINLINE}inline;{$endif}
  334. procedure putansistring(const s:ansistring);
  335. procedure putset(const arr: array of byte);
  336. procedure tempclose; // MG: not used, obsolete?
  337. function tempopen:boolean; // MG: not used, obsolete?
  338. end;
  339. implementation
  340. uses
  341. {$ifndef FPC_HAS_TYPE_EXTENDED}
  342. {$ifdef FPC_SOFT_FPUX80}
  343. sfpux80,math,
  344. {$endif FPC_SOFT_FPUX80}
  345. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  346. cutils;
  347. function swapendian_entryreal(d:entryreal):entryreal;
  348. type
  349. entryreal_bytes=array[0..sizeof(d)-1] of byte;
  350. var
  351. i:0..sizeof(d)-1;
  352. begin
  353. for i:=low(entryreal_bytes) to high(entryreal_bytes) do
  354. entryreal_bytes(result)[i]:=entryreal_bytes(d)[high(entryreal_bytes)-i];
  355. end;
  356. {*****************************************************************************
  357. tentryfile
  358. *****************************************************************************}
  359. function tentryfile.outputallowed: boolean;
  360. begin
  361. result:=true;
  362. end;
  363. constructor tentryfile.create(const fn:string
  364. {$ifdef CHECK_INPUTPOINTER_LIMITS}
  365. ;aentryfilebufsize : longint = default_entryfilebufsize
  366. {$endif CHECK_INPUTPOINTER_LIMITS}
  367. );
  368. begin
  369. fname:=fn;
  370. fisfile:=false;
  371. change_endian:=false;
  372. mode:=0;
  373. newheader;
  374. error:=false;
  375. closed:=true;
  376. tempclosed:=false;
  377. {$ifdef CHECK_INPUTPOINTER_LIMITS}
  378. entryfilebufsize:=aentryfilebufsize;
  379. {$endif CHECK_INPUTPOINTER_LIMITS}
  380. getmem(buf,entryfilebufsize);
  381. {$ifdef DEBUG_PPU}
  382. assign(flog,fn+'.debug-log');
  383. flog_open:=false;
  384. {$endif DEBUG_PPU}
  385. end;
  386. destructor tentryfile.destroy;
  387. begin
  388. closefile;
  389. {$ifdef DEBUG_PPU}
  390. if flog_open then
  391. close(flog);
  392. flog_open:=false;
  393. {$endif DEBUG_PPU}
  394. if assigned(buf) then
  395. freemem(buf,entryfilebufsize);
  396. end;
  397. {$ifdef DEBUG_PPU}
  398. function entryid_name(nr : byte) : string;
  399. begin
  400. case nr of
  401. {ppu entries}
  402. mainentryid: entryid_name:='main_entry_id';
  403. subentryid: entryid_name:='sub_entry_id';
  404. else
  405. entryid_name:='unknown entryid '+tostr(nr);
  406. end;
  407. end;
  408. function entry_name(nr : byte) : string;
  409. begin
  410. case nr of
  411. {special}
  412. iberror: entry_name:='iberror';
  413. ibextraheader: entry_name:='ibextraheader';
  414. ibpputable: entry_name:='ibpputable';
  415. ibstartrequireds: entry_name:='ibstartrequireds';
  416. ibendrequireds: entry_name:='ibendrequireds';
  417. ibstartcontained: entry_name:='ibstartcontained';
  418. ibendcontained: entry_name:='ibendcontained';
  419. ibstartdefs: entry_name:='ibstartdefs';
  420. ibenddefs: entry_name:='ibenddefs';
  421. ibstartsyms: entry_name:='ibstartsyms';
  422. ibendsyms: entry_name:='ibendsyms';
  423. ibendinterface: entry_name:='ibendinterface';
  424. ibendimplementation: entry_name:='ibendimplementation';
  425. // ibendbrowser: entry_name:='ibendbrowser';
  426. ibend: entry_name:='ibend';
  427. {general}
  428. ibmodulename: entry_name:='ibmodulename';
  429. ibsourcefiles: entry_name:='ibsourcefiles';
  430. ibloadunit: entry_name:='ibloadunit';
  431. ibinitunit: entry_name:='ibinitunit';
  432. iblinkunitofiles: entry_name:='iblinkunitofiles';
  433. iblinkunitstaticlibs: entry_name:='iblinkunitstaticlibs';
  434. iblinkunitsharedlibs: entry_name:='iblinkunitsharedlibs';
  435. iblinkotherofiles: entry_name:='iblinkotherofiles';
  436. iblinkotherstaticlibs: entry_name:='iblinkotherstaticlibs';
  437. iblinkothersharedlibs: entry_name:='iblinkothersharedlibs';
  438. ibImportSymbols: entry_name:='ibImportSymbols';
  439. ibsymref: entry_name:='ibsymref';
  440. ibdefref: entry_name:='ibdefref';
  441. ibfeatures: entry_name:='ibfeatures';
  442. {$IFDEF MACRO_DIFF_HINT}
  443. ibusedmacros: entry_name:='ibusedmacros';
  444. {$ENDIF}
  445. ibderefdata: entry_name:='ibderefdata';
  446. ibexportedmacros: entry_name:='ibexportedmacros';
  447. ibderefmap: entry_name:='ibderefmap';
  448. {syms}
  449. ibtypesym: entry_name:='ibtypesym';
  450. ibprocsym: entry_name:='ibprocsym';
  451. ibstaticvarsym: entry_name:='ibstaticvarsym';
  452. ibconstsym: entry_name:='ibconstsym';
  453. ibenumsym: entry_name:='ibenumsym';
  454. // ibtypedconstsym: entry_name:='ibtypedconstsym';
  455. ibabsolutevarsym: entry_name:='ibabsolutevarsym';
  456. ibpropertysym: entry_name:='ibpropertysym';
  457. ibfieldvarsym: entry_name:='ibfieldvarsym';
  458. ibunitsym: entry_name:='ibunitsym';
  459. iblabelsym: entry_name:='iblabelsym';
  460. ibsyssym: entry_name:='ibsyssym';
  461. ibnamespacesym: entry_name:='ibnamespacesym';
  462. iblocalvarsym: entry_name:='iblocalvarsym';
  463. ibparavarsym: entry_name:='ibparavarsym';
  464. ibmacrosym: entry_name:='ibmacrosym';
  465. {definitions}
  466. iborddef: entry_name:='iborddef';
  467. ibpointerdef: entry_name:='ibpointerdef';
  468. ibarraydef: entry_name:='ibarraydef';
  469. ibprocdef: entry_name:='ibprocdef';
  470. ibshortstringdef: entry_name:='ibshortstringdef';
  471. ibrecorddef: entry_name:='ibrecorddef';
  472. ibfiledef: entry_name:='ibfiledef';
  473. ibformaldef: entry_name:='ibformaldef';
  474. ibobjectdef: entry_name:='ibobjectdef';
  475. ibenumdef: entry_name:='ibenumdef';
  476. ibsetdef: entry_name:='ibsetdef';
  477. ibprocvardef: entry_name:='ibprocvardef';
  478. ibfloatdef: entry_name:='ibfloatdef';
  479. ibclassrefdef: entry_name:='ibclassrefdef';
  480. iblongstringdef: entry_name:='iblongstringdef';
  481. ibansistringdef: entry_name:='ibansistringdef';
  482. ibwidestringdef: entry_name:='ibwidestringdef';
  483. ibvariantdef: entry_name:='ibvariantdef';
  484. ibundefineddef: entry_name:='ibundefineddef';
  485. ibunicodestringdef: entry_name:='ibunicodestringdef';
  486. {implementation/ObjData}
  487. ibnodetree: entry_name:='ibnodetree';
  488. ibasmsymbols: entry_name:='ibasmsymbols';
  489. ibresources: entry_name:='ibresources';
  490. ibcreatedobjtypes: entry_name:='ibcreatedobjtypes';
  491. ibwpofile: entry_name:='ibwpofile';
  492. ibmoduleoptions: entry_name:='ibmoduleoptions';
  493. ibunitimportsyms: entry_name:='ibunitimportsyms';
  494. iborderedsymbols: entry_name:='iborderedsymbols';
  495. ibmainname: entry_name:='ibmainname';
  496. ibsymtableoptions: entry_name:='ibsymtableoptions';
  497. // ibrecsymtableoptions: entry_name:='ibrecsymtableoptions';
  498. ibpackagefiles: entry_name:='ibpackagefiles';
  499. ibpackagename: entry_name:='ibpackagename';
  500. { target-specific things }
  501. iblinkotherframeworks: entry_name:='iblinkotherframeworks';
  502. ibjvmnamespace: entry_name:='ibjvmnamespace';
  503. else
  504. entry_name:='unknown entry '+tostr(nr);
  505. end;
  506. end;
  507. procedure tentryfile.ppu_log(st :string);
  508. begin
  509. if flog_open then
  510. begin
  511. writeln(flog,bufstart+bufidx,': ',st);
  512. end;
  513. {$ifdef IN_PPUDUMP}
  514. writeln(bufstart+bufidx,': ',st);
  515. {$endif}
  516. end;
  517. procedure tentryfile.inc_log_level;
  518. begin
  519. inc(ppu_log_level);
  520. end;
  521. procedure tentryfile.ppu_log_val(st :string);
  522. begin
  523. if flog_open then
  524. begin
  525. writeln(flog,'(',ppu_log_level,') value: ',st);
  526. end;
  527. {$ifdef IN_PPUDUMP}
  528. writeln('(',ppu_log_level,') value: ',st);
  529. {$endif}
  530. end;
  531. procedure tentryfile.dec_log_level;
  532. begin
  533. dec(ppu_log_level);
  534. end;
  535. {$endif}
  536. function tentryfile.getversion:integer;
  537. var
  538. l : integer;
  539. code : integer;
  540. header : pentryheader;
  541. begin
  542. header:=getheaderaddr;
  543. Val(header^.ver[1]+header^.ver[2]+header^.ver[3],l,code);
  544. if code=0 then
  545. result:=l
  546. else
  547. result:=0;
  548. end;
  549. procedure tentryfile.flush;
  550. begin
  551. if mode=2 then
  552. writebuf;
  553. end;
  554. procedure tentryfile.RaiseAssertion(Code: Longint);
  555. begin
  556. { It's down to descendent classes to raise an internal error as desired. [Kit] }
  557. error := true;
  558. end;
  559. procedure tentryfile.closefile;
  560. begin
  561. if mode<>0 then
  562. begin
  563. flush;
  564. {$ifdef DEBUG_PPU}
  565. if (entry.nr<>0) and (mode=1) then
  566. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  567. {$endif}
  568. if fisfile then
  569. f.Free;
  570. mode:=0;
  571. closed:=true;
  572. end;
  573. end;
  574. procedure tentryfile.setposition(value:longint);
  575. begin
  576. if assigned(f) then
  577. f.Position:=value
  578. else
  579. if tempclosed then
  580. closepos:=value;
  581. end;
  582. function tentryfile.getposition:longint;
  583. begin
  584. if assigned(f) then
  585. result:=f.Position
  586. else
  587. if tempclosed then
  588. result:=closepos
  589. else
  590. result:=0;
  591. end;
  592. function tentryfile.substream(ofs,len:longint):TCStream;
  593. begin
  594. result:=nil;
  595. if assigned(f) then
  596. result:=TCRangeStream.Create(f,ofs,len);
  597. end;
  598. {*****************************************************************************
  599. tentryfile Reading
  600. *****************************************************************************}
  601. function tentryfile.openfile:boolean;
  602. var
  603. strm : TCStream;
  604. begin
  605. openfile:=false;
  606. try
  607. strm:=CFileStreamClass.Create(fname,fmOpenRead)
  608. except
  609. exit;
  610. end;
  611. openfile:=openstream(strm);
  612. fisfile:=result;
  613. end;
  614. function tentryfile.openstream(strm:TCStream):boolean;
  615. var
  616. i : longint;
  617. begin
  618. openstream:=false;
  619. f:=strm;
  620. closed:=false;
  621. {$ifdef DEBUG_PPU}
  622. {$push}
  623. {$I-}
  624. assign(flog,fname+'.debug-read-log');
  625. rewrite(flog);
  626. if InOutRes=0 then
  627. flog_open:=true;
  628. {$pop}
  629. {$endif DEBUG_PPU}
  630. {read ppuheader}
  631. fsize:=f.Size;
  632. i:=readheader;
  633. if i<0 then
  634. exit;
  635. {reset buffer}
  636. bufstart:=i;
  637. bufsize:=0;
  638. bufidx:=0;
  639. mode:=1;
  640. FillChar(entry,sizeof(tentry),0);
  641. entryidx:=0;
  642. entrystart:=0;
  643. entrybufstart:=0;
  644. error:=false;
  645. openstream:=true;
  646. end;
  647. procedure tentryfile.reloadbuf;
  648. begin
  649. inc(bufstart,bufsize);
  650. bufsize:=f.Read(buf^,entryfilebufsize);
  651. bufidx:=0;
  652. end;
  653. procedure tentryfile.readdata(out b;len:integer);
  654. var
  655. p,pbuf : pchar;
  656. left : integer;
  657. {$ifdef DEBUG_PPU}
  658. i : integer;
  659. {$endif DEBUG_PPU}
  660. begin
  661. p:=pchar(@b);
  662. pbuf:=@buf[bufidx];
  663. repeat
  664. left:=bufsize-bufidx;
  665. if len<left then
  666. break;
  667. move(pbuf^,p^,left);
  668. dec(len,left);
  669. inc(p,left);
  670. reloadbuf;
  671. pbuf:=@buf[bufidx];
  672. if bufsize=0 then
  673. exit;
  674. until false;
  675. move(pbuf^,p^,len);
  676. {$ifdef DEBUG_PPU}
  677. if ppu_log_level <= 0 then
  678. begin
  679. ppu_log('writedata, length='+tostr(len)+' level='+tostr(ppu_log_level));
  680. for i:=0 to len-1 do
  681. ppu_log_val('p['+tostr(i)+']=$'+hexstr(byte(p[i]),2));
  682. end;
  683. {$endif DEBUG_PPU}
  684. inc(bufidx,len);
  685. end;
  686. procedure tentryfile.readdata(const b: TByteDynArray);
  687. begin
  688. ReadData(B[0],Length(B));
  689. end;
  690. procedure tentryfile.readdata(const b: TAnsiCharDynArray);
  691. begin
  692. ReadData(B[0],Length(B));
  693. end;
  694. procedure tentryfile.skipdata(len:integer);
  695. var
  696. left : integer;
  697. begin
  698. {$ifdef DEBUG_PPU}
  699. if len>0 then
  700. ppu_log('explicit skipdata '+tostr(len));
  701. {$endif}
  702. while len>0 do
  703. begin
  704. left:=bufsize-bufidx;
  705. if len>left then
  706. begin
  707. dec(len,left);
  708. reloadbuf;
  709. if bufsize=0 then
  710. exit;
  711. end
  712. else
  713. begin
  714. inc(bufidx,len);
  715. exit;
  716. end;
  717. end;
  718. end;
  719. function tentryfile.readentry:byte;
  720. begin
  721. if entryidx<entry.size then
  722. begin
  723. {$ifdef generic_cpu}
  724. has_more:=true;
  725. {$endif not generic_cpu}
  726. {$ifdef DEBUG_PPU}
  727. if entry.size-entryidx>0 then
  728. ppu_log('skipdata '+tostr(entry.size-entryidx));
  729. {$endif}
  730. skipdata(entry.size-entryidx);
  731. end;
  732. {$ifdef DEBUG_PPU}
  733. if entry.nr<>0 then
  734. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  735. ppu_log('entrystart');
  736. {$endif}
  737. readdata(entry,sizeof(tentry));
  738. if change_endian then
  739. entry.size:=swapendian(entry.size);
  740. entrystart:=bufstart+bufidx;
  741. entryidx:=0;
  742. {$ifdef generic_cpu}
  743. has_more:=false;
  744. {$endif not generic_cpu}
  745. if not(entry.id in [mainentryid,subentryid]) then
  746. begin
  747. readentry:=iberror;
  748. error:=true;
  749. exit;
  750. end;
  751. readentry:=entry.nr;
  752. end;
  753. function tentryfile.endofentry: boolean;
  754. begin
  755. {$ifdef generic_cpu}
  756. endofentry:=(entryidx=entry.size);
  757. {$else not generic_cpu}
  758. endofentry:=(entryidx>=entry.size);
  759. {$endif not generic_cpu}
  760. end;
  761. function tentryfile.entrysize:longint;
  762. begin
  763. entrysize:=entry.size;
  764. end;
  765. function tentryfile.entryleft:longint;
  766. begin
  767. entryleft:=entry.size-entryidx;
  768. end;
  769. procedure tentryfile.getdatabuf(out b;len:integer;out res:integer);
  770. begin
  771. if entryidx+len>entry.size then
  772. res:=entry.size-entryidx
  773. else
  774. res:=len;
  775. readdata(b,res);
  776. inc(entryidx,res);
  777. end;
  778. procedure tentryfile.getdata(out b;len:integer);
  779. begin
  780. if entryidx+len>entry.size then
  781. begin
  782. error:=true;
  783. exit;
  784. end;
  785. readdata(b,len);
  786. inc(entryidx,len);
  787. end;
  788. procedure tentryfile.getdata(b: TByteDynArray);
  789. begin
  790. if entryidx+Length(b)>entry.size then
  791. begin
  792. error:=true;
  793. exit;
  794. end;
  795. readdata(b);
  796. inc(entryidx,length(b));
  797. end;
  798. procedure tentryfile.getdata(b: TAnsiCharDynArray);
  799. begin
  800. if entryidx+Length(b)>entry.size then
  801. begin
  802. error:=true;
  803. exit;
  804. end;
  805. readdata(b);
  806. inc(entryidx,length(b));
  807. end;
  808. function tentryfile.getbyte:byte;
  809. begin
  810. if entryidx>=entry.size then
  811. begin
  812. error:=true;
  813. result:=0;
  814. exit;
  815. end;
  816. {$ifdef DEBUG_PPU}
  817. ppu_log('putbyte');
  818. inc_log_level;
  819. {$endif}
  820. if bufidx<bufsize then
  821. begin
  822. result:=pbyte(@buf[bufidx])^;
  823. inc(bufidx);
  824. end
  825. else
  826. readdata(result,1);
  827. {$ifdef DEBUG_PPU}
  828. ppu_log_val(tostr(result));
  829. dec_log_level;
  830. {$endif}
  831. inc(entryidx);
  832. end;
  833. function tentryfile.getword:word;
  834. begin
  835. if entryidx+2>entry.size then
  836. begin
  837. error:=true;
  838. result:=0;
  839. exit;
  840. end;
  841. {$ifdef DEBUG_PPU}
  842. ppu_log('putword');
  843. inc_log_level;
  844. {$endif}
  845. if bufsize-bufidx>=sizeof(word) then
  846. begin
  847. result:=Unaligned(pword(@buf[bufidx])^);
  848. inc(bufidx,sizeof(word));
  849. end
  850. else
  851. readdata(result,sizeof(word));
  852. if change_endian then
  853. result:=swapendian(result);
  854. {$ifdef DEBUG_PPU}
  855. ppu_log_val(tostr(result));
  856. dec_log_level;
  857. {$endif}
  858. inc(entryidx,2);
  859. end;
  860. function tentryfile.getlongint:longint;
  861. begin
  862. if entryidx+4>entry.size then
  863. begin
  864. error:=true;
  865. result:=0;
  866. exit;
  867. end;
  868. {$ifdef DEBUG_PPU}
  869. ppu_log('putlongint');
  870. inc_log_level;
  871. {$endif}
  872. if bufsize-bufidx>=sizeof(longint) then
  873. begin
  874. result:=Unaligned(plongint(@buf[bufidx])^);
  875. inc(bufidx,sizeof(longint));
  876. end
  877. else
  878. readdata(result,sizeof(longint));
  879. if change_endian then
  880. result:=swapendian(result);
  881. {$ifdef DEBUG_PPU}
  882. ppu_log_val(tostr(result));
  883. dec_log_level;
  884. {$endif}
  885. inc(entryidx,4);
  886. end;
  887. function tentryfile.getdword:dword;
  888. begin
  889. if entryidx+4>entry.size then
  890. begin
  891. error:=true;
  892. result:=0;
  893. exit;
  894. end;
  895. {$ifdef DEBUG_PPU}
  896. ppu_log('putdword');
  897. inc_log_level;
  898. {$endif}
  899. if bufsize-bufidx>=sizeof(dword) then
  900. begin
  901. result:=Unaligned(pdword(@buf[bufidx])^);
  902. inc(bufidx,sizeof(longint));
  903. end
  904. else
  905. readdata(result,sizeof(dword));
  906. if change_endian then
  907. result:=swapendian(result);
  908. {$ifdef DEBUG_PPU}
  909. ppu_log_val(tostr(result));
  910. dec_log_level;
  911. {$endif}
  912. inc(entryidx,4);
  913. end;
  914. function tentryfile.getint64:int64;
  915. begin
  916. if entryidx+8>entry.size then
  917. begin
  918. error:=true;
  919. result:=0;
  920. exit;
  921. end;
  922. {$ifdef DEBUG_PPU}
  923. ppu_log('putint64');
  924. inc_log_level;
  925. {$endif}
  926. if bufsize-bufidx>=sizeof(int64) then
  927. begin
  928. result:=Unaligned(pint64(@buf[bufidx])^);
  929. inc(bufidx,sizeof(int64));
  930. end
  931. else
  932. readdata(result,sizeof(int64));
  933. if change_endian then
  934. result:=swapendian(result);
  935. {$ifdef DEBUG_PPU}
  936. ppu_log_val(tostr(result));
  937. dec_log_level;
  938. {$endif}
  939. inc(entryidx,8);
  940. end;
  941. function tentryfile.getqword:qword;
  942. begin
  943. if entryidx+8>entry.size then
  944. begin
  945. error:=true;
  946. result:=0;
  947. exit;
  948. end;
  949. {$ifdef DEBUG_PPU}
  950. ppu_log('putqword');
  951. inc_log_level;
  952. {$endif}
  953. if bufsize-bufidx>=sizeof(qword) then
  954. begin
  955. result:=Unaligned(pqword(@buf[bufidx])^);
  956. inc(bufidx,sizeof(qword));
  957. end
  958. else
  959. readdata(result,sizeof(qword));
  960. if change_endian then
  961. result:=swapendian(result);
  962. {$ifdef DEBUG_PPU}
  963. ppu_log_val(tostr(result));
  964. dec_log_level;
  965. {$endif}
  966. inc(entryidx,8);
  967. end;
  968. function tentryfile.getaint:{$ifdef generic_cpu}int64{$else}aint{$endif};
  969. {$ifdef generic_cpu}
  970. var
  971. header : pentryheader;
  972. {$endif generic_cpu}
  973. begin
  974. {$ifdef DEBUG_PPU}
  975. ppu_log('putaint');
  976. inc_log_level;
  977. {$endif}
  978. {$ifdef generic_cpu}
  979. header:=getheaderaddr;
  980. if CpuAluBitSize[tsystemcpu(header^.cpu)]=64 then
  981. result:=getint64
  982. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=32 then
  983. result:=getlongint
  984. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=16 then
  985. result:=smallint(getword)
  986. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=8 then
  987. result:=shortint(getbyte)
  988. else
  989. begin
  990. error:=true;
  991. result:=0;
  992. end;
  993. {$else not generic_cpu}
  994. case sizeof(aint) of
  995. 8: result:=getint64;
  996. 4: result:=getlongint;
  997. 2: result:=smallint(getword);
  998. 1: result:=shortint(getbyte);
  999. else
  1000. begin
  1001. RaiseAssertion(2019041801);
  1002. result:=0;
  1003. end;
  1004. end;
  1005. {$endif not generic_cpu}
  1006. {$ifdef DEBUG_PPU}
  1007. ppu_log_val(tostr(result));
  1008. dec_log_level;
  1009. {$endif}
  1010. end;
  1011. function tentryfile.getasizeint:{$ifdef generic_cpu}int64{$else}asizeint{$endif};
  1012. {$ifdef generic_cpu}
  1013. var
  1014. header : pentryheader;
  1015. {$endif generic_cpu}
  1016. begin
  1017. {$ifdef DEBUG_PPU}
  1018. ppu_log('putasizeint');
  1019. inc_log_level;
  1020. {$endif}
  1021. {$ifdef generic_cpu}
  1022. header:=getheaderaddr;
  1023. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  1024. result:=getint64
  1025. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=32 then
  1026. result:=getlongint
  1027. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=16 then
  1028. begin
  1029. { result:=smallint(getword);
  1030. would have been logical, but it contradicts
  1031. definition of asizeint in globtype unit,
  1032. which uses 32-bit lngint type even for 16-bit
  1033. address size, to be able to cope with
  1034. I8086 seg:ofs huge addresses }
  1035. result:=getlongint;
  1036. end
  1037. else
  1038. begin
  1039. error:=true;
  1040. result:=0;
  1041. end;
  1042. {$else not generic_cpu}
  1043. case sizeof(asizeint) of
  1044. 8: result:=asizeint(getint64);
  1045. 4: result:=asizeint(getlongint);
  1046. 2: result:=asizeint(getword);
  1047. 1: result:=asizeint(getbyte);
  1048. else
  1049. begin
  1050. RaiseAssertion(2019041802);
  1051. result:=0;
  1052. end;
  1053. end;
  1054. {$endif not generic_cpu}
  1055. {$ifdef DEBUG_PPU}
  1056. ppu_log_val(tostr(result));
  1057. dec_log_level;
  1058. {$endif}
  1059. end;
  1060. function tentryfile.getpuint:{$ifdef generic_cpu}qword{$else}puint{$endif};
  1061. {$ifdef generic_cpu}
  1062. var
  1063. header : pentryheader;
  1064. {$endif generic_cpu}
  1065. begin
  1066. {$ifdef DEBUG_PPU}
  1067. ppu_log('putpuint');
  1068. inc_log_level;
  1069. {$endif}
  1070. {$ifdef generic_cpu}
  1071. header:=getheaderaddr;
  1072. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  1073. result:=getqword
  1074. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=32 then
  1075. result:=getdword
  1076. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=16 then
  1077. result:=getword
  1078. else
  1079. begin
  1080. error:=true;
  1081. result:=0;
  1082. end;
  1083. {$else not generic_cpu}
  1084. case sizeof(puint) of
  1085. 8: result:=getqword;
  1086. 4: result:=getdword;
  1087. 2: result:=getword;
  1088. 1: result:=getbyte;
  1089. else
  1090. begin
  1091. RaiseAssertion(2019041803);
  1092. result:=0;
  1093. end;
  1094. end;
  1095. {$endif not generic_cpu}
  1096. {$ifdef DEBUG_PPU}
  1097. ppu_log_val(tostr(result));
  1098. dec_log_level;
  1099. {$endif}
  1100. end;
  1101. function tentryfile.getptruint:{$ifdef generic_cpu}qword{$else}TConstPtrUInt{$endif};
  1102. {$ifdef generic_cpu}
  1103. var
  1104. header : pentryheader;
  1105. {$endif generic_cpu}
  1106. begin
  1107. {$ifdef DEBUG_PPU}
  1108. ppu_log('putptruint');
  1109. inc_log_level;
  1110. {$endif}
  1111. {$ifdef generic_cpu}
  1112. header:=getheaderaddr;
  1113. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  1114. result:=getqword
  1115. else result:=getdword;
  1116. {$else not generic_cpu}
  1117. {$if sizeof(TConstPtrUInt)=8}
  1118. result:=tconstptruint(getint64);
  1119. {$else}
  1120. result:=TConstPtrUInt(getlongint);
  1121. {$endif}
  1122. {$endif not generic_cpu}
  1123. {$ifdef DEBUG_PPU}
  1124. ppu_log_val(tostr(result));
  1125. dec_log_level;
  1126. {$endif}
  1127. end;
  1128. function tentryfile.getaword:{$ifdef generic_cpu}qword{$else}aword{$endif};
  1129. {$ifdef generic_cpu}
  1130. var
  1131. header : pentryheader;
  1132. {$endif generic_cpu}
  1133. begin
  1134. {$ifdef DEBUG_PPU}
  1135. ppu_log('putaword');
  1136. inc_log_level;
  1137. {$endif}
  1138. {$ifdef generic_cpu}
  1139. header:=getheaderaddr;
  1140. if CpuAluBitSize[tsystemcpu(header^.cpu)]=64 then
  1141. result:=getqword
  1142. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=32 then
  1143. result:=getdword
  1144. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=16 then
  1145. result:=getword
  1146. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=8 then
  1147. result:=getbyte
  1148. else
  1149. begin
  1150. error:=true;
  1151. result:=0;
  1152. end;
  1153. {$else not generic_cpu}
  1154. case sizeof(aword) of
  1155. 8: result:=getqword;
  1156. 4: result:=getdword;
  1157. 2: result:=getword;
  1158. 1: result:=getbyte;
  1159. else
  1160. begin
  1161. RaiseAssertion(2019041804);
  1162. result:=0;
  1163. end;
  1164. end;
  1165. {$endif not generic_cpu}
  1166. {$ifdef DEBUG_PPU}
  1167. ppu_log_val(tostr(result));
  1168. dec_log_level;
  1169. {$endif}
  1170. end;
  1171. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1172. {$ifdef FPC_SOFT_FPUX80}
  1173. { i8086,i386 and x86_64 normally have 80bit float type for
  1174. entryreal, but this is not supported
  1175. on CPUs without 80bit floats.
  1176. Special code is required to handle this. }
  1177. const
  1178. sizeof_floatx80 = 10;
  1179. type
  1180. floatx80_byte_array=array[0..sizeof_floatx80-1] of byte;
  1181. pentryreal=^entryreal;
  1182. function swapendian_floatx80entryreal(d:floatx80_byte_array):floatx80_byte_array;
  1183. var
  1184. i:0..sizeof(d)-1;
  1185. begin
  1186. for i:=low(floatx80_byte_array) to high(floatx80_byte_array) do
  1187. result[i]:=d[high(floatx80_byte_array)-i];
  1188. end;
  1189. {$endif FPC_SOFT_FPUX80}
  1190. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1191. function tentryfile.getrealsize(sizeofreal : longint):entryreal;
  1192. var
  1193. e : entryreal;
  1194. d : double;
  1195. di : qword;{ integer of same size as double }
  1196. s : single;
  1197. si : dword; { integer of same size as single }
  1198. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1199. {$ifdef FPC_SOFT_FPUX80}
  1200. floatx80_ba : floatx80_byte_array;
  1201. floatx80_e: floatx80;
  1202. local_softfloat_exception_mask : TFPUExceptionMask;
  1203. high : word;
  1204. qlow : qword;
  1205. f64 : float64;
  1206. i:byte;
  1207. {$endif}
  1208. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1209. begin
  1210. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1211. {$ifdef FPC_SOFT_FPUX80}
  1212. if sizeofreal=sizeof(floatx80_byte_array) then
  1213. begin
  1214. {$ifdef DEBUG_PPU}
  1215. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')='));
  1216. inc_log_level;
  1217. {$endif}
  1218. if entryidx+sizeof(floatx80_ba)>entry.size then
  1219. begin
  1220. error:=true;
  1221. result:=0;
  1222. {$ifdef DEBUG_PPU}
  1223. ppu_log_val(realtostr(result));
  1224. dec_log_level;
  1225. {$endif}
  1226. exit;
  1227. end;
  1228. readdata(floatx80_ba,sizeof(floatx80_ba));
  1229. if change_endian then
  1230. floatx80_ba:=swapendian_floatx80entryreal(floatx80_ba);
  1231. {$ifdef FPC_BIG_ENDIAN}
  1232. floatx80_e.high:=pword(@floatx80_ba[0])^;
  1233. floatx80_e.low:=unaligned(pqword(@floatx80_ba[2])^);
  1234. {$else}
  1235. floatx80_e.high:=pword(@floatx80_ba[8])^;
  1236. floatx80_e.low:=pqword(@floatx80_ba[0])^;
  1237. {$endif}
  1238. local_softfloat_exception_mask:=softfloat_exception_mask;
  1239. softfloat_exception_mask:=[float_flag_invalid,float_flag_denormal,float_flag_divbyzero,float_flag_overflow,float_flag_underflow,float_flag_inexact];
  1240. f64:=floatx80_to_float64(floatx80_e);
  1241. result:=pentryreal(@f64)^;
  1242. softfloat_exception_mask:=local_softfloat_exception_mask;
  1243. inc(entryidx,sizeof(floatx80_ba));
  1244. {$ifdef DEBUG_PPU}
  1245. ppu_log_val(realtostr(result));
  1246. dec_log_level;
  1247. {$endif}
  1248. exit;
  1249. end;
  1250. {$endif FPC_SOFT_FPUX80}
  1251. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1252. if sizeofreal=sizeof(e) then
  1253. begin
  1254. {$ifdef DEBUG_PPU}
  1255. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')=');
  1256. inc_log_level;
  1257. {$endif}
  1258. if entryidx+sizeof(e)>entry.size then
  1259. begin
  1260. error:=true;
  1261. result:=0;
  1262. {$ifdef DEBUG_PPU}
  1263. ppu_log_val(realtostr(result));
  1264. dec_log_level;
  1265. {$endif}
  1266. exit;
  1267. end;
  1268. readdata(e,sizeof(e));
  1269. if change_endian then
  1270. result:=swapendian_entryreal(e)
  1271. else
  1272. result:=e;
  1273. inc(entryidx,sizeof(e));
  1274. {$ifdef DEBUG_PPU}
  1275. ppu_log_val(realtostr(result));
  1276. dec_log_level;
  1277. {$endif}
  1278. exit;
  1279. end;
  1280. if sizeofreal=sizeof(d) then
  1281. begin
  1282. {$ifdef DEBUG_PPU}
  1283. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')=');
  1284. inc_log_level;
  1285. {$endif}
  1286. if entryidx+sizeof(d)>entry.size then
  1287. begin
  1288. error:=true;
  1289. result:=0;
  1290. {$ifdef DEBUG_PPU}
  1291. ppu_log_val(realtostr(result));
  1292. dec_log_level;
  1293. {$endif}
  1294. exit;
  1295. end;
  1296. readdata(d,sizeof(d));
  1297. if change_endian then
  1298. begin
  1299. di:=swapendian(pqword(@d)^);
  1300. d:=pdouble(@di)^;
  1301. end;
  1302. result:=d;
  1303. inc(entryidx,sizeof(d));
  1304. result:=d;
  1305. {$ifdef DEBUG_PPU}
  1306. ppu_log_val(realtostr(result));
  1307. dec_log_level;
  1308. {$endif}
  1309. exit;
  1310. end;
  1311. if sizeofreal=sizeof(s) then
  1312. begin
  1313. {$ifdef DEBUG_PPU}
  1314. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')=');
  1315. inc_log_level;
  1316. {$endif}
  1317. if entryidx+sizeof(s)>entry.size then
  1318. begin
  1319. error:=true;
  1320. result:=0;
  1321. {$ifdef DEBUG_PPU}
  1322. ppu_log_val(realtostr(result));
  1323. dec_log_level;
  1324. {$endif}
  1325. exit;
  1326. end;
  1327. readdata(s,sizeof(s));
  1328. if change_endian then
  1329. begin
  1330. si:=swapendian(pdword(@s)^);
  1331. s:=psingle(@si)^;
  1332. end;
  1333. result:=s;
  1334. inc(entryidx,sizeof(s));
  1335. result:=s;
  1336. {$ifdef DEBUG_PPU}
  1337. ppu_log_val(realtostr(result));
  1338. dec_log_level;
  1339. {$endif}
  1340. exit;
  1341. end;
  1342. error:=true;
  1343. result:=0.0;
  1344. end;
  1345. function tentryfile.getreal:entryreal;
  1346. var
  1347. d : entryreal;
  1348. hd : double;
  1349. begin
  1350. if target_info.system=system_x86_64_win64 then
  1351. begin
  1352. hd:=getrealsize(sizeof(hd));
  1353. getreal:=hd;
  1354. end
  1355. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1356. {$ifdef FPC_SOFT_FPUX80}
  1357. else
  1358. if target_info.cpu in [cpu_i8086, cpu_i386, cpu_x86_64] then
  1359. begin
  1360. d:=getrealsize(sizeof(floatx80_byte_array));
  1361. getreal:=d;
  1362. end
  1363. {$endif def FPC_SOFT_FPUX80}
  1364. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1365. else
  1366. begin
  1367. d:=getrealsize(sizeof(d));
  1368. getreal:=d;
  1369. end;
  1370. end;
  1371. function tentryfile.getboolean:boolean;
  1372. begin
  1373. {$ifdef DEBUG_PPU}
  1374. ppu_log('putboolean');
  1375. {$endif}
  1376. result:=boolean(getbyte);
  1377. end;
  1378. function tentryfile.getstring:string;
  1379. begin
  1380. result[0]:=chr(getbyte);
  1381. {$ifdef DEBUG_PPU}
  1382. ppu_log('putstring,size='+tostr(length(result)+1));
  1383. inc_log_level;
  1384. {$endif}
  1385. if entryidx+length(result)>entry.size then
  1386. begin
  1387. error:=true;
  1388. exit;
  1389. end;
  1390. ReadData(result[1],length(result));
  1391. {$ifdef DEBUG_PPU}
  1392. ppu_log_val(result);
  1393. dec_log_level;
  1394. {$endif}
  1395. inc(entryidx,length(result));
  1396. end;
  1397. function tentryfile.getpshortstring:pshortstring;
  1398. var
  1399. len: char;
  1400. begin
  1401. result:=nil;
  1402. len:=chr(getbyte);
  1403. {$ifdef DEBUG_PPU}
  1404. ppu_log('putstring,size='+tostr(ord(len)+1));
  1405. inc_log_level;
  1406. {$endif}
  1407. if entryidx+ord(len)>entry.size then
  1408. begin
  1409. error:=true;
  1410. exit;
  1411. end;
  1412. getmem(result,ord(len)+1);
  1413. result^[0]:=len;
  1414. ReadData(result^[1],ord(len));
  1415. inc(entryidx,ord(len));
  1416. {$ifdef DEBUG_PPU}
  1417. ppu_log_val(result^);
  1418. dec_log_level;
  1419. {$endif}
  1420. end;
  1421. function tentryfile.getansistring:ansistring;
  1422. var
  1423. len: longint;
  1424. begin
  1425. {$ifdef DEBUG_PPU}
  1426. ppu_log('putansistring');
  1427. inc_log_level;
  1428. {$endif}
  1429. len:=getlongint;
  1430. if entryidx+len>entry.size then
  1431. begin
  1432. error:=true;
  1433. result:='';
  1434. exit;
  1435. end;
  1436. setlength(result,len);
  1437. if len>0 then
  1438. getdata(result[1],len);
  1439. {$ifdef DEBUG_PPU}
  1440. ppu_log_val(result);
  1441. dec_log_level;
  1442. {$endif}
  1443. end;
  1444. procedure tentryfile.getset(out arr: array of byte);
  1445. var
  1446. i : longint;
  1447. begin
  1448. {$ifdef DEBUG_PPU}
  1449. ppu_log('putset');
  1450. inc_log_level;
  1451. {$endif}
  1452. getdata(arr,sizeof(arr));
  1453. if change_endian then
  1454. for i:=low(arr) to high(arr) do
  1455. arr[i]:=reverse_byte(arr[i]);
  1456. {$ifdef DEBUG_PPU}
  1457. for i:=low(arr) to high(arr) do
  1458. ppu_log_val('byte['+tostr(i)+']=$'+hexstr(arr[i],2));
  1459. dec_log_level;
  1460. {$endif}
  1461. end;
  1462. function tentryfile.skipuntilentry(untilb:byte):boolean;
  1463. var
  1464. b : byte;
  1465. begin
  1466. {$ifdef DEBUG_PPU}
  1467. ppu_log('skipuntilentry '+tostr(untilb));
  1468. {$endif}
  1469. repeat
  1470. b:=readentry;
  1471. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  1472. skipuntilentry:=(b=untilb);
  1473. end;
  1474. {*****************************************************************************
  1475. tentryfile Writing
  1476. *****************************************************************************}
  1477. function tentryfile.createfile:boolean;
  1478. var
  1479. ok: boolean;
  1480. strm : TCStream;
  1481. begin
  1482. createfile:=false;
  1483. strm:=nil;
  1484. if outputallowed then
  1485. begin
  1486. {$ifdef MACOS}
  1487. {FPas is FreePascal's creator code on MacOS. See systems/mac_crea.txt}
  1488. SetDefaultMacOSCreator('FPas');
  1489. SetDefaultMacOSFiletype('FPPU');
  1490. {$endif}
  1491. ok:=false;
  1492. try
  1493. strm:=CFileStreamClass.Create(fname,fmCreate);
  1494. ok:=true;
  1495. except
  1496. end;
  1497. {$ifdef MACOS}
  1498. SetDefaultMacOSCreator('MPS ');
  1499. SetDefaultMacOSFiletype('TEXT');
  1500. {$endif}
  1501. if not ok then
  1502. exit;
  1503. end;
  1504. createfile:=createstream(strm);
  1505. fisfile:=result;
  1506. end;
  1507. function tentryfile.createstream(strm:TCStream):boolean;
  1508. begin
  1509. createstream:=false;
  1510. if outputallowed then
  1511. begin
  1512. f:=strm;
  1513. mode:=2;
  1514. {write header for sure}
  1515. f.Write(getheaderaddr^,getheadersize);
  1516. end;
  1517. bufsize:=entryfilebufsize;
  1518. bufstart:=getheadersize;
  1519. bufidx:=0;
  1520. {reset}
  1521. resetfile;
  1522. error:=false;
  1523. size:=0;
  1524. entrytyp:=mainentryid;
  1525. {$ifdef DEBUG_PPU}
  1526. {$push}
  1527. {$I-}
  1528. assign(flog,fname+'.debug-write-log');
  1529. rewrite(flog);
  1530. if InOutRes=0 then
  1531. flog_open:=true;
  1532. {$pop}
  1533. {$endif DEBUG_PPU}
  1534. {start}
  1535. newentry;
  1536. createstream:=true;
  1537. end;
  1538. procedure tentryfile.writebuf;
  1539. begin
  1540. if outputallowed and
  1541. (bufidx <> 0) then
  1542. f.Write(buf^,bufidx);
  1543. inc(bufstart,bufidx);
  1544. bufidx:=0;
  1545. end;
  1546. procedure tentryfile.writedata(const b;len:integer);
  1547. var
  1548. p : pchar;
  1549. left,
  1550. idx : integer;
  1551. {$ifdef DEBUG_PPU}
  1552. start_len : integer;
  1553. {$endif}
  1554. begin
  1555. if not outputallowed then
  1556. exit;
  1557. {$ifdef DEBUG_PPU}
  1558. start_len:=len;
  1559. {$endif}
  1560. p:=pchar(@b);
  1561. idx:=0;
  1562. while len>0 do
  1563. begin
  1564. left:=bufsize-bufidx;
  1565. if len>left then
  1566. begin
  1567. move(p[idx],buf[bufidx],left);
  1568. dec(len,left);
  1569. inc(idx,left);
  1570. inc(bufidx,left);
  1571. writebuf;
  1572. end
  1573. else
  1574. begin
  1575. move(p[idx],buf[bufidx],len);
  1576. inc(bufidx,len);
  1577. {$ifdef DEBUG_PPU}
  1578. len:=0;
  1579. {$else}
  1580. exit;
  1581. {$endif}
  1582. end;
  1583. end;
  1584. {$ifdef DEBUG_PPU}
  1585. if (start_len > 0) and (ppu_log_level <= 0) then
  1586. begin
  1587. ppu_log('writedata, length='+tostr(start_len)+' level='+tostr(ppu_log_level));
  1588. for idx:=0 to start_len-1 do
  1589. ppu_log_val('p['+tostr(idx)+']=$'+hexstr(byte(p[idx]),2));
  1590. end;
  1591. {$endif DEBUG_PPU}
  1592. end;
  1593. procedure tentryfile.newentry;
  1594. begin
  1595. with entry do
  1596. begin
  1597. id:=entrytyp;
  1598. nr:=ibend;
  1599. size:=0;
  1600. end;
  1601. {Reset Entry State}
  1602. entryidx:=0;
  1603. entrybufstart:=bufstart;
  1604. entrystart:=bufstart+bufidx;
  1605. {$ifdef DEBUG_PPU}
  1606. ppu_log('entrystart');
  1607. {$endif}
  1608. {Alloc in buffer}
  1609. writedata(entry,sizeof(tentry));
  1610. end;
  1611. procedure tentryfile.writeentry(ibnr:byte);
  1612. var
  1613. opos : integer;
  1614. begin
  1615. {create entry}
  1616. entry.id:=entrytyp;
  1617. entry.nr:=ibnr;
  1618. entry.size:=entryidx;
  1619. {it's already been sent to disk ?}
  1620. if entrybufstart<>bufstart then
  1621. begin
  1622. if outputallowed then
  1623. begin
  1624. {flush to be sure}
  1625. WriteBuf;
  1626. {write entry}
  1627. opos:=f.Position;
  1628. f.Position:=entrystart;
  1629. f.write(entry,sizeof(tentry));
  1630. f.Position:=opos;
  1631. end;
  1632. entrybufstart:=bufstart;
  1633. end
  1634. else
  1635. move(entry,buf[entrystart-bufstart],sizeof(entry));
  1636. {$ifdef DEBUG_PPU}
  1637. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  1638. {$endif}
  1639. {Add New Entry, which is ibend by default}
  1640. entrystart:=bufstart+bufidx; {next entry position}
  1641. newentry;
  1642. end;
  1643. procedure tentryfile.putdata(const b;len:integer);
  1644. begin
  1645. if outputallowed then
  1646. writedata(b,len);
  1647. inc(entryidx,len);
  1648. end;
  1649. procedure tentryfile.putbyte(b:byte);
  1650. begin
  1651. {$ifdef DEBUG_PPU}
  1652. ppu_log('putbyte');
  1653. inc_log_level;
  1654. ppu_log_val(tostr(b));
  1655. {$endif}
  1656. putdata(b,1);
  1657. {$ifdef DEBUG_PPU}
  1658. dec_log_level;
  1659. {$endif}
  1660. end;
  1661. procedure tentryfile.putword(w:word);
  1662. begin
  1663. {$ifdef DEBUG_PPU}
  1664. ppu_log('putword');
  1665. inc_log_level;
  1666. ppu_log_val(tostr(w));
  1667. {$endif}
  1668. putdata(w,2);
  1669. {$ifdef DEBUG_PPU}
  1670. dec_log_level;
  1671. {$endif}
  1672. end;
  1673. procedure tentryfile.putdword(w:dword);
  1674. begin
  1675. {$ifdef DEBUG_PPU}
  1676. ppu_log('putdword');
  1677. inc_log_level;
  1678. ppu_log_val(tostr(w));
  1679. {$endif}
  1680. putdata(w,4);
  1681. {$ifdef DEBUG_PPU}
  1682. dec_log_level;
  1683. {$endif}
  1684. end;
  1685. procedure tentryfile.putlongint(l:longint);
  1686. begin
  1687. {$ifdef DEBUG_PPU}
  1688. ppu_log('putlongint');
  1689. inc_log_level;
  1690. ppu_log_val(tostr(l));
  1691. {$endif}
  1692. putdata(l,4);
  1693. {$ifdef DEBUG_PPU}
  1694. dec_log_level;
  1695. {$endif}
  1696. end;
  1697. procedure tentryfile.putint64(i:int64);
  1698. begin
  1699. {$ifdef DEBUG_PPU}
  1700. ppu_log('putint64');
  1701. inc_log_level;
  1702. ppu_log_val(tostr(i));
  1703. {$endif}
  1704. putdata(i,8);
  1705. {$ifdef DEBUG_PPU}
  1706. dec_log_level;
  1707. {$endif}
  1708. end;
  1709. procedure tentryfile.putqword(q:qword);
  1710. begin
  1711. {$ifdef DEBUG_PPU}
  1712. ppu_log('putqword');
  1713. inc_log_level;
  1714. ppu_log_val(tostr(q));
  1715. {$endif}
  1716. putdata(q,sizeof(qword));
  1717. {$ifdef DEBUG_PPU}
  1718. dec_log_level;
  1719. {$endif}
  1720. end;
  1721. procedure tentryfile.putaint(i:aint);
  1722. begin
  1723. {$ifdef DEBUG_PPU}
  1724. ppu_log('putaint');
  1725. inc_log_level;
  1726. case sizeof(aint) of
  1727. 8: ppu_log('putint64');
  1728. 4: ppu_log('putlongint');
  1729. 2: ppu_log('putword');
  1730. 1: ppu_log('putbyte');
  1731. end;
  1732. ppu_log_val(tostr(i));
  1733. {$endif}
  1734. putdata(i,sizeof(aint));
  1735. {$ifdef DEBUG_PPU}
  1736. dec_log_level;
  1737. {$endif}
  1738. end;
  1739. procedure tentryfile.putasizeint(i: asizeint);
  1740. begin
  1741. {$ifdef DEBUG_PPU}
  1742. ppu_log('putasizeint');
  1743. inc_log_level;
  1744. case sizeof(asizeint) of
  1745. 8: ppu_log('putint64');
  1746. 4: ppu_log('putlongint');
  1747. 2: ppu_log('putword');
  1748. 1: ppu_log('putbyte');
  1749. end;
  1750. ppu_log_val(tostr(i));
  1751. {$endif}
  1752. putdata(i,sizeof(asizeint));
  1753. {$ifdef DEBUG_PPU}
  1754. dec_log_level;
  1755. {$endif}
  1756. end;
  1757. procedure tentryfile.putpuint(i : puint);
  1758. begin
  1759. {$ifdef DEBUG_PPU}
  1760. ppu_log('putpuint');
  1761. inc_log_level;
  1762. ppu_log_val(tostr(i));
  1763. {$endif}
  1764. putdata(i,sizeof(puint));
  1765. {$ifdef DEBUG_PPU}
  1766. dec_log_level;
  1767. {$endif}
  1768. end;
  1769. procedure tentryfile.putptruint(v:TConstPtrUInt);
  1770. begin
  1771. {$ifdef DEBUG_PPU}
  1772. ppu_log('putptruint');
  1773. inc_log_level;
  1774. {$endif}
  1775. {$if sizeof(TConstPtrUInt)=8}
  1776. putint64(int64(v));
  1777. {$else}
  1778. putlongint(longint(v));
  1779. {$endif}
  1780. {$ifdef DEBUG_PPU}
  1781. dec_log_level;
  1782. {$endif}
  1783. end;
  1784. procedure tentryfile.putaword(i:aword);
  1785. begin
  1786. {$ifdef DEBUG_PPU}
  1787. ppu_log('putaword');
  1788. inc_log_level;
  1789. ppu_log_val(tostr(i));
  1790. {$endif}
  1791. putdata(i,sizeof(aword));
  1792. {$ifdef DEBUG_PPU}
  1793. dec_log_level;
  1794. {$endif}
  1795. end;
  1796. procedure tentryfile.putreal(d:entryreal);
  1797. var
  1798. hd : double;
  1799. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1800. {$ifdef FPC_SOFT_FPUX80}
  1801. floatx80_ba : floatx80_byte_array;
  1802. floatx80_e : floatx80;
  1803. f64 : float64;
  1804. local_softfloat_exception_mask : TFPUExceptionMask;
  1805. i:byte;
  1806. {$endif FPC_SOFT_FFPUX80}
  1807. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1808. begin
  1809. if target_info.system=system_x86_64_win64 then
  1810. begin
  1811. {$ifdef DEBUG_PPU}
  1812. ppu_log('putreal,size='+tostr(sizeof(hd)));
  1813. inc_log_level;
  1814. ppu_log_val(realtostr(d));
  1815. {$endif}
  1816. hd:=d;
  1817. putdata(hd,sizeof(hd));
  1818. end
  1819. {$ifndef FPC_HAS_TYPE_EXTENDED}
  1820. {$ifdef FPC_SOFT_FPUX80}
  1821. else if target_info.cpu in [cpu_i8086, cpu_i386, cpu_x86_64] then
  1822. begin
  1823. {$ifdef DEBUG_PPU}
  1824. ppu_log('putreal,size='+tostr(sizeof(floatx80_e)));
  1825. inc_log_level;
  1826. {$endif}
  1827. local_softfloat_exception_mask:=softfloat_exception_mask;
  1828. softfloat_exception_mask:=[float_flag_invalid,float_flag_denormal,float_flag_divbyzero,float_flag_overflow,float_flag_underflow,float_flag_inexact];
  1829. f64:=float64(d);
  1830. floatx80_e:=float64_to_floatx80(f64);
  1831. softfloat_exception_mask:=local_softfloat_exception_mask;
  1832. {$ifdef FPC_BIG_ENDIAN}
  1833. pword(@floatx80_ba[0])^:=floatx80_e.high;
  1834. unaligned(pqword(@floatx80_ba[2])^):=floatx80_e.low;
  1835. {$else}
  1836. pword(@floatx80_ba[8])^:=floatx80_e.high;
  1837. pqword(@floatx80_ba[0])^:=floatx80_e.low;
  1838. {$endif}
  1839. putdata(floatx80_ba,sizeof(floatx80_ba));
  1840. end
  1841. {$endif FPC_SOFT_FPUX80}
  1842. {$endif ndef FPC_HAS_TYPE_EXTENDED}
  1843. else
  1844. begin
  1845. {$ifdef DEBUG_PPU}
  1846. ppu_log('putreal,size='+tostr(sizeof(d)));
  1847. inc_log_level;
  1848. ppu_log_val(realtostr(d));
  1849. {$endif}
  1850. putdata(d,sizeof(entryreal));
  1851. end;
  1852. {$ifdef DEBUG_PPU}
  1853. dec_log_level;
  1854. {$endif}
  1855. end;
  1856. procedure tentryfile.putboolean(b:boolean);
  1857. begin
  1858. {$ifdef DEBUG_PPU}
  1859. ppu_log('putboolean');
  1860. inc_log_level;
  1861. {$endif}
  1862. putbyte(byte(b));
  1863. {$ifdef DEBUG_PPU}
  1864. dec_log_level;
  1865. {$endif}
  1866. end;
  1867. procedure tentryfile.putstring(const s:string);
  1868. begin
  1869. {$ifdef DEBUG_PPU}
  1870. { The reading method uses getbyte, so fake it here }
  1871. ppu_log('putbyte');
  1872. inc_log_level;
  1873. inc(bufidx);
  1874. ppu_log('putstring,size='+tostr(length(s)+1));
  1875. dec(bufidx);
  1876. ppu_log_val(s);
  1877. {$endif}
  1878. putdata(s,length(s)+1);
  1879. {$ifdef DEBUG_PPU}
  1880. dec_log_level;
  1881. {$endif}
  1882. end;
  1883. procedure tentryfile.putansistring(const s:ansistring);
  1884. var
  1885. len: longint;
  1886. begin
  1887. len:=length(s);
  1888. {$ifdef DEBUG_PPU}
  1889. ppu_log('putansistring');
  1890. inc_log_level;
  1891. ppu_log_val(s);
  1892. {$endif}
  1893. putlongint(len);
  1894. if len>0 then
  1895. putdata(s[1],len);
  1896. {$ifdef DEBUG_PPU}
  1897. dec_log_level;
  1898. {$endif}
  1899. end;
  1900. procedure tentryfile.putset(const arr: array of byte);
  1901. {$ifdef DEBUG_PPU}
  1902. var
  1903. i : byte;
  1904. {$endif}
  1905. begin
  1906. {$ifdef DEBUG_PPU}
  1907. ppu_log('putset');
  1908. inc_log_level;
  1909. {$endif}
  1910. putdata(arr,sizeof(arr));
  1911. {$ifdef DEBUG_PPU}
  1912. for i:=0 to sizeof(arr)-1 do
  1913. ppu_log_val('byte['+tostr(i)+']=$'+hexstr(arr[i],2));
  1914. dec_log_level;
  1915. {$endif}
  1916. end;
  1917. procedure tentryfile.tempclose;
  1918. begin
  1919. if not closed then
  1920. begin
  1921. closepos:=f.Position;
  1922. f.Free;
  1923. f:=nil;
  1924. closed:=true;
  1925. tempclosed:=true;
  1926. end;
  1927. end;
  1928. function tentryfile.tempopen:boolean;
  1929. begin
  1930. tempopen:=false;
  1931. if not closed or not tempclosed then
  1932. exit;
  1933. { MG: not sure, if this is correct
  1934. f.position:=0;
  1935. No, f was freed in tempclose above, we need to
  1936. recreate it. PM 2011/06/06 }
  1937. try
  1938. f:=CFileStreamClass.Create(fname,fmOpenRead);
  1939. except
  1940. exit;
  1941. end;
  1942. closed:=false;
  1943. tempclosed:=false;
  1944. { restore state }
  1945. f.Position:=closepos;
  1946. tempopen:=true;
  1947. end;
  1948. end.