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