symtype.pas 27 KB

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