symtype.pas 30 KB

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