symtype.pas 26 KB

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