symtype.pas 27 KB

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