symtype.pas 26 KB

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