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