symtype.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. This unit handles the symbol tables
  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 symtype;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,
  23. cclasses,
  24. { global }
  25. globtype,globals,constexp,
  26. { symtable }
  27. symconst,symbase,
  28. { aasm }
  29. aasmbase,ppu,cpuinfo
  30. ;
  31. type
  32. {************************************************
  33. Required Forwards
  34. ************************************************}
  35. tsym = class;
  36. Tcompilerppufile=class;
  37. {************************************************
  38. TDef
  39. ************************************************}
  40. tgeTSymtable = (gs_none,gs_record,gs_local,gs_para);
  41. tdef = class(TDefEntry)
  42. typesym : tsym; { which type the definition was generated this def }
  43. { maybe it's useful to merge the dwarf and stabs debugging info with some hacking }
  44. { dwarf debugging }
  45. dwarf_lab : tasmsymbol;
  46. dwarf_ref_lab : tasmsymbol;
  47. { stabs debugging }
  48. stab_number : word;
  49. dbg_state : tdefdbgstatus;
  50. defoptions : tdefoptions;
  51. defstates : tdefstates;
  52. constructor create(dt:tdeftyp);
  53. procedure buildderef;virtual;abstract;
  54. procedure buildderefimpl;virtual;abstract;
  55. procedure deref;virtual;abstract;
  56. procedure derefimpl;virtual;abstract;
  57. function typename:string;
  58. function fulltypename:string;
  59. function GetTypeName:string;virtual;
  60. function typesymbolprettyname:string;virtual;
  61. function mangledparaname:string;
  62. function getmangledparaname:TSymStr;virtual;
  63. function rtti_mangledname(rt:trttitype):string;virtual;abstract;
  64. function OwnerHierarchyName: string; virtual; abstract;
  65. function fullownerhierarchyname:string;virtual;abstract;
  66. function size:asizeint;virtual;abstract;
  67. function packedbitsize:asizeint;virtual;
  68. function alignment:shortint;virtual;abstract;
  69. { alignment when this type appears in a record/class/... }
  70. function structalignment:shortint;virtual;
  71. function getvardef:longint;virtual;abstract;
  72. function getparentdef:tdef;virtual;
  73. function geTSymtable(t:tgeTSymtable):TSymtable;virtual;
  74. function is_publishable:boolean;virtual;abstract;
  75. function needs_inittable:boolean;virtual;abstract;
  76. function needs_separate_initrtti:boolean;virtual;abstract;
  77. procedure ChangeOwner(st:TSymtable);
  78. procedure register_created_object_type;virtual;
  79. end;
  80. {************************************************
  81. TSym
  82. ************************************************}
  83. { this object is the base for all symbol objects }
  84. { tsym }
  85. tsym = class(TSymEntry)
  86. protected
  87. public
  88. fileinfo : tfileposinfo;
  89. { size of fileinfo is 10 bytes, so if a >word aligned type would follow,
  90. two bytes of memory would be wasted, so we put two one byte fields over here }
  91. visibility : tvisibility;
  92. isdbgwritten : boolean;
  93. symoptions : tsymoptions;
  94. refs : longint;
  95. reflist : TLinkedList;
  96. { deprecated optionally can have a message }
  97. deprecatedmsg: pshortstring;
  98. constructor create(st:tsymtyp;const aname:string);
  99. destructor destroy;override;
  100. function mangledname:TSymStr; virtual;
  101. function prettyname:string; virtual;
  102. procedure buildderef;virtual;
  103. procedure deref;virtual;
  104. procedure ChangeOwner(st:TSymtable);
  105. procedure IncRefCount;
  106. procedure IncRefCountBy(AValue : longint);
  107. procedure MaybeCreateRefList;
  108. procedure AddRef;
  109. end;
  110. tsymarr = array[0..maxlongint div sizeof(pointer)-1] of tsym;
  111. psymarr = ^tsymarr;
  112. {************************************************
  113. TDeref
  114. ************************************************}
  115. tderef = object
  116. dataidx : longint;
  117. procedure reset;
  118. procedure build(s:TObject);
  119. function resolve:TObject;
  120. end;
  121. pderef = ^tderef;
  122. {************************************************
  123. tpropaccesslist
  124. ************************************************}
  125. ppropaccesslistitem = ^tpropaccesslistitem;
  126. tpropaccesslistitem = record
  127. sltype : tsltype;
  128. next : ppropaccesslistitem;
  129. case byte of
  130. 0 : (sym : tsym; symderef : tderef);
  131. 1 : (value : TConstExprInt; valuedef: tdef; valuedefderef:tderef);
  132. 2 : (def: tdef; defderef:tderef);
  133. end;
  134. tpropaccesslist = class
  135. procdef : tdef;
  136. procdefderef : tderef;
  137. firstsym,
  138. lastsym : ppropaccesslistitem;
  139. constructor create;
  140. destructor destroy;override;
  141. function empty:boolean;
  142. procedure addsym(slt:tsltype;p:tsym);
  143. procedure addconst(slt:tsltype;v:TConstExprInt;d:tdef);
  144. procedure addtype(slt:tsltype;d:tdef);
  145. procedure addsymderef(slt:tsltype;d:tderef);
  146. procedure addconstderef(slt:tsltype;v:TConstExprInt;d:tderef);
  147. procedure addtypederef(slt:tsltype;d:tderef);
  148. procedure clear;
  149. procedure resolve;
  150. procedure buildderef;
  151. end;
  152. {************************************************
  153. Tcompilerppufile
  154. ************************************************}
  155. tcompilerppufile=class(tppufile)
  156. public
  157. procedure checkerror;
  158. procedure getguid(var g: tguid);
  159. function getexprint:Tconstexprint;
  160. function getptruint:TConstPtrUInt;
  161. procedure getposinfo(var p:tfileposinfo);
  162. procedure getderef(var d:tderef);
  163. function getpropaccesslist:tpropaccesslist;
  164. function getasmsymbol:tasmsymbol;
  165. procedure putguid(const g: tguid);
  166. procedure putexprint(const v:tconstexprint);
  167. procedure PutPtrUInt(v:TConstPtrUInt);
  168. procedure putposinfo(const p:tfileposinfo);
  169. procedure putderef(const d:tderef);
  170. procedure putpropaccesslist(p:tpropaccesslist);
  171. procedure putasmsymbol(s:tasmsymbol);
  172. end;
  173. {$ifdef MEMDEBUG}
  174. var
  175. memmanglednames,
  176. memprocpara,
  177. memprocparast,
  178. memproclocalst,
  179. memprocnodetree : tmemdebug;
  180. {$endif MEMDEBUG}
  181. function FindUnitSymtable(st:TSymtable):TSymtable;
  182. implementation
  183. uses
  184. crefs,
  185. verbose,
  186. fmodule
  187. ;
  188. {****************************************************************************
  189. Utils
  190. ****************************************************************************}
  191. function FindUnitSymtable(st:TSymtable):TSymtable;
  192. begin
  193. result:=nil;
  194. repeat
  195. if not assigned(st) then
  196. internalerror(200602034);
  197. case st.symtabletype of
  198. localmacrosymtable,
  199. exportedmacrosymtable,
  200. staticsymtable,
  201. globalsymtable :
  202. begin
  203. result:=st;
  204. exit;
  205. end;
  206. recordsymtable,
  207. enumsymtable,
  208. arraysymtable,
  209. localsymtable,
  210. parasymtable,
  211. ObjectSymtable :
  212. st:=st.defowner.owner;
  213. else
  214. internalerror(200602035);
  215. end;
  216. until false;
  217. end;
  218. {****************************************************************************
  219. Tdef
  220. ****************************************************************************}
  221. constructor tdef.create(dt:tdeftyp);
  222. begin
  223. inherited create;
  224. typ:=dt;
  225. owner := nil;
  226. typesym := nil;
  227. defoptions:=[];
  228. dbg_state:=dbg_state_unused;
  229. stab_number:=0;
  230. end;
  231. function tdef.typename:string;
  232. begin
  233. result:=OwnerHierarchyName;
  234. if assigned(typesym) and
  235. not(typ in [procvardef,procdef]) and
  236. (typesym.realname[1]<>'$') then
  237. result:=result+typesym.realname
  238. else
  239. result:=result+GetTypeName;
  240. end;
  241. function tdef.fulltypename:string;
  242. begin
  243. result:=fullownerhierarchyname;
  244. if assigned(typesym) and
  245. not(typ in [procvardef,procdef]) and
  246. (typesym.realname[1]<>'$') then
  247. result:=result+typesym.realname
  248. else
  249. result:=result+GetTypeName;
  250. end;
  251. function tdef.GetTypeName : string;
  252. begin
  253. GetTypeName:='<unknown type>' end;
  254. function tdef.typesymbolprettyname:string;
  255. begin
  256. result:=OwnerHierarchyName;
  257. if assigned(typesym) then
  258. result:=result+typesym.prettyname
  259. else
  260. result:=result+'<no type symbol>'
  261. end;
  262. function tdef.mangledparaname:string;
  263. begin
  264. result:=OwnerHierarchyName;
  265. if assigned(typesym) then
  266. mangledparaname:=result+typesym.name
  267. else
  268. mangledparaname:=result+getmangledparaname;
  269. end;
  270. function tdef.getmangledparaname:TSymStr;
  271. begin
  272. result:='<unknown type>';
  273. end;
  274. function tdef.getparentdef:tdef;
  275. begin
  276. result:=nil;
  277. end;
  278. function tdef.geTSymtable(t:tgeTSymtable):TSymtable;
  279. begin
  280. result:=nil;
  281. end;
  282. function tdef.packedbitsize:asizeint;
  283. begin
  284. result:=size * 8;
  285. end;
  286. function tdef.structalignment: shortint;
  287. begin
  288. result:=alignment;
  289. end;
  290. procedure tdef.ChangeOwner(st:TSymtable);
  291. begin
  292. // if assigned(Owner) then
  293. // Owner.DefList.List[i]:=nil;
  294. Owner:=st;
  295. Owner.DefList.Add(self);
  296. end;
  297. procedure tdef.register_created_object_type;
  298. begin
  299. end;
  300. {****************************************************************************
  301. TSYM (base for all symtypes)
  302. ****************************************************************************}
  303. constructor tsym.create(st:tsymtyp;const aname:string);
  304. begin
  305. inherited CreateNotOwned;
  306. realname:=aname;
  307. typ:=st;
  308. RefList:=nil;
  309. symoptions:=[];
  310. fileinfo:=current_tokenpos;
  311. isdbgwritten := false;
  312. visibility:=vis_public;
  313. deprecatedmsg:=nil;
  314. end;
  315. destructor Tsym.destroy;
  316. begin
  317. stringdispose(deprecatedmsg);
  318. if assigned(RefList) then
  319. RefList.Free;
  320. inherited Destroy;
  321. end;
  322. procedure Tsym.IncRefCount;
  323. begin
  324. inc(refs);
  325. if cs_browser in current_settings.moduleswitches then
  326. begin
  327. MaybeCreateRefList;
  328. AddRef;
  329. end;
  330. end;
  331. procedure Tsym.IncRefCountBy(AValue : longint);
  332. begin
  333. inc(refs,AValue);
  334. end;
  335. procedure Tsym.MaybeCreateRefList;
  336. begin
  337. if not assigned(reflist) then
  338. reflist:=TRefLinkedList.create;
  339. end;
  340. procedure Tsym.AddRef;
  341. var
  342. RefItem: TRefItem;
  343. begin
  344. RefItem:=TRefItem.Create(current_tokenpos);
  345. RefList.Concat(RefItem);
  346. end;
  347. procedure Tsym.buildderef;
  348. begin
  349. end;
  350. procedure Tsym.deref;
  351. begin
  352. end;
  353. function tsym.mangledname : TSymStr;
  354. begin
  355. internalerror(200204171);
  356. result:='';
  357. end;
  358. function tsym.prettyname : string;
  359. begin
  360. result:=realname;
  361. end;
  362. procedure tsym.ChangeOwner(st:TSymtable);
  363. begin
  364. Owner:=st;
  365. inherited ChangeOwner(Owner.SymList);
  366. end;
  367. {****************************************************************************
  368. tpropaccesslist
  369. ****************************************************************************}
  370. constructor tpropaccesslist.create;
  371. begin
  372. procdef:=nil; { needed for procedures }
  373. firstsym:=nil;
  374. lastsym:=nil;
  375. end;
  376. destructor tpropaccesslist.destroy;
  377. begin
  378. clear;
  379. end;
  380. function tpropaccesslist.empty:boolean;
  381. begin
  382. empty:=(firstsym=nil);
  383. end;
  384. procedure tpropaccesslist.clear;
  385. var
  386. hp : ppropaccesslistitem;
  387. begin
  388. while assigned(firstsym) do
  389. begin
  390. hp:=firstsym;
  391. firstsym:=firstsym^.next;
  392. dispose(hp);
  393. end;
  394. firstsym:=nil;
  395. lastsym:=nil;
  396. procdef:=nil;
  397. end;
  398. procedure tpropaccesslist.addsym(slt:tsltype;p:tsym);
  399. var
  400. hp : ppropaccesslistitem;
  401. begin
  402. new(hp);
  403. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  404. hp^.sltype:=slt;
  405. hp^.sym:=p;
  406. hp^.symderef.reset;
  407. if assigned(lastsym) then
  408. lastsym^.next:=hp
  409. else
  410. firstsym:=hp;
  411. lastsym:=hp;
  412. end;
  413. procedure tpropaccesslist.addconst(slt:tsltype;v:TConstExprInt;d:tdef);
  414. var
  415. hp : ppropaccesslistitem;
  416. begin
  417. new(hp);
  418. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  419. hp^.sltype:=slt;
  420. hp^.value:=v;
  421. hp^.valuedef:=d;
  422. hp^.valuedefderef.reset;
  423. if assigned(lastsym) then
  424. lastsym^.next:=hp
  425. else
  426. firstsym:=hp;
  427. lastsym:=hp;
  428. end;
  429. procedure tpropaccesslist.addtype(slt:tsltype;d:tdef);
  430. var
  431. hp : ppropaccesslistitem;
  432. begin
  433. new(hp);
  434. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  435. hp^.sltype:=slt;
  436. hp^.def:=d;
  437. hp^.defderef.reset;
  438. if assigned(lastsym) then
  439. lastsym^.next:=hp
  440. else
  441. firstsym:=hp;
  442. lastsym:=hp;
  443. end;
  444. procedure tpropaccesslist.addsymderef(slt:tsltype;d:tderef);
  445. begin
  446. addsym(slt,nil);
  447. lastsym^.symderef:=d;
  448. end;
  449. procedure tpropaccesslist.addconstderef(slt:tsltype;v:TConstExprInt;d:tderef);
  450. begin
  451. addconst(slt,v,nil);
  452. lastsym^.valuedefderef:=d;
  453. end;
  454. procedure tpropaccesslist.addtypederef(slt:tsltype;d:tderef);
  455. begin
  456. addtype(slt,nil);
  457. lastsym^.defderef:=d;
  458. end;
  459. procedure tpropaccesslist.resolve;
  460. var
  461. hp : ppropaccesslistitem;
  462. begin
  463. procdef:=tdef(procdefderef.resolve);
  464. hp:=firstsym;
  465. while assigned(hp) do
  466. begin
  467. case hp^.sltype of
  468. sl_call,
  469. sl_load,
  470. sl_subscript :
  471. hp^.sym:=tsym(hp^.symderef.resolve);
  472. sl_absolutetype,
  473. sl_typeconv :
  474. hp^.def:=tdef(hp^.defderef.resolve);
  475. sl_vec:
  476. hp^.valuedef:=tdef(hp^.valuedefderef.resolve);
  477. else
  478. internalerror(200110205);
  479. end;
  480. hp:=hp^.next;
  481. end;
  482. end;
  483. procedure tpropaccesslist.buildderef;
  484. var
  485. hp : ppropaccesslistitem;
  486. begin
  487. procdefderef.build(procdef);
  488. hp:=firstsym;
  489. while assigned(hp) do
  490. begin
  491. case hp^.sltype of
  492. sl_call,
  493. sl_load,
  494. sl_subscript :
  495. hp^.symderef.build(hp^.sym);
  496. sl_absolutetype,
  497. sl_typeconv :
  498. hp^.defderef.build(hp^.def);
  499. sl_vec:
  500. hp^.valuedefderef.build(hp^.valuedef);
  501. else
  502. internalerror(200110205);
  503. end;
  504. hp:=hp^.next;
  505. end;
  506. end;
  507. {****************************************************************************
  508. Tderef
  509. ****************************************************************************}
  510. procedure tderef.reset;
  511. begin
  512. dataidx:=-1;
  513. end;
  514. procedure tderef.build(s:TObject);
  515. var
  516. len : byte;
  517. st : TSymtable;
  518. data : array[0..255] of byte;
  519. idx : word;
  520. begin
  521. { skip length byte }
  522. len:=1;
  523. if assigned(s) then
  524. begin
  525. { TODO: ugly hack}
  526. if s is tsym then
  527. st:=FindUnitSymtable(tsym(s).owner)
  528. else
  529. st:=FindUnitSymtable(tdef(s).owner);
  530. if not st.iscurrentunit then
  531. begin
  532. { register that the unit is needed for resolving }
  533. data[len]:=ord(deref_unit);
  534. idx:=current_module.derefidx_unit(st.moduleid);
  535. data[len+1]:=idx shr 8 and $ff;
  536. data[len+2]:=idx and $ff;
  537. inc(len,3);
  538. end;
  539. if s is tsym then
  540. begin
  541. data[len]:=ord(deref_symid);
  542. data[len+1]:=tsym(s).symid shr 24 and $ff;
  543. data[len+2]:=tsym(s).symid shr 16 and $ff;
  544. data[len+3]:=tsym(s).symid shr 8 and $ff;
  545. data[len+4]:=tsym(s).symid and $ff;
  546. inc(len,5);
  547. end
  548. else
  549. begin
  550. data[len]:=ord(deref_defid);
  551. data[len+1]:=tdef(s).defid shr 24 and $ff;
  552. data[len+2]:=tdef(s).defid shr 16 and $ff;
  553. data[len+3]:=tdef(s).defid shr 8 and $ff;
  554. data[len+4]:=tdef(s).defid and $ff;
  555. inc(len,5);
  556. end;
  557. end
  558. else
  559. begin
  560. { nil pointer }
  561. data[len]:=ord(deref_nil);
  562. inc(len);
  563. end;
  564. { store data length in first byte }
  565. data[0]:=len-1;
  566. { store index and write to derefdata }
  567. dataidx:=current_module.derefdata.size;
  568. current_module.derefdata.write(data,len);
  569. end;
  570. function tderef.resolve:TObject;
  571. var
  572. pm : tmodule;
  573. typ : tdereftype;
  574. idx : longint;
  575. i : aint;
  576. len : byte;
  577. data : array[0..255] of byte;
  578. begin
  579. result:=nil;
  580. { not initialized or error }
  581. if dataidx<0 then
  582. internalerror(200306067);
  583. { read data }
  584. current_module.derefdata.seek(dataidx);
  585. if current_module.derefdata.read(len,1)<>1 then
  586. internalerror(200310221);
  587. if len>0 then
  588. begin
  589. if current_module.derefdata.read(data,len)<>len then
  590. internalerror(200310222);
  591. end;
  592. { process data }
  593. pm:=current_module;
  594. i:=0;
  595. while (i<len) do
  596. begin
  597. typ:=tdereftype(data[i]);
  598. inc(i);
  599. case typ of
  600. deref_unit :
  601. begin
  602. idx:=(data[i] shl 8) or data[i+1];
  603. inc(i,2);
  604. pm:=current_module.resolve_unit(idx);
  605. end;
  606. deref_defid :
  607. begin
  608. idx:=longint((data[i] shl 24) or (data[i+1] shl 16) or (data[i+2] shl 8) or data[i+3]);
  609. inc(i,4);
  610. result:=tdef(pm.deflist[idx]);
  611. end;
  612. deref_symid :
  613. begin
  614. idx:=longint((data[i] shl 24) or (data[i+1] shl 16) or (data[i+2] shl 8) or data[i+3]);
  615. inc(i,4);
  616. result:=tsym(pm.symlist[idx]);
  617. end;
  618. deref_nil :
  619. begin
  620. result:=nil;
  621. { Only allowed when no other deref is available }
  622. if len<>1 then
  623. internalerror(200306232);
  624. end;
  625. else
  626. internalerror(200212277);
  627. end;
  628. end;
  629. end;
  630. {*****************************************************************************
  631. TCompilerPPUFile
  632. *****************************************************************************}
  633. procedure tcompilerppufile.checkerror;
  634. begin
  635. if error then
  636. Message(unit_f_ppu_read_error);
  637. end;
  638. procedure tcompilerppufile.getguid(var g: tguid);
  639. begin
  640. longint(g.d1):=getlongint;
  641. g.d2:=getword;
  642. g.d3:=getword;
  643. getdata(g.d4,sizeof(g.d4));
  644. end;
  645. function tcompilerppufile.getexprint:Tconstexprint;
  646. begin
  647. getexprint.overflow:=false;
  648. getexprint.signed:=boolean(getbyte);
  649. getexprint.svalue:=getint64;
  650. end;
  651. function tcompilerppufile.getPtrUInt:TConstPtrUInt;
  652. begin
  653. {$if sizeof(TConstPtrUInt)=8}
  654. result:=tconstptruint(getint64);
  655. {$else}
  656. result:=TConstPtrUInt(getlongint);
  657. {$endif}
  658. end;
  659. procedure tcompilerppufile.getposinfo(var p:tfileposinfo);
  660. var
  661. info : byte;
  662. begin
  663. {
  664. info byte layout in bits:
  665. 0-1 - amount of bytes for fileindex
  666. 2-3 - amount of bytes for line
  667. 4-5 - amount of bytes for column
  668. }
  669. info:=getbyte;
  670. case (info and $03) of
  671. 0 : p.fileindex:=getbyte;
  672. 1 : p.fileindex:=getword;
  673. 2 : p.fileindex:=(getbyte shl 16) or getword;
  674. 3 : p.fileindex:=getlongint;
  675. end;
  676. case ((info shr 2) and $03) of
  677. 0 : p.line:=getbyte;
  678. 1 : p.line:=getword;
  679. 2 : p.line:=(getbyte shl 16) or getword;
  680. 3 : p.line:=getlongint;
  681. end;
  682. case ((info shr 4) and $03) of
  683. 0 : p.column:=getbyte;
  684. 1 : p.column:=getword;
  685. 2 : p.column:=(getbyte shl 16) or getword;
  686. 3 : p.column:=getlongint;
  687. end;
  688. p.moduleindex:=current_module.unit_index;
  689. end;
  690. procedure tcompilerppufile.getderef(var d:tderef);
  691. begin
  692. d.dataidx:=getlongint;
  693. end;
  694. function tcompilerppufile.getpropaccesslist:tpropaccesslist;
  695. var
  696. hderef : tderef;
  697. slt : tsltype;
  698. idx : longint;
  699. p : tpropaccesslist;
  700. begin
  701. p:=tpropaccesslist.create;
  702. getderef(p.procdefderef);
  703. repeat
  704. slt:=tsltype(getbyte);
  705. case slt of
  706. sl_none :
  707. break;
  708. sl_call,
  709. sl_load,
  710. sl_subscript :
  711. begin
  712. getderef(hderef);
  713. p.addsymderef(slt,hderef);
  714. end;
  715. sl_absolutetype,
  716. sl_typeconv :
  717. begin
  718. getderef(hderef);
  719. p.addtypederef(slt,hderef);
  720. end;
  721. sl_vec :
  722. begin
  723. idx:=getlongint;
  724. getderef(hderef);
  725. p.addconstderef(slt,idx,hderef);
  726. end;
  727. else
  728. internalerror(200110204);
  729. end;
  730. until false;
  731. getpropaccesslist:=tpropaccesslist(p);
  732. end;
  733. function tcompilerppufile.getasmsymbol:tasmsymbol;
  734. begin
  735. getlongint;
  736. getasmsymbol:=nil;
  737. end;
  738. procedure tcompilerppufile.putposinfo(const p:tfileposinfo);
  739. var
  740. oldcrc : boolean;
  741. info : byte;
  742. begin
  743. { posinfo is not relevant for changes in PPU }
  744. oldcrc:=do_crc;
  745. do_crc:=false;
  746. {
  747. info byte layout in bits:
  748. 0-1 - amount of bytes for fileindex
  749. 2-3 - amount of bytes for line
  750. 4-5 - amount of bytes for column
  751. }
  752. info:=0;
  753. { calculate info byte }
  754. if (p.fileindex>$ff) then
  755. begin
  756. info:=info or $1;
  757. { uncomment this code if tfileposinfo.fileindex type was changed
  758. if (p.fileindex<=$ffff) then
  759. info:=info or $1
  760. else
  761. if (p.fileindex<=$ffffff) then
  762. info:=info or $2
  763. else
  764. info:=info or $3;
  765. }
  766. end;
  767. if (p.line>$ff) then
  768. begin
  769. if (p.line<=$ffff) then
  770. info:=info or $4
  771. else
  772. if (p.line<=$ffffff) then
  773. info:=info or $8
  774. else
  775. info:=info or $c;
  776. end;
  777. if (p.column>$ff) then
  778. begin
  779. info:=info or $10;
  780. { uncomment this code if tfileposinfo.column type was changed
  781. if (p.column<=$ffff) then
  782. info:=info or $10
  783. else
  784. if (p.column<=$ffffff) then
  785. info:=info or $20
  786. else
  787. info:=info or $30;
  788. }
  789. end;
  790. { write data }
  791. putbyte(info);
  792. case (info and $03) of
  793. 0 : putbyte(p.fileindex);
  794. 1 : putword(p.fileindex);
  795. 2 : begin
  796. putbyte(p.fileindex shr 16);
  797. putword(p.fileindex and $ffff);
  798. end;
  799. 3 : putlongint(p.fileindex);
  800. end;
  801. case ((info shr 2) and $03) of
  802. 0 : putbyte(p.line);
  803. 1 : putword(p.line);
  804. 2 : begin
  805. putbyte(p.line shr 16);
  806. putword(p.line and $ffff);
  807. end;
  808. 3 : putlongint(p.line);
  809. end;
  810. case ((info shr 4) and $03) of
  811. 0 : putbyte(p.column);
  812. 1 : putword(p.column);
  813. 2 : begin
  814. putbyte(p.column shr 16);
  815. putword(p.column and $ffff);
  816. end;
  817. 3 : putlongint(p.column);
  818. end;
  819. do_crc:=oldcrc;
  820. end;
  821. procedure tcompilerppufile.putguid(const g: tguid);
  822. begin
  823. putlongint(longint(g.d1));
  824. putword(g.d2);
  825. putword(g.d3);
  826. putdata(g.d4,sizeof(g.d4));
  827. end;
  828. procedure Tcompilerppufile.putexprint(const v:Tconstexprint);
  829. begin
  830. if v.overflow then
  831. internalerror(200706102);
  832. putbyte(byte(v.signed));
  833. putint64(v.svalue);
  834. end;
  835. procedure tcompilerppufile.PutPtrUInt(v:TConstPtrUInt);
  836. begin
  837. {$if sizeof(TConstPtrUInt)=8}
  838. putint64(int64(v));
  839. {$else}
  840. putlongint(longint(v));
  841. {$endif}
  842. end;
  843. procedure tcompilerppufile.putderef(const d:tderef);
  844. var
  845. oldcrc : boolean;
  846. begin
  847. oldcrc:=do_crc;
  848. do_crc:=false;
  849. putlongint(d.dataidx);
  850. do_crc:=oldcrc;
  851. end;
  852. procedure tcompilerppufile.putpropaccesslist(p:tpropaccesslist);
  853. var
  854. hp : ppropaccesslistitem;
  855. begin
  856. putderef(p.procdefderef);
  857. hp:=p.firstsym;
  858. while assigned(hp) do
  859. begin
  860. putbyte(byte(hp^.sltype));
  861. case hp^.sltype of
  862. sl_call,
  863. sl_load,
  864. sl_subscript :
  865. putderef(hp^.symderef);
  866. sl_absolutetype,
  867. sl_typeconv :
  868. putderef(hp^.defderef);
  869. sl_vec :
  870. begin
  871. putlongint(int64(hp^.value));
  872. putderef(hp^.valuedefderef);
  873. end;
  874. else
  875. internalerror(200110205);
  876. end;
  877. hp:=hp^.next;
  878. end;
  879. putbyte(byte(sl_none));
  880. end;
  881. procedure tcompilerppufile.putasmsymbol(s:tasmsymbol);
  882. begin
  883. putlongint(0);
  884. end;
  885. {$ifdef MEMDEBUG}
  886. initialization
  887. memmanglednames:=TMemDebug.create('Manglednames');
  888. memmanglednames.stop;
  889. memprocpara:=TMemDebug.create('ProcPara');
  890. memprocpara.stop;
  891. memprocparast:=TMemDebug.create('ProcParaSt');
  892. memprocparast.stop;
  893. memproclocalst:=TMemDebug.create('ProcLocalSt');
  894. memproclocalst.stop;
  895. memprocnodetree:=TMemDebug.create('ProcNodeTree');
  896. memprocnodetree.stop;
  897. finalization
  898. memmanglednames.free;
  899. memprocpara.free;
  900. memprocparast.free;
  901. memproclocalst.free;
  902. memprocnodetree.free;
  903. {$endif MEMDEBUG}
  904. end.