entfile.pas 48 KB

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