symtype.pas 27 KB

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