symtype.pas 27 KB

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