symtype.pas 26 KB

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