symtype.pas 27 KB

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