symtype.pas 27 KB

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