entfile.pas 47 KB

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