ncgrtti.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Routines for the code generation of RTTI data structures
  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 ncgrtti;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,constexp,
  22. aasmbase,aasmcnst,
  23. symbase,symconst,symtype,symdef,symsym;
  24. type
  25. { TRTTIWriter }
  26. TRTTIWriter=class
  27. private
  28. { required internal alignment of the rtti data }
  29. reqalign: shortint;
  30. { required packing of all structures except for ttypeinfo and tpropinfo,
  31. which always use packrecords 1 }
  32. defaultpacking: shortint;
  33. procedure fields_write_rtti(st:tsymtable;rt:trttitype);
  34. procedure params_write_rtti(def:tabstractprocdef;rt:trttitype);
  35. procedure fields_write_rtti_data(tcb: ttai_typedconstbuilder; def: tabstractrecorddef; rt: trttitype);
  36. procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  37. procedure published_write_rtti(st:tsymtable;rt:trttitype);
  38. function published_properties_count(st:tsymtable):longint;
  39. procedure published_properties_write_rtti_data(tcb: ttai_typedconstbuilder; propnamelist: TFPHashObjectList; st: tsymtable);
  40. procedure collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  41. { only use a direct reference if the referenced type can *only* reside
  42. in the same unit as the current one }
  43. function ref_rtti(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  44. procedure write_rtti_name(tcb: ttai_typedconstbuilder; def: tdef);
  45. procedure write_rtti_data(tcb: ttai_typedconstbuilder; def:tdef; rt: trttitype);
  46. procedure write_child_rtti_data(def:tdef;rt:trttitype);
  47. procedure write_rtti_reference(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  48. procedure write_header(tcb: ttai_typedconstbuilder; def: tdef; typekind: byte);
  49. function write_methodkind(tcb:ttai_typedconstbuilder;def:tabstractprocdef):byte;
  50. procedure write_callconv(tcb:ttai_typedconstbuilder;def:tabstractprocdef);
  51. procedure write_paralocs(tcb:ttai_typedconstbuilder;parasym:tparavarsym);
  52. public
  53. constructor create;
  54. procedure write_rtti(def:tdef;rt:trttitype);
  55. function get_rtti_label(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  56. function get_rtti_label_ord2str(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  57. function get_rtti_label_str2ord(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  58. end;
  59. { generate RTTI and init tables }
  60. procedure write_persistent_type_info(st:tsymtable;is_global:boolean);
  61. var
  62. RTTIWriter : TRTTIWriter;
  63. implementation
  64. uses
  65. cutils,
  66. globals,globtype,verbose,systems,
  67. fmodule, procinfo,
  68. symtable,
  69. aasmtai,aasmdata,
  70. defutil,
  71. parabase,paramgr,
  72. wpobase
  73. ;
  74. const
  75. rttidefstate : array[trttitype] of tdefstate =
  76. (ds_rtti_table_written,ds_init_table_written,
  77. { Objective-C related, does not pass here }
  78. symconst.ds_none,symconst.ds_none,
  79. symconst.ds_none,symconst.ds_none);
  80. type
  81. TPropNameListItem = class(TFPHashObject)
  82. propindex : longint;
  83. propowner : TSymtable;
  84. end;
  85. procedure write_persistent_type_info(st: tsymtable; is_global: boolean);
  86. var
  87. i : longint;
  88. def : tdef;
  89. begin
  90. { no Delphi-style RTTI for managed platforms }
  91. if target_info.system in systems_managed_vm then
  92. exit;
  93. for i:=0 to st.DefList.Count-1 do
  94. begin
  95. def:=tdef(st.DefList[i]);
  96. { skip generics }
  97. if [df_generic,df_genconstraint]*def.defoptions<>[] then
  98. continue;
  99. case def.typ of
  100. recorddef:
  101. write_persistent_type_info(trecorddef(def).symtable,is_global);
  102. objectdef :
  103. begin
  104. { Skip forward defs }
  105. if (oo_is_forward in tobjectdef(def).objectoptions) then
  106. continue;
  107. write_persistent_type_info(tobjectdef(def).symtable,is_global);
  108. end;
  109. procdef :
  110. begin
  111. if assigned(tprocdef(def).localst) and
  112. (tprocdef(def).localst.symtabletype=localsymtable) then
  113. write_persistent_type_info(tprocdef(def).localst,false);
  114. if assigned(tprocdef(def).parast) then
  115. write_persistent_type_info(tprocdef(def).parast,false);
  116. end;
  117. errordef:
  118. { we shouldn't have come this far if we have an errordef somewhere }
  119. internalerror(2017010701);
  120. undefineddef:
  121. { don't write any RTTI for these }
  122. continue;
  123. end;
  124. { always generate persistent tables for types in the interface so
  125. they can be reused in other units and give always the same pointer
  126. location. }
  127. { Init }
  128. if (
  129. assigned(def.typesym) and
  130. is_global and
  131. not is_objc_class_or_protocol(def)
  132. ) or
  133. is_managed_type(def) or
  134. (ds_init_table_used in def.defstates) then
  135. RTTIWriter.write_rtti(def,initrtti);
  136. { RTTI }
  137. if (
  138. assigned(def.typesym) and
  139. is_global and
  140. not is_objc_class_or_protocol(def)
  141. ) or
  142. (ds_rtti_table_used in def.defstates) then
  143. RTTIWriter.write_rtti(def,fullrtti);
  144. end;
  145. end;
  146. {***************************************************************************
  147. TRTTIWriter
  148. ***************************************************************************}
  149. procedure TRTTIWriter.write_header(tcb: ttai_typedconstbuilder; def: tdef; typekind: byte);
  150. var
  151. name: shortstring;
  152. begin
  153. if assigned(def.typesym) then
  154. name:=ttypesym(def.typesym).realname
  155. else
  156. name:='';
  157. { TTypeInfo, always packed and doesn't need alignment }
  158. tcb.begin_anonymous_record(
  159. internaltypeprefixName[itp_rtti_header]+tostr(length(name)),1,1,
  160. targetinfos[target_info.system]^.alignment.recordalignmin,
  161. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  162. if def.typ=arraydef then
  163. InternalError(201012211);
  164. tcb.emit_tai(Tai_const.Create_8bit(typekind),u8inttype);
  165. tcb.emit_shortstring_const(name);
  166. tcb.end_anonymous_record;
  167. end;
  168. function TRTTIWriter.write_methodkind(tcb:ttai_typedconstbuilder;def:tabstractprocdef):byte;
  169. begin
  170. case def.proctypeoption of
  171. potype_constructor: result:=mkConstructor;
  172. potype_destructor: result:=mkDestructor;
  173. potype_class_constructor: result:=mkClassConstructor;
  174. potype_class_destructor: result:=mkClassDestructor;
  175. potype_operator: result:=mkOperatorOverload;
  176. potype_procedure:
  177. if po_classmethod in def.procoptions then
  178. result:=mkClassProcedure
  179. else
  180. result:=mkProcedure;
  181. potype_function:
  182. if po_classmethod in def.procoptions then
  183. result:=mkClassFunction
  184. else
  185. result:=mkFunction;
  186. else
  187. begin
  188. if def.returndef = voidtype then
  189. result:=mkProcedure
  190. else
  191. result:=mkFunction;
  192. end;
  193. end;
  194. tcb.emit_ord_const(result,u8inttype);
  195. end;
  196. procedure TRTTIWriter.write_callconv(tcb:ttai_typedconstbuilder;def:tabstractprocdef);
  197. const
  198. ProcCallOptionToCallConv: array[tproccalloption] of byte = (
  199. { pocall_none } 0,
  200. { pocall_cdecl } 1,
  201. { pocall_cppdecl } 5,
  202. { pocall_far16 } 6,
  203. { pocall_oldfpccall } 7,
  204. { pocall_internproc } 8,
  205. { pocall_syscall } 9,
  206. { pocall_pascal } 2,
  207. { pocall_register } 0,
  208. { pocall_safecall } 4,
  209. { pocall_stdcall } 3,
  210. { pocall_softfloat } 10,
  211. { pocall_mwpascal } 11,
  212. { pocall_interrupt } 12,
  213. { pocall_hardfloat } 13
  214. );
  215. begin
  216. tcb.emit_ord_const(ProcCallOptionToCallConv[def.proccalloption],u8inttype);
  217. end;
  218. procedure TRTTIWriter.write_paralocs(tcb:ttai_typedconstbuilder;parasym:tparavarsym);
  219. var
  220. locs : trttiparalocs;
  221. i : longint;
  222. begin
  223. locs:=paramanager.cgparalocs_to_rttiparalocs(parasym.paraloc[callerside].location);
  224. if length(locs)>high(byte) then
  225. internalerror(2017010601);
  226. tcb.emit_ord_const(length(locs),u8inttype);
  227. for i:=low(locs) to high(locs) do
  228. begin
  229. tcb.emit_ord_const(locs[i].loctype,u8inttype);
  230. tcb.emit_ord_const(locs[i].regsub,u8inttype);
  231. tcb.emit_ord_const(locs[i].regindex,u16inttype);
  232. { the corresponding type for aint is alusinttype }
  233. tcb.emit_ord_const(locs[i].offset,alusinttype);
  234. end;
  235. end;
  236. procedure TRTTIWriter.write_rtti_name(tcb: ttai_typedconstbuilder; def: tdef);
  237. begin
  238. if is_open_array(def) then
  239. { open arrays never have a typesym with a name, since you cannot
  240. define an "open array type". Kylix prints the type of the
  241. elements in the array in this case (so together with the pfArray
  242. flag, you can reconstruct the full typename, I assume (JM))
  243. }
  244. def:=tarraydef(def).elementdef;
  245. { name }
  246. if assigned(def.typesym) then
  247. tcb.emit_shortstring_const(ttypesym(def.typesym).realname)
  248. else
  249. tcb.emit_shortstring_const('');
  250. end;
  251. { writes a 32-bit count followed by array of field infos for given symtable }
  252. procedure TRTTIWriter.fields_write_rtti_data(tcb: ttai_typedconstbuilder; def: tabstractrecorddef; rt: trttitype);
  253. var
  254. i : longint;
  255. sym : tsym;
  256. fieldcnt: longint;
  257. st: tsymtable;
  258. fields: tfplist;
  259. parentrtti: boolean;
  260. begin
  261. fieldcnt:=0;
  262. parentrtti:=false;
  263. st:=def.symtable;
  264. fields:=tfplist.create;
  265. fields.capacity:=st.symlist.count+1;
  266. { For objects, treat parent (if any) as a field with offset 0. This
  267. provides correct handling of entire instance with RTL rtti routines. }
  268. if (def.typ=objectdef) and (tobjectdef(def).objecttype=odt_object) and
  269. Assigned(tobjectdef(def).childof) and
  270. ((rt=fullrtti) or (tobjectdef(def).childof.needs_inittable)) then
  271. begin
  272. parentrtti:=true;
  273. inc(fieldcnt);
  274. end;
  275. for i:=0 to st.SymList.Count-1 do
  276. begin
  277. sym:=tsym(st.SymList[i]);
  278. if (tsym(sym).typ=fieldvarsym) and
  279. not(sp_static in tsym(sym).symoptions) and
  280. (
  281. (rt=fullrtti) or
  282. tfieldvarsym(sym).vardef.needs_inittable
  283. ) and
  284. not is_objc_class_or_protocol(tfieldvarsym(sym).vardef) then
  285. begin
  286. fields.add(tfieldvarsym(sym));
  287. inc(fieldcnt);
  288. end;
  289. end;
  290. { insert field count before data }
  291. tcb.emit_ord_const(fieldcnt,u32inttype);
  292. { parent object? }
  293. if parentrtti then
  294. begin
  295. write_rtti_reference(tcb,tobjectdef(def).childof,rt);
  296. tcb.emit_ord_const(0,ptruinttype);
  297. end;
  298. { fields }
  299. for i:=0 to fields.count-1 do
  300. begin
  301. sym:=tsym(fields[i]);
  302. write_rtti_reference(tcb,tfieldvarsym(sym).vardef,rt);
  303. tcb.emit_ord_const(tfieldvarsym(sym).fieldoffset,ptruinttype);
  304. end;
  305. fields.free;
  306. end;
  307. procedure TRTTIWriter.fields_write_rtti(st:tsymtable;rt:trttitype);
  308. var
  309. i : longint;
  310. sym : tsym;
  311. begin
  312. for i:=0 to st.SymList.Count-1 do
  313. begin
  314. sym:=tsym(st.SymList[i]);
  315. if (tsym(sym).typ=fieldvarsym) and
  316. not(sp_static in tsym(sym).symoptions) and
  317. (
  318. (rt=fullrtti) or
  319. tfieldvarsym(sym).vardef.needs_inittable
  320. ) then
  321. write_rtti(tfieldvarsym(sym).vardef,rt);
  322. end;
  323. end;
  324. procedure TRTTIWriter.params_write_rtti(def:tabstractprocdef;rt:trttitype);
  325. var
  326. i : longint;
  327. sym : tparavarsym;
  328. begin
  329. for i:=0 to def.paras.count-1 do
  330. begin
  331. sym:=tparavarsym(def.paras[i]);
  332. if not (vo_is_hidden_para in sym.varoptions) then
  333. write_rtti(sym.vardef,rt);
  334. end;
  335. end;
  336. procedure TRTTIWriter.published_write_rtti(st:tsymtable;rt:trttitype);
  337. var
  338. i : longint;
  339. sym : tsym;
  340. begin
  341. for i:=0 to st.SymList.Count-1 do
  342. begin
  343. sym:=tsym(st.SymList[i]);
  344. if (sym.visibility=vis_published) then
  345. begin
  346. case tsym(sym).typ of
  347. propertysym:
  348. write_rtti(tpropertysym(sym).propdef,rt);
  349. fieldvarsym:
  350. write_rtti(tfieldvarsym(sym).vardef,rt);
  351. end;
  352. end;
  353. end;
  354. end;
  355. function TRTTIWriter.published_properties_count(st:tsymtable):longint;
  356. var
  357. i : longint;
  358. sym : tsym;
  359. begin
  360. result:=0;
  361. for i:=0 to st.SymList.Count-1 do
  362. begin
  363. sym:=tsym(st.SymList[i]);
  364. if (tsym(sym).typ=propertysym) and
  365. (sym.visibility=vis_published) then
  366. inc(result);
  367. end;
  368. end;
  369. procedure TRTTIWriter.collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  370. var
  371. i : longint;
  372. sym : tsym;
  373. pn : tpropnamelistitem;
  374. begin
  375. if assigned(objdef.childof) then
  376. collect_propnamelist(propnamelist,objdef.childof);
  377. for i:=0 to objdef.symtable.SymList.Count-1 do
  378. begin
  379. sym:=tsym(objdef.symtable.SymList[i]);
  380. if (tsym(sym).typ=propertysym) and
  381. (sym.visibility=vis_published) then
  382. begin
  383. pn:=TPropNameListItem(propnamelist.Find(tsym(sym).name));
  384. if not assigned(pn) then
  385. begin
  386. pn:=tpropnamelistitem.create(propnamelist,tsym(sym).name);
  387. pn.propindex:=propnamelist.count-1;
  388. pn.propowner:=tsym(sym).owner;
  389. end;
  390. end;
  391. end;
  392. end;
  393. procedure TRTTIWriter.published_properties_write_rtti_data(tcb: ttai_typedconstbuilder; propnamelist:TFPHashObjectList;st:tsymtable);
  394. var
  395. i : longint;
  396. sym : tsym;
  397. proctypesinfo : byte;
  398. propnameitem : tpropnamelistitem;
  399. propdefname : string;
  400. procedure writeaccessproc(pap:tpropaccesslisttypes; shiftvalue : byte; unsetvalue: byte);
  401. var
  402. typvalue : byte;
  403. hp : ppropaccesslistitem;
  404. extnumber: longint;
  405. address,space : longint;
  406. def : tdef;
  407. hpropsym : tpropertysym;
  408. propaccesslist : tpropaccesslist;
  409. begin
  410. hpropsym:=tpropertysym(sym);
  411. repeat
  412. propaccesslist:=hpropsym.propaccesslist[pap];
  413. if not propaccesslist.empty then
  414. break;
  415. hpropsym:=hpropsym.overriddenpropsym;
  416. until not assigned(hpropsym);
  417. if not(assigned(propaccesslist) and assigned(propaccesslist.firstsym)) then
  418. begin
  419. tcb.emit_tai(Tai_const.Create_int_codeptr(unsetvalue),codeptruinttype);
  420. typvalue:=3;
  421. end
  422. else if propaccesslist.firstsym^.sym.typ=fieldvarsym then
  423. begin
  424. address:=0;
  425. hp:=propaccesslist.firstsym;
  426. def:=nil;
  427. while assigned(hp) do
  428. begin
  429. case hp^.sltype of
  430. sl_load :
  431. begin
  432. def:=tfieldvarsym(hp^.sym).vardef;
  433. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  434. end;
  435. sl_subscript :
  436. begin
  437. if not(assigned(def) and
  438. ((def.typ=recorddef) or
  439. is_object(def))) then
  440. internalerror(200402171);
  441. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  442. def:=tfieldvarsym(hp^.sym).vardef;
  443. end;
  444. sl_vec :
  445. begin
  446. if not(assigned(def) and (def.typ=arraydef)) then
  447. internalerror(200402172);
  448. def:=tarraydef(def).elementdef;
  449. {Hp.value is a Tconstexprint, which can be rather large,
  450. sanity check for longint overflow.}
  451. space:=(high(address)-address) div def.size;
  452. if int64(space)<hp^.value then
  453. internalerror(200706101);
  454. inc(address,int64(def.size*hp^.value));
  455. end;
  456. end;
  457. hp:=hp^.next;
  458. end;
  459. tcb.emit_tai(Tai_const.Create_int_codeptr(address),codeptruinttype);
  460. typvalue:=0;
  461. end
  462. else
  463. begin
  464. { When there was an error then procdef is not assigned }
  465. if not assigned(propaccesslist.procdef) then
  466. exit;
  467. if not(po_virtualmethod in tprocdef(propaccesslist.procdef).procoptions) or
  468. is_objectpascal_helper(tprocdef(propaccesslist.procdef).struct) then
  469. begin
  470. tcb.queue_init(codeptruinttype);
  471. tcb.queue_emit_proc(tprocdef(propaccesslist.procdef));
  472. typvalue:=1;
  473. end
  474. else
  475. begin
  476. { virtual method, write vmt offset }
  477. extnumber:=tprocdef(propaccesslist.procdef).extnumber;
  478. tcb.emit_tai(Tai_const.Create_int_codeptr(
  479. tobjectdef(tprocdef(propaccesslist.procdef).struct).vmtmethodoffset(extnumber)),
  480. codeptruinttype);
  481. { register for wpo }
  482. tobjectdef(tprocdef(propaccesslist.procdef).struct).register_vmt_call(extnumber);
  483. {$ifdef vtentry}
  484. { not sure if we can insert those vtentry symbols safely here }
  485. {$error register methods used for published properties}
  486. {$endif vtentry}
  487. typvalue:=2;
  488. end;
  489. end;
  490. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  491. end;
  492. begin
  493. tcb.begin_anonymous_record('',defaultpacking,min(reqalign,SizeOf(PtrInt)),
  494. targetinfos[target_info.system]^.alignment.recordalignmin,
  495. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  496. tcb.emit_ord_const(published_properties_count(st),u16inttype);
  497. for i:=0 to st.SymList.Count-1 do
  498. begin
  499. sym:=tsym(st.SymList[i]);
  500. if (sym.typ=propertysym) and
  501. (sym.visibility=vis_published) then
  502. begin
  503. { we can only easily reuse defs if the property is not stored,
  504. because otherwise the rtti layout depends on how the "stored"
  505. is defined (field, indexed expression, virtual method, ...) }
  506. if not(ppo_stored in tpropertysym(sym).propoptions) then
  507. propdefname:=internaltypeprefixName[itp_rtti_prop]+tostr(length(tpropertysym(sym).realname))
  508. else
  509. propdefname:='';
  510. { TPropInfo is a packed record (even on targets that require
  511. alignment), but it starts aligned }
  512. tcb.begin_anonymous_record(
  513. propdefname,
  514. 1,min(reqalign,SizeOf(PtrInt)),
  515. targetinfos[target_info.system]^.alignment.recordalignmin,
  516. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  517. if ppo_indexed in tpropertysym(sym).propoptions then
  518. proctypesinfo:=$40
  519. else
  520. proctypesinfo:=0;
  521. write_rtti_reference(tcb,tpropertysym(sym).propdef,fullrtti);
  522. writeaccessproc(palt_read,0,0);
  523. writeaccessproc(palt_write,2,0);
  524. { is it stored ? }
  525. if not(ppo_stored in tpropertysym(sym).propoptions) then
  526. begin
  527. { no, so put a constant zero }
  528. tcb.emit_tai(Tai_const.Create_nil_codeptr,codeptruinttype);
  529. proctypesinfo:=proctypesinfo or (3 shl 4);
  530. end
  531. else
  532. writeaccessproc(palt_stored,4,1); { maybe; if no procedure put a constant 1 (=true) }
  533. tcb.emit_ord_const(tpropertysym(sym).index,u32inttype);
  534. tcb.emit_ord_const(tpropertysym(sym).default,u32inttype);
  535. propnameitem:=TPropNameListItem(propnamelist.Find(tpropertysym(sym).name));
  536. if not assigned(propnameitem) then
  537. internalerror(200512201);
  538. tcb.emit_ord_const(propnameitem.propindex,u16inttype);
  539. tcb.emit_ord_const(proctypesinfo,u8inttype);
  540. tcb.emit_shortstring_const(tpropertysym(sym).realname);
  541. tcb.end_anonymous_record;
  542. end;
  543. end;
  544. tcb.end_anonymous_record;
  545. end;
  546. procedure TRTTIWriter.write_rtti_data(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  547. procedure unknown_rtti(def:tstoreddef);
  548. begin
  549. tcb.emit_ord_const(tkUnknown,u8inttype);
  550. write_rtti_name(tcb,def);
  551. end;
  552. procedure variantdef_rtti(def:tvariantdef);
  553. begin
  554. write_header(tcb,def,tkVariant);
  555. end;
  556. procedure stringdef_rtti(def:tstringdef);
  557. begin
  558. case def.stringtype of
  559. st_ansistring:
  560. begin
  561. write_header(tcb,def,tkAString);
  562. { align }
  563. tcb.begin_anonymous_record(
  564. internaltypeprefixName[itp_rtti_ansistr],
  565. defaultpacking,reqalign,
  566. targetinfos[target_info.system]^.alignment.recordalignmin,
  567. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  568. tcb.emit_ord_const(def.encoding,u16inttype);
  569. tcb.end_anonymous_record;
  570. end;
  571. st_widestring:
  572. write_header(tcb,def,tkWString);
  573. st_unicodestring:
  574. write_header(tcb,def,tkUString);
  575. st_longstring:
  576. write_header(tcb,def,tkLString);
  577. st_shortstring:
  578. begin
  579. write_header(tcb,def,tkSString);
  580. tcb.emit_ord_const(def.len,u8inttype);
  581. end;
  582. end;
  583. end;
  584. procedure enumdef_rtti(def: tenumdef);
  585. var
  586. i : integer;
  587. hp : tenumsym;
  588. begin
  589. write_header(tcb,def,tkEnumeration);
  590. { align; the named fields are so that we can let the compiler
  591. calculate the string offsets later on }
  592. tcb.next_field_name:='size_start_rec';
  593. { add a typename so that it can be reused when writing the the s2o
  594. and o2s arrays for llvm (otherwise we have to write out the entire
  595. type definition every time we access an element from this record) }
  596. tcb.begin_anonymous_record(internaltypeprefixName[itp_rtti_enum_size_start_rec]+def.unique_id_str,defaultpacking,reqalign,
  597. targetinfos[target_info.system]^.alignment.recordalignmin,
  598. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  599. case longint(def.size) of
  600. 1 :
  601. tcb.emit_ord_const(otUByte,u8inttype);
  602. 2 :
  603. tcb.emit_ord_const(otUWord,u8inttype);
  604. 4 :
  605. tcb.emit_ord_const(otULong,u8inttype);
  606. end;
  607. { we need to align by Tconstptruint here to satisfy the alignment
  608. rules set by records: in the typinfo unit we overlay a TTypeData
  609. record on this data, which at the innermost variant record needs an
  610. alignment of TConstPtrUint due to e.g. the "CompType" member for
  611. tkSet (also the "BaseType" member for tkEnumeration).
  612. We need to adhere to this, otherwise things will break. }
  613. tcb.next_field_name:='min_max_rec';
  614. tcb.begin_anonymous_record(internaltypeprefixName[itp_rtti_enum_min_max_rec]+def.unique_id_str,defaultpacking,reqalign,
  615. targetinfos[target_info.system]^.alignment.recordalignmin,
  616. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  617. tcb.emit_ord_const(def.min,s32inttype);
  618. tcb.emit_ord_const(def.max,s32inttype);
  619. tcb.next_field_name:='basetype_array_rec';
  620. { all strings must appear right after each other -> from now on
  621. packrecords 1 (but the start must still be aligned) }
  622. tcb.begin_anonymous_record(internaltypeprefixName[itp_rtti_enum_basetype_array_rec]+def.unique_id_str,1,reqalign,
  623. targetinfos[target_info.system]^.alignment.recordalignmin,
  624. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  625. { write base type }
  626. write_rtti_reference(tcb,def.basedef,rt);
  627. for i:=0 to def.symtable.SymList.Count-1 do
  628. begin
  629. hp:=tenumsym(def.symtable.SymList[i]);
  630. if hp.value<def.minval then
  631. continue
  632. else
  633. if hp.value>def.maxval then
  634. break;
  635. tcb.next_field_name:=hp.name;
  636. tcb.emit_shortstring_const(hp.realname);
  637. end;
  638. { write unit name }
  639. tcb.emit_shortstring_const(current_module.realmodulename^);
  640. { write zero which is required by RTL }
  641. tcb.emit_ord_const(0,u8inttype);
  642. { terminate all records }
  643. tcb.end_anonymous_record;
  644. tcb.end_anonymous_record;
  645. tcb.end_anonymous_record;
  646. end;
  647. procedure orddef_rtti(def:torddef);
  648. procedure doint32_64(typekind: byte;min,max:int64);
  649. const
  650. trans : array[tordtype] of byte =
  651. (otUByte{otNone},
  652. otUByte,otUWord,otULong,otUQWord,otUByte{otNone},
  653. otSByte,otSWord,otSLong,otSQWord,otUByte{otNone},
  654. otUByte,otUWord,otULong,otUQWord,
  655. otSByte,otSWord,otSLong,otSQWord,
  656. otUByte,otUWord,otUByte);
  657. var
  658. elesize: string[1];
  659. begin
  660. write_header(tcb,def,typekind);
  661. case trans[def.ordtype] of
  662. otUQWord,
  663. otSQWord:
  664. elesize:='8'
  665. else
  666. elesize:='4'
  667. end;
  668. tcb.begin_anonymous_record(
  669. internaltypeprefixName[itp_rtti_ord_outer]+elesize,
  670. defaultpacking,reqalign,
  671. targetinfos[target_info.system]^.alignment.recordalignmin,
  672. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  673. tcb.emit_ord_const(byte(trans[def.ordtype]),u8inttype);
  674. tcb.begin_anonymous_record(
  675. internaltypeprefixName[itp_rtti_ord_inner]+elesize,
  676. defaultpacking,reqalign,
  677. targetinfos[target_info.system]^.alignment.recordalignmin,
  678. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  679. {Convert to longint to smuggle values in high(longint)+1..high(cardinal) into asmlist.}
  680. case trans[def.ordtype] of
  681. otUQWord:
  682. begin
  683. tcb.emit_ord_const(min,u64inttype);
  684. tcb.emit_ord_const(max,u64inttype);
  685. end;
  686. otSQWord:
  687. begin
  688. tcb.emit_ord_const(min,s64inttype);
  689. tcb.emit_ord_const(max,s64inttype);
  690. end;
  691. else
  692. begin
  693. tcb.emit_ord_const(longint(min),s32inttype);
  694. tcb.emit_ord_const(longint(max),s32inttype);
  695. end;
  696. end;
  697. tcb.end_anonymous_record;
  698. tcb.end_anonymous_record;
  699. end;
  700. procedure dointeger(typekind:byte);inline;
  701. begin
  702. doint32_64(typekind,int64(def.low.svalue),int64(def.high.svalue));
  703. end;
  704. begin
  705. case def.ordtype of
  706. s64bit :
  707. dointeger(tkInt64);
  708. u64bit :
  709. dointeger(tkQWord);
  710. pasbool8,
  711. pasbool16,
  712. pasbool32,
  713. pasbool64:
  714. dointeger(tkBool);
  715. { use different low/high values to be Delphi compatible }
  716. bool8bit,
  717. bool16bit,
  718. bool32bit:
  719. doint32_64(tkBool,longint(low(longint)),longint(high(longint)));
  720. bool64bit:
  721. doint32_64(tkBool,low(int64),high(int64));
  722. uchar:
  723. dointeger(tkChar);
  724. uwidechar:
  725. dointeger(tkWChar);
  726. scurrency:
  727. begin
  728. write_header(tcb,def,tkFloat);
  729. tcb.begin_anonymous_record(
  730. internaltypeprefixName[itp_1byte],
  731. defaultpacking,reqalign,
  732. targetinfos[target_info.system]^.alignment.recordalignmin,
  733. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  734. tcb.emit_ord_const(ftCurr,u8inttype);
  735. tcb.end_anonymous_record;
  736. end;
  737. else
  738. dointeger(tkInteger);
  739. end;
  740. end;
  741. procedure floatdef_rtti(def:tfloatdef);
  742. const
  743. {tfloattype = (s32real,s64real,s80real,sc80real,s64bit,s128bit);}
  744. translate : array[tfloattype] of byte =
  745. (ftSingle,ftDouble,ftExtended,ftExtended,ftComp,ftCurr,ftFloat128);
  746. begin
  747. write_header(tcb,def,tkFloat);
  748. tcb.begin_anonymous_record(
  749. internaltypeprefixName[itp_1byte],
  750. defaultpacking,reqalign,
  751. targetinfos[target_info.system]^.alignment.recordalignmin,
  752. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  753. tcb.emit_ord_const(translate[def.floattype],u8inttype);
  754. tcb.end_anonymous_record;
  755. end;
  756. procedure setdef_rtti(def:tsetdef);
  757. begin
  758. write_header(tcb,def,tkSet);
  759. tcb.begin_anonymous_record(
  760. internaltypeprefixName[itp_1byte],
  761. defaultpacking,reqalign,
  762. targetinfos[target_info.system]^.alignment.recordalignmin,
  763. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  764. case def.size of
  765. 1:
  766. tcb.emit_ord_const(otUByte,u8inttype);
  767. 2:
  768. tcb.emit_ord_const(otUWord,u8inttype);
  769. 4:
  770. tcb.emit_ord_const(otULong,u8inttype);
  771. else
  772. tcb.emit_ord_const(otUByte,u8inttype);
  773. end;
  774. tcb.end_anonymous_record;
  775. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  776. targetinfos[target_info.system]^.alignment.recordalignmin,
  777. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  778. write_rtti_reference(tcb,def.elementdef,rt);
  779. tcb.end_anonymous_record;
  780. end;
  781. procedure arraydef_rtti(def:tarraydef);
  782. var
  783. i,dimcount: byte;
  784. totalcount: asizeuint;
  785. finaldef: tdef;
  786. curdef:tarraydef;
  787. begin
  788. if ado_IsDynamicArray in def.arrayoptions then
  789. tcb.emit_ord_const(tkDynArray,u8inttype)
  790. else
  791. tcb.emit_ord_const(tkArray,u8inttype);
  792. write_rtti_name(tcb,def);
  793. if not(ado_IsDynamicArray in def.arrayoptions) then
  794. begin
  795. { remember tha last instruction. we will need to insert some
  796. calculated values after it }
  797. finaldef:=def;
  798. totalcount:=1;
  799. dimcount:=0;
  800. repeat
  801. curdef:=tarraydef(finaldef);
  802. finaldef:=curdef.elementdef;
  803. { Dims[i] PTypeInfo }
  804. inc(dimcount);
  805. totalcount:=totalcount*curdef.elecount;
  806. until (finaldef.typ<>arraydef) or
  807. (ado_IsDynamicArray in tarraydef(finaldef).arrayoptions);
  808. tcb.begin_anonymous_record(
  809. internaltypeprefixName[itp_rtti_normal_array]+tostr(dimcount),
  810. defaultpacking,reqalign,
  811. targetinfos[target_info.system]^.alignment.recordalignmin,
  812. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  813. { total size = elecount * elesize of the first arraydef }
  814. tcb.emit_tai(Tai_const.Create_sizeint(def.elecount*def.elesize),sizeuinttype);
  815. { total element count }
  816. tcb.emit_tai(Tai_const.Create_sizeint(asizeint(totalcount)),sizeuinttype);
  817. { last dimension element type }
  818. tcb.emit_tai(Tai_const.Create_sym(ref_rtti(curdef.elementdef,rt,true)),voidpointertype);
  819. { dimension count }
  820. tcb.emit_ord_const(dimcount,u8inttype);
  821. finaldef:=def;
  822. { ranges of the dimensions }
  823. for i:=1 to dimcount do
  824. begin
  825. curdef:=tarraydef(finaldef);
  826. finaldef:=curdef.elementdef;
  827. { Dims[i] PPTypeInfo }
  828. write_rtti_reference(tcb,curdef.rangedef,rt);
  829. end;
  830. end
  831. else
  832. { write a delphi almost compatible dyn. array entry:
  833. there are two types, eltype and eltype2, the latter is nil if the element type needs
  834. no finalization, the former is always valid, delphi has this swapped, but for
  835. compatibility with older fpc versions we do it different, to be delphi compatible,
  836. the names are swapped in typinfo.pp
  837. }
  838. begin
  839. tcb.begin_anonymous_record(
  840. internaltypeprefixName[itp_rtti_dyn_array],
  841. defaultpacking,reqalign,
  842. targetinfos[target_info.system]^.alignment.recordalignmin,
  843. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  844. { size of elements }
  845. tcb.emit_tai(Tai_const.Create_sizeint(def.elesize),sizeuinttype);
  846. { element type }
  847. write_rtti_reference(tcb,def.elementdef,rt);
  848. { variant type }
  849. tcb.emit_ord_const(tstoreddef(def.elementdef).getvardef,s32inttype);
  850. { element type }
  851. if def.elementdef.needs_inittable then
  852. write_rtti_reference(tcb,def.elementdef,rt)
  853. else
  854. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype);
  855. { write unit name }
  856. tcb.emit_shortstring_const(current_module.realmodulename^);
  857. end;
  858. tcb.end_anonymous_record;
  859. end;
  860. procedure classrefdef_rtti(def:tclassrefdef);
  861. begin
  862. write_header(tcb,def,tkClassRef);
  863. tcb.begin_anonymous_record(
  864. '',
  865. defaultpacking,reqalign,
  866. targetinfos[target_info.system]^.alignment.recordalignmin,
  867. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  868. write_rtti_reference(tcb,def.pointeddef,rt);
  869. tcb.end_anonymous_record;
  870. end;
  871. procedure pointerdef_rtti(def:tpointerdef);
  872. begin
  873. write_header(tcb,def,tkPointer);
  874. tcb.begin_anonymous_record(
  875. '',
  876. defaultpacking,reqalign,
  877. targetinfos[target_info.system]^.alignment.recordalignmin,
  878. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  879. write_rtti_reference(tcb,def.pointeddef,rt);
  880. tcb.end_anonymous_record;
  881. end;
  882. procedure recorddef_rtti(def:trecorddef);
  883. begin
  884. write_header(tcb,def,tkRecord);
  885. { need extra reqalign record, because otherwise the u32 int will
  886. only be aligned to 4 even on 64 bit target (while the rtti code
  887. in typinfo expects alignments to sizeof(pointer)) }
  888. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  889. targetinfos[target_info.system]^.alignment.recordalignmin,
  890. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  891. { store special terminator for init table for more optimal rtl operations
  892. strictly related to RecordRTTI procedure in rtti.inc (directly
  893. related to RTTIRecordRttiInfoToInitInfo function) }
  894. if (rt=initrtti) then
  895. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype)
  896. else
  897. begin
  898. { point to more optimal init table }
  899. include(def.defstates,ds_init_table_used);
  900. { we use a direct reference as the init RTTI is always in the same
  901. unit as the full RTTI }
  902. tcb.emit_tai(Tai_const.Create_sym(ref_rtti(def,initrtti,false)),voidpointertype);
  903. end;
  904. tcb.emit_ord_const(def.size,u32inttype);
  905. fields_write_rtti_data(tcb,def,rt);
  906. tcb.end_anonymous_record;
  907. { guarantee initrtti for any record for fpc_initialize, fpc_finalize }
  908. if (rt=fullrtti) and
  909. (ds_init_table_used in def.defstates) and
  910. not (ds_init_table_written in def.defstates)
  911. then
  912. write_rtti(def, initrtti);
  913. end;
  914. procedure procvardef_rtti(def:tprocvardef);
  915. procedure write_param_flag(parasym:tparavarsym);
  916. var
  917. paraspec : byte;
  918. begin
  919. case parasym.varspez of
  920. vs_value : paraspec := 0;
  921. vs_const : paraspec := pfConst;
  922. vs_var : paraspec := pfVar;
  923. vs_out : paraspec := pfOut;
  924. vs_constref: paraspec := pfConstRef;
  925. else
  926. internalerror(2013112904);
  927. end;
  928. { Kylix also seems to always add both pfArray and pfReference
  929. in this case
  930. }
  931. if is_open_array(parasym.vardef) then
  932. paraspec:=paraspec or pfArray or pfReference;
  933. { and these for classes and interfaces (maybe because they
  934. are themselves addresses?)
  935. }
  936. if is_class_or_interface(parasym.vardef) then
  937. paraspec:=paraspec or pfAddress;
  938. { set bits run from the highest to the lowest bit on
  939. big endian systems
  940. }
  941. if (target_info.endian = endian_big) then
  942. paraspec:=reverse_byte(paraspec);
  943. { write flags for current parameter }
  944. tcb.emit_ord_const(paraspec,u8inttype);
  945. end;
  946. procedure write_para(parasym:tparavarsym);
  947. begin
  948. { only store user visible parameters }
  949. if not(vo_is_hidden_para in parasym.varoptions) then
  950. begin
  951. { write flags for current parameter }
  952. write_param_flag(parasym);
  953. { write name of current parameter }
  954. tcb.emit_shortstring_const(parasym.realname);
  955. { write name of type of current parameter }
  956. write_rtti_name(tcb,parasym.vardef);
  957. end;
  958. end;
  959. procedure write_procedure_param(parasym:tparavarsym);
  960. begin
  961. { only store user visible parameters }
  962. if not(vo_is_hidden_para in parasym.varoptions) then
  963. begin
  964. { every parameter is expected to start aligned }
  965. tcb.begin_anonymous_record(
  966. internaltypeprefixName[itp_rtti_proc_param]+tostr(length(parasym.realname)),
  967. defaultpacking,min(reqalign,SizeOf(PtrInt)),
  968. targetinfos[target_info.system]^.alignment.recordalignmin,
  969. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  970. { write flags for current parameter }
  971. write_param_flag(parasym);
  972. { write param type }
  973. write_rtti_reference(tcb,parasym.vardef,fullrtti);
  974. { write name of current parameter }
  975. tcb.emit_shortstring_const(parasym.realname);
  976. tcb.end_anonymous_record;
  977. end;
  978. end;
  979. var
  980. methodkind : byte;
  981. i : integer;
  982. begin
  983. if po_methodpointer in def.procoptions then
  984. begin
  985. { write method id and name }
  986. write_header(tcb,def,tkMethod);
  987. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  988. targetinfos[target_info.system]^.alignment.recordalignmin,
  989. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  990. { write kind of method }
  991. methodkind:=write_methodkind(tcb,def);
  992. { write parameter info. The parameters must be written in reverse order
  993. if this method uses right to left parameter pushing! }
  994. tcb.emit_ord_const(def.maxparacount,u8inttype);
  995. for i:=0 to def.paras.count-1 do
  996. write_para(tparavarsym(def.paras[i]));
  997. if (methodkind=mkFunction) or (methodkind=mkClassFunction) then
  998. begin
  999. { write name of result type }
  1000. write_rtti_name(tcb,def.returndef);
  1001. { enclosing record takes care of alignment }
  1002. { write result typeinfo }
  1003. write_rtti_reference(tcb,def.returndef,fullrtti);
  1004. end;
  1005. { write calling convention }
  1006. write_callconv(tcb,def);
  1007. { enclosing record takes care of alignment }
  1008. { write params typeinfo }
  1009. for i:=0 to def.paras.count-1 do
  1010. if not(vo_is_hidden_para in tparavarsym(def.paras[i]).varoptions) then
  1011. write_rtti_reference(tcb,tparavarsym(def.paras[i]).vardef,fullrtti);
  1012. tcb.end_anonymous_record;
  1013. end
  1014. else
  1015. begin
  1016. write_header(tcb,def,tkProcvar);
  1017. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1018. targetinfos[target_info.system]^.alignment.recordalignmin,
  1019. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1020. { flags }
  1021. tcb.emit_ord_const(0,u8inttype);
  1022. { write calling convention }
  1023. write_callconv(tcb,def);
  1024. { enclosing record takes care of alignment }
  1025. { write result typeinfo }
  1026. write_rtti_reference(tcb,def.returndef,fullrtti);
  1027. { write parameter count }
  1028. tcb.emit_ord_const(def.maxparacount,u8inttype);
  1029. for i:=0 to def.paras.count-1 do
  1030. write_procedure_param(tparavarsym(def.paras[i]));
  1031. tcb.end_anonymous_record;
  1032. end;
  1033. end;
  1034. procedure objectdef_rtti(def: tobjectdef);
  1035. procedure objectdef_rtti_fields(def:tobjectdef);
  1036. begin
  1037. { - for compatiblity with record RTTI we need to write a terminator-
  1038. Nil pointer as well for objects
  1039. - classes are assumed to have the same INIT RTTI as records
  1040. (see TObject.CleanupInstance) }
  1041. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype);
  1042. tcb.emit_ord_const(def.size, u32inttype);
  1043. { enclosing record takes care of alignment }
  1044. fields_write_rtti_data(tcb,def,rt);
  1045. end;
  1046. procedure objectdef_rtti_interface_init(def:tobjectdef);
  1047. begin
  1048. tcb.emit_ord_const(def.size, u32inttype);
  1049. end;
  1050. procedure objectdef_rtti_class_full(def:tobjectdef);
  1051. var
  1052. propnamelist : TFPHashObjectList;
  1053. begin
  1054. { Collect unique property names with nameindex }
  1055. propnamelist:=TFPHashObjectList.Create;
  1056. collect_propnamelist(propnamelist,def);
  1057. if not is_objectpascal_helper(def) then
  1058. if (oo_has_vmt in def.objectoptions) then
  1059. tcb.emit_tai(
  1060. Tai_const.Createname(def.vmt_mangledname,AT_DATA_FORCEINDIRECT,0),
  1061. cpointerdef.getreusable(def.vmt_def))
  1062. else
  1063. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype);
  1064. { write parent typeinfo }
  1065. write_rtti_reference(tcb,def.childof,fullrtti);
  1066. { write typeinfo of extended type }
  1067. if is_objectpascal_helper(def) then
  1068. if assigned(def.extendeddef) then
  1069. write_rtti_reference(tcb,def.extendeddef,fullrtti)
  1070. else
  1071. InternalError(2011033001);
  1072. { total number of unique properties }
  1073. tcb.emit_ord_const(propnamelist.count,u16inttype);
  1074. { write unit name }
  1075. tcb.emit_shortstring_const(current_module.realmodulename^);
  1076. { write published properties for this object }
  1077. published_properties_write_rtti_data(tcb,propnamelist,def.symtable);
  1078. propnamelist.free;
  1079. end;
  1080. procedure objectdef_rtti_interface_full(def:tobjectdef);
  1081. var
  1082. propnamelist : TFPHashObjectList;
  1083. { if changed to a set, make sure it's still a byte large, and
  1084. swap appropriately when cross-compiling
  1085. }
  1086. IntfFlags: byte;
  1087. begin
  1088. { Collect unique property names with nameindex }
  1089. propnamelist:=TFPHashObjectList.Create;
  1090. collect_propnamelist(propnamelist,def);
  1091. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1092. targetinfos[target_info.system]^.alignment.recordalignmin,
  1093. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1094. { write parent typeinfo }
  1095. write_rtti_reference(tcb,def.childof,fullrtti);
  1096. { interface: write flags, iid and iidstr }
  1097. IntfFlags:=0;
  1098. if assigned(def.iidguid) then
  1099. IntfFlags:=IntfFlags or (1 shl ord(ifHasGuid));
  1100. if (def.objecttype=odt_interfacecorba) and (def.iidstr^<>'') then
  1101. IntfFlags:=IntfFlags or (1 shl ord(ifHasStrGUID));
  1102. if (def.objecttype=odt_dispinterface) then
  1103. IntfFlags:=IntfFlags or (1 shl ord(ifDispInterface));
  1104. if (target_info.endian=endian_big) then
  1105. IntfFlags:=reverse_byte(IntfFlags);
  1106. {
  1107. ifDispatch, }
  1108. tcb.emit_ord_const(IntfFlags,u8inttype);
  1109. { write GUID }
  1110. tcb.emit_guid_const(def.iidguid^);
  1111. { write unit name }
  1112. tcb.emit_shortstring_const(current_module.realmodulename^);
  1113. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1114. targetinfos[target_info.system]^.alignment.recordalignmin,
  1115. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1116. { write iidstr }
  1117. if def.objecttype=odt_interfacecorba then
  1118. begin
  1119. { prepareguid always allocates an empty string }
  1120. if not assigned(def.iidstr) then
  1121. internalerror(2016021901);
  1122. tcb.emit_shortstring_const(def.iidstr^)
  1123. end;
  1124. { write published properties for this object }
  1125. published_properties_write_rtti_data(tcb,propnamelist,def.symtable);
  1126. tcb.end_anonymous_record;
  1127. tcb.end_anonymous_record;
  1128. propnamelist.free;
  1129. end;
  1130. begin
  1131. case def.objecttype of
  1132. odt_class:
  1133. tcb.emit_ord_const(tkclass,u8inttype);
  1134. odt_object:
  1135. tcb.emit_ord_const(tkobject,u8inttype);
  1136. odt_dispinterface,
  1137. odt_interfacecom:
  1138. tcb.emit_ord_const(tkInterface,u8inttype);
  1139. odt_interfacecorba:
  1140. tcb.emit_ord_const(tkinterfaceCorba,u8inttype);
  1141. odt_helper:
  1142. tcb.emit_ord_const(tkhelper,u8inttype);
  1143. else
  1144. internalerror(200611034);
  1145. end;
  1146. { generate the name }
  1147. tcb.emit_shortstring_const(def.objrealname^);
  1148. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1149. targetinfos[target_info.system]^.alignment.recordalignmin,
  1150. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1151. case rt of
  1152. initrtti :
  1153. begin
  1154. if def.objecttype in [odt_class,odt_object,odt_helper] then
  1155. objectdef_rtti_fields(def)
  1156. else
  1157. objectdef_rtti_interface_init(def);
  1158. end;
  1159. fullrtti :
  1160. begin
  1161. case def.objecttype of
  1162. odt_helper,
  1163. odt_class:
  1164. objectdef_rtti_class_full(def);
  1165. odt_object:
  1166. objectdef_rtti_fields(def);
  1167. else
  1168. objectdef_rtti_interface_full(def);
  1169. end;
  1170. end;
  1171. end;
  1172. tcb.end_anonymous_record;
  1173. end;
  1174. begin
  1175. case def.typ of
  1176. variantdef :
  1177. variantdef_rtti(tvariantdef(def));
  1178. stringdef :
  1179. stringdef_rtti(tstringdef(def));
  1180. enumdef :
  1181. enumdef_rtti(tenumdef(def));
  1182. orddef :
  1183. orddef_rtti(torddef(def));
  1184. floatdef :
  1185. floatdef_rtti(tfloatdef(def));
  1186. setdef :
  1187. setdef_rtti(tsetdef(def));
  1188. procvardef :
  1189. procvardef_rtti(tprocvardef(def));
  1190. arraydef :
  1191. begin
  1192. if ado_IsBitPacked in tarraydef(def).arrayoptions then
  1193. unknown_rtti(tstoreddef(def))
  1194. else
  1195. arraydef_rtti(tarraydef(def));
  1196. end;
  1197. recorddef :
  1198. begin
  1199. if trecorddef(def).is_packed then
  1200. unknown_rtti(tstoreddef(def))
  1201. else
  1202. recorddef_rtti(trecorddef(def));
  1203. end;
  1204. objectdef :
  1205. objectdef_rtti(tobjectdef(def));
  1206. classrefdef :
  1207. classrefdef_rtti(tclassrefdef(def));
  1208. pointerdef :
  1209. pointerdef_rtti(tpointerdef(def));
  1210. else
  1211. unknown_rtti(tstoreddef(def));
  1212. end;
  1213. end;
  1214. function enumsym_compare_name(item1, item2: pointer): Integer;
  1215. var
  1216. enum1: tenumsym absolute item1;
  1217. enum2: tenumsym absolute item2;
  1218. begin
  1219. if enum1=enum2 then
  1220. result:=0
  1221. else if enum1.name>enum2.name then
  1222. result:=1
  1223. else
  1224. { there can't be equal names, identifiers are unique }
  1225. result:=-1;
  1226. end;
  1227. function enumsym_compare_value(item1, item2: pointer): Integer;
  1228. var
  1229. enum1: tenumsym absolute item1;
  1230. enum2: tenumsym absolute item2;
  1231. begin
  1232. if enum1.value>enum2.value then
  1233. result:=1
  1234. else if enum1.value<enum2.value then
  1235. result:=-1
  1236. else
  1237. result:=0;
  1238. end;
  1239. procedure TRTTIWriter.write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  1240. type Penumsym = ^Tenumsym;
  1241. { Writes a helper table for accelerated conversion of ordinal enum values to strings.
  1242. If you change something in this method, make sure to adapt the corresponding code
  1243. in sstrings.inc. }
  1244. procedure enumdef_rtti_ord2stringindex(rttidef: trecorddef; const syms: tfplist);
  1245. var rttilab:Tasmsymbol;
  1246. h,i,o,prev_value:longint;
  1247. mode:(lookup,search); {Modify with care, ordinal value of enum is written.}
  1248. r:single; {Must be real type because of integer overflow risk.}
  1249. tcb: ttai_typedconstbuilder;
  1250. sym_count: integer;
  1251. tabledef: tdef;
  1252. begin
  1253. {Decide wether a lookup array is size efficient.}
  1254. mode:=lookup;
  1255. sym_count:=syms.count;
  1256. if sym_count>0 then
  1257. begin
  1258. i:=1;
  1259. r:=0;
  1260. h:=tenumsym(syms[0]).value; {Next expected enum value is min.}
  1261. { set prev_value for the first iteration to a value that is
  1262. different from the first one without risking overflow (it's used
  1263. to detect whether two enum values are the same) }
  1264. if h=0 then
  1265. prev_value:=1
  1266. else
  1267. prev_value:=0;
  1268. while i<sym_count do
  1269. begin
  1270. { if two enum values are the same, we have to create a table }
  1271. if (prev_value=h) then
  1272. begin
  1273. mode:=search;
  1274. break;
  1275. end;
  1276. {Calculate size of hole between values. Avoid integer overflows.}
  1277. r:=r+(single(tenumsym(syms[i]).value)-single(h))-1;
  1278. prev_value:=h;
  1279. h:=tenumsym(syms[i]).value;
  1280. inc(i);
  1281. end;
  1282. if r>sym_count then
  1283. mode:=search; {Don't waste more than 50% space.}
  1284. end;
  1285. { write rtti data; make sure that the alignment matches the corresponding data structure
  1286. in the code that uses it (if alignment is required). }
  1287. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1288. { use TConstPtrUInt packrecords to ensure good alignment }
  1289. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1290. targetinfos[target_info.system]^.alignment.recordalignmin,
  1291. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1292. { now emit the data: first the mode }
  1293. tcb.emit_tai(Tai_const.create_32bit(longint(mode)),u32inttype);
  1294. { align }
  1295. tcb.begin_anonymous_record('',defaultpacking,min(reqalign,sizeof(pointer)),
  1296. targetinfos[target_info.system]^.alignment.recordalignmin,
  1297. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1298. if mode=lookup then
  1299. begin
  1300. o:=tenumsym(syms[0]).value; {Start with min value.}
  1301. for i:=0 to sym_count-1 do
  1302. begin
  1303. while o<tenumsym(syms[i]).value do
  1304. begin
  1305. tcb.emit_tai(Tai_const.create_nil_dataptr,ptruinttype);
  1306. inc(o);
  1307. end;
  1308. inc(o);
  1309. tcb.queue_init(voidpointertype);
  1310. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1311. ['size_start_rec',
  1312. 'min_max_rec',
  1313. 'basetype_array_rec',
  1314. tsym(syms[i]).Name]
  1315. );
  1316. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1317. end;
  1318. end
  1319. else
  1320. begin
  1321. tcb.emit_ord_const(sym_count,u32inttype);
  1322. tcb.begin_anonymous_record('',defaultpacking,min(reqalign,sizeof(pointer)),
  1323. targetinfos[target_info.system]^.alignment.recordalignmin,
  1324. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1325. for i:=0 to sym_count-1 do
  1326. begin
  1327. tcb.emit_ord_const(tenumsym(syms[i]).value,s32inttype);
  1328. tcb.queue_init(voidpointertype);
  1329. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1330. ['size_start_rec',
  1331. 'min_max_rec',
  1332. 'basetype_array_rec',
  1333. tsym(syms[i]).Name]
  1334. );
  1335. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1336. end;
  1337. tcb.end_anonymous_record;
  1338. end;
  1339. tcb.end_anonymous_record;
  1340. tabledef:=tcb.end_anonymous_record;
  1341. rttilab:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_o2s',AB_GLOBAL,AT_DATA_FORCEINDIRECT,tabledef);
  1342. current_asmdata.asmlists[al_rtti].concatlist(tcb.get_final_asmlist(
  1343. rttilab,tabledef,sec_rodata,
  1344. rttilab.name,sizeof(pint)));
  1345. tcb.free;
  1346. current_module.add_public_asmsym(rttilab);
  1347. end;
  1348. { Writes a helper table for accelerated conversion of string to ordinal enum values.
  1349. If you change something in this method, make sure to adapt the corresponding code
  1350. in sstrings.inc. }
  1351. procedure enumdef_rtti_string2ordindex(rttidef: trecorddef; const syms: tfplist);
  1352. var
  1353. tcb: ttai_typedconstbuilder;
  1354. rttilab: Tasmsymbol;
  1355. i:longint;
  1356. tabledef: tdef;
  1357. begin
  1358. { write rtti data }
  1359. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1360. { begin of Tstring_to_ord }
  1361. tcb.begin_anonymous_record('',defaultpacking,min(reqalign,sizeof(pointer)),
  1362. targetinfos[target_info.system]^.alignment.recordalignmin,
  1363. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1364. tcb.emit_ord_const(syms.count,s32inttype);
  1365. { begin of "data" array in Tstring_to_ord }
  1366. tcb.begin_anonymous_record('',defaultpacking,min(reqalign,sizeof(pointer)),
  1367. targetinfos[target_info.system]^.alignment.recordalignmin,
  1368. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1369. for i:=0 to syms.count-1 do
  1370. begin
  1371. tcb.emit_ord_const(tenumsym(syms[i]).value,s32inttype);
  1372. { alignment of pointer value handled by enclosing record already }
  1373. tcb.queue_init(voidpointertype);
  1374. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1375. ['size_start_rec',
  1376. 'min_max_rec',
  1377. 'basetype_array_rec',
  1378. tsym(syms[i]).Name]
  1379. );
  1380. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1381. end;
  1382. tcb.end_anonymous_record;
  1383. tabledef:=tcb.end_anonymous_record;
  1384. rttilab:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_s2o',AB_GLOBAL,AT_DATA_FORCEINDIRECT,tabledef);
  1385. current_asmdata.asmlists[al_rtti].concatlist(tcb.get_final_asmlist(
  1386. rttilab,tabledef,sec_rodata,
  1387. rttilab.name,sizeof(pint)));
  1388. tcb.free;
  1389. current_module.add_public_asmsym(rttilab);
  1390. end;
  1391. procedure enumdef_rtti_extrasyms(def:Tenumdef);
  1392. var
  1393. t:Tenumsym;
  1394. syms:tfplist;
  1395. i:longint;
  1396. rttitypesym: ttypesym;
  1397. rttidef: trecorddef;
  1398. begin
  1399. { collect enumsyms belonging to this enum type (could be a subsection
  1400. in case of a subrange type) }
  1401. syms:=tfplist.create;
  1402. for i := 0 to def.symtable.SymList.Count - 1 do
  1403. begin
  1404. t:=tenumsym(def.symtable.SymList[i]);
  1405. if t.value<def.minval then
  1406. continue
  1407. else
  1408. if t.value>def.maxval then
  1409. break;
  1410. syms.add(t);
  1411. end;
  1412. { sort the syms by enum name }
  1413. syms.sort(@enumsym_compare_name);
  1414. rttitypesym:=try_search_current_module_type(internaltypeprefixName[itp_rttidef]+def.rtti_mangledname(fullrtti));
  1415. if not assigned(rttitypesym) or
  1416. (ttypesym(rttitypesym).typedef.typ<>recorddef) then
  1417. internalerror(2015071402);
  1418. rttidef:=trecorddef(ttypesym(rttitypesym).typedef);
  1419. enumdef_rtti_string2ordindex(rttidef,syms);
  1420. { sort the syms by enum value }
  1421. syms.sort(@enumsym_compare_value);
  1422. enumdef_rtti_ord2stringindex(rttidef,syms);
  1423. syms.free;
  1424. end;
  1425. begin
  1426. case def.typ of
  1427. enumdef:
  1428. if rt=fullrtti then
  1429. begin
  1430. enumdef_rtti_extrasyms(Tenumdef(def));
  1431. end;
  1432. end;
  1433. end;
  1434. procedure TRTTIWriter.write_child_rtti_data(def:tdef;rt:trttitype);
  1435. begin
  1436. case def.typ of
  1437. enumdef :
  1438. if assigned(tenumdef(def).basedef) then
  1439. write_rtti(tenumdef(def).basedef,rt);
  1440. setdef :
  1441. write_rtti(tsetdef(def).elementdef,rt);
  1442. arraydef :
  1443. begin
  1444. write_rtti(tarraydef(def).rangedef,rt);
  1445. write_rtti(tarraydef(def).elementdef,rt);
  1446. end;
  1447. recorddef :
  1448. fields_write_rtti(trecorddef(def).symtable,rt);
  1449. objectdef :
  1450. begin
  1451. if assigned(tobjectdef(def).childof) then
  1452. write_rtti(tobjectdef(def).childof,rt);
  1453. if (rt=initrtti) or (tobjectdef(def).objecttype=odt_object) then
  1454. fields_write_rtti(tobjectdef(def).symtable,rt)
  1455. else
  1456. published_write_rtti(tobjectdef(def).symtable,rt);
  1457. end;
  1458. classrefdef,
  1459. pointerdef:
  1460. if not is_objc_class_or_protocol(tabstractpointerdef(def).pointeddef) then
  1461. write_rtti(tabstractpointerdef(def).pointeddef,rt);
  1462. procvardef:
  1463. params_write_rtti(tabstractprocdef(def),rt);
  1464. end;
  1465. end;
  1466. procedure TRTTIWriter.write_rtti_reference(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  1467. begin
  1468. { we don't care about the real type here, because
  1469. a) we don't index into these elements
  1470. b) we may not have the rtti type available at the point that we
  1471. are emitting this data, because of forward definitions etc
  1472. c) if the rtti is emitted in another unit, we won't have the type
  1473. available at all
  1474. For the cases where the type is emitted in the current unit and hence
  1475. the underlying system will detect and complain about symbol def
  1476. mismatches, type conversions will have to be inserted afterwards (like
  1477. in llvm/llvmtype)
  1478. }
  1479. if not assigned(def) or is_void(def) or ((rt<>initrtti) and is_objc_class_or_protocol(def)) then
  1480. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype)
  1481. else
  1482. tcb.emit_tai(Tai_const.Create_sym(ref_rtti(def,rt,true)),voidpointertype);
  1483. end;
  1484. function TRTTIWriter.ref_rtti(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  1485. var
  1486. s : TSymStr;
  1487. begin
  1488. s:=def.rtti_mangledname(rt);
  1489. result:=current_asmdata.RefAsmSymbol(s,AT_DATA,indirect);
  1490. if (cs_create_pic in current_settings.moduleswitches) and
  1491. assigned(current_procinfo) then
  1492. include(current_procinfo.flags,pi_needs_got);
  1493. if def.owner.moduleid<>current_module.moduleid then
  1494. current_module.add_extern_asmsym(s,AB_EXTERNAL,AT_DATA);
  1495. end;
  1496. procedure TRTTIWriter.write_rtti(def:tdef;rt:trttitype);
  1497. var
  1498. tcb: ttai_typedconstbuilder;
  1499. rttilab: tasmsymbol;
  1500. rttidef: tdef;
  1501. begin
  1502. { only write rtti of definitions from the current module }
  1503. if not findunitsymtable(def.owner).iscurrentunit then
  1504. exit;
  1505. { check if separate initrtti is actually needed }
  1506. if (rt=initrtti) and (not def.needs_separate_initrtti) then
  1507. rt:=fullrtti;
  1508. { prevent recursion }
  1509. if rttidefstate[rt] in def.defstates then
  1510. exit;
  1511. include(def.defstates,rttidefstate[rt]);
  1512. { write first all dependencies }
  1513. write_child_rtti_data(def,rt);
  1514. { write rtti data }
  1515. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1516. tcb.begin_anonymous_record(
  1517. internaltypeprefixName[itp_rttidef]+tstoreddef(def).rtti_mangledname(rt),
  1518. defaultpacking,reqalign,
  1519. targetinfos[target_info.system]^.alignment.recordalignmin,
  1520. targetinfos[target_info.system]^.alignment.maxCrecordalign
  1521. );
  1522. write_rtti_data(tcb,def,rt);
  1523. rttidef:=tcb.end_anonymous_record;
  1524. rttilab:=current_asmdata.DefineAsmSymbol(tstoreddef(def).rtti_mangledname(rt),AB_GLOBAL,AT_DATA_FORCEINDIRECT,rttidef);
  1525. current_asmdata.AsmLists[al_rtti].concatList(
  1526. tcb.get_final_asmlist(rttilab,rttidef,sec_rodata,rttilab.name,min(target_info.alignment.maxCrecordalign,SizeOf(QWord))));
  1527. tcb.free;
  1528. current_module.add_public_asmsym(rttilab);
  1529. { write additional data }
  1530. write_rtti_extrasyms(def,rt,rttilab);
  1531. end;
  1532. constructor TRTTIWriter.create;
  1533. begin
  1534. if tf_requires_proper_alignment in target_info.flags then
  1535. begin
  1536. reqalign:=min(sizeof(qword),target_info.alignment.maxCrecordalign);
  1537. defaultpacking:=C_alignment;
  1538. end
  1539. else
  1540. begin
  1541. reqalign:=1;
  1542. defaultpacking:=1;
  1543. end;
  1544. end;
  1545. function TRTTIWriter.get_rtti_label(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  1546. var
  1547. name : tsymstr;
  1548. begin
  1549. name:=def.rtti_mangledname(rt);
  1550. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,indirect);
  1551. if (cs_create_pic in current_settings.moduleswitches) and
  1552. assigned(current_procinfo) then
  1553. include(current_procinfo.flags,pi_needs_got);
  1554. if assigned(current_module) and (findunitsymtable(def.owner).moduleid<>current_module.moduleid) then
  1555. current_module.add_extern_asmsym(name,AB_EXTERNAL,AT_DATA);
  1556. end;
  1557. function TRTTIWriter.get_rtti_label_ord2str(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  1558. var
  1559. name : tsymstr;
  1560. begin
  1561. name:=def.rtti_mangledname(rt)+'_o2s';
  1562. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,indirect);
  1563. if (cs_create_pic in current_settings.moduleswitches) and
  1564. assigned(current_procinfo) then
  1565. include(current_procinfo.flags,pi_needs_got);
  1566. if assigned(current_module) and (findunitsymtable(def.owner).moduleid<>current_module.moduleid) then
  1567. current_module.add_extern_asmsym(name,AB_EXTERNAL,AT_DATA);
  1568. end;
  1569. function TRTTIWriter.get_rtti_label_str2ord(def:tdef;rt:trttitype;indirect:boolean):tasmsymbol;
  1570. var
  1571. name : tsymstr;
  1572. begin
  1573. name:=def.rtti_mangledname(rt)+'_s2o';
  1574. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,indirect);
  1575. if (cs_create_pic in current_settings.moduleswitches) and
  1576. assigned(current_procinfo) then
  1577. include(current_procinfo.flags,pi_needs_got);
  1578. if assigned(current_module) and (findunitsymtable(def.owner).moduleid<>current_module.moduleid) then
  1579. current_module.add_extern_asmsym(name,AB_EXTERNAL,AT_DATA);
  1580. end;
  1581. end.