symtype.pas 26 KB

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