symtype.pas 28 KB

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