ncgrtti.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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,
  22. aasmbase,
  23. symbase,symconst,symtype,symdef;
  24. type
  25. { TRTTIWriter }
  26. TRTTIWriter=class
  27. private
  28. function fields_count(st:tsymtable;rt:trttitype):longint;
  29. procedure fields_write_rtti(st:tsymtable;rt:trttitype);
  30. procedure fields_write_rtti_data(st:tsymtable;rt:trttitype);
  31. procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  32. procedure published_write_rtti(st:tsymtable;rt:trttitype);
  33. function published_properties_count(st:tsymtable):longint;
  34. procedure published_properties_write_rtti_data(propnamelist:TFPHashObjectList;st:tsymtable);
  35. procedure collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  36. procedure write_rtti_name(def:tdef);
  37. procedure write_rtti_data(def:tdef;rt:trttitype);
  38. procedure write_child_rtti_data(def:tdef;rt:trttitype);
  39. function ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  40. public
  41. procedure write_rtti(def:tdef;rt:trttitype);
  42. function get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  43. function get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  44. function get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  45. end;
  46. var
  47. RTTIWriter : TRTTIWriter;
  48. implementation
  49. uses
  50. cutils,
  51. globals,globtype,verbose,systems,
  52. fmodule,
  53. symsym,
  54. aasmtai,aasmdata
  55. ;
  56. const
  57. rttidefstate : array[trttitype] of tdefstate = (ds_rtti_table_written,ds_init_table_written);
  58. type
  59. TPropNameListItem = class(TFPHashObject)
  60. propindex : longint;
  61. propowner : TSymtable;
  62. end;
  63. {***************************************************************************
  64. TRTTIWriter
  65. ***************************************************************************}
  66. procedure TRTTIWriter.write_rtti_name(def:tdef);
  67. var
  68. hs : string;
  69. begin
  70. { name }
  71. if assigned(def.typesym) then
  72. begin
  73. hs:=ttypesym(def.typesym).realname;
  74. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(chr(length(hs))+hs));
  75. end
  76. else
  77. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0));
  78. end;
  79. function TRTTIWriter.fields_count(st:tsymtable;rt:trttitype):longint;
  80. var
  81. i : longint;
  82. sym : tsym;
  83. begin
  84. result:=0;
  85. for i:=0 to st.SymList.Count-1 do
  86. begin
  87. sym:=tsym(st.SymList[i]);
  88. if (rt=fullrtti) or
  89. (
  90. (tsym(sym).typ=fieldvarsym) and
  91. tfieldvarsym(sym).vardef.needs_inittable
  92. ) then
  93. inc(result);
  94. end;
  95. end;
  96. procedure TRTTIWriter.fields_write_rtti_data(st:tsymtable;rt:trttitype);
  97. var
  98. i : longint;
  99. sym : tsym;
  100. begin
  101. for i:=0 to st.SymList.Count-1 do
  102. begin
  103. sym:=tsym(st.SymList[i]);
  104. if (rt=fullrtti) or
  105. (
  106. (tsym(sym).typ=fieldvarsym) and
  107. tfieldvarsym(sym).vardef.needs_inittable
  108. ) then
  109. begin
  110. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tfieldvarsym(sym).vardef,rt)));
  111. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
  112. end;
  113. end;
  114. end;
  115. procedure TRTTIWriter.fields_write_rtti(st:tsymtable;rt:trttitype);
  116. var
  117. i : longint;
  118. sym : tsym;
  119. begin
  120. for i:=0 to st.SymList.Count-1 do
  121. begin
  122. sym:=tsym(st.SymList[i]);
  123. if (rt=fullrtti) or
  124. (
  125. (tsym(sym).typ=fieldvarsym) and
  126. tfieldvarsym(sym).vardef.needs_inittable
  127. ) then
  128. write_rtti(tfieldvarsym(sym).vardef,rt);
  129. end;
  130. end;
  131. procedure TRTTIWriter.published_write_rtti(st:tsymtable;rt:trttitype);
  132. var
  133. i : longint;
  134. sym : tsym;
  135. begin
  136. for i:=0 to st.SymList.Count-1 do
  137. begin
  138. sym:=tsym(st.SymList[i]);
  139. if (sp_published in tsym(sym).symoptions) then
  140. begin
  141. case tsym(sym).typ of
  142. propertysym:
  143. write_rtti(tpropertysym(sym).propdef,rt);
  144. fieldvarsym:
  145. write_rtti(tfieldvarsym(sym).vardef,rt);
  146. end;
  147. end;
  148. end;
  149. end;
  150. function TRTTIWriter.published_properties_count(st:tsymtable):longint;
  151. var
  152. i : longint;
  153. sym : tsym;
  154. begin
  155. result:=0;
  156. for i:=0 to st.SymList.Count-1 do
  157. begin
  158. sym:=tsym(st.SymList[i]);
  159. if (tsym(sym).typ=propertysym) and
  160. (sp_published in tsym(sym).symoptions) then
  161. inc(result);
  162. end;
  163. end;
  164. procedure TRTTIWriter.collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  165. var
  166. i : longint;
  167. sym : tsym;
  168. pn : tpropnamelistitem;
  169. begin
  170. if assigned(objdef.childof) then
  171. collect_propnamelist(propnamelist,objdef.childof);
  172. for i:=0 to objdef.symtable.SymList.Count-1 do
  173. begin
  174. sym:=tsym(objdef.symtable.SymList[i]);
  175. if (tsym(sym).typ=propertysym) and
  176. (sp_published in tsym(sym).symoptions) then
  177. begin
  178. pn:=TPropNameListItem(propnamelist.Find(tsym(sym).name));
  179. if not assigned(pn) then
  180. begin
  181. pn:=tpropnamelistitem.create(propnamelist,tsym(sym).name);
  182. pn.propindex:=propnamelist.count-1;
  183. pn.propowner:=tsym(sym).owner;
  184. end;
  185. end;
  186. end;
  187. end;
  188. procedure TRTTIWriter.published_properties_write_rtti_data(propnamelist:TFPHashObjectList;st:tsymtable);
  189. var
  190. i : longint;
  191. sym : tsym;
  192. proctypesinfo : byte;
  193. propnameitem : tpropnamelistitem;
  194. procedure writeaccessproc(pap:tpropaccesslisttypes; shiftvalue : byte; unsetvalue: byte);
  195. var
  196. typvalue : byte;
  197. hp : ppropaccesslistitem;
  198. address,space : longint;
  199. def : tdef;
  200. hpropsym : tpropertysym;
  201. propaccesslist : tpropaccesslist;
  202. begin
  203. hpropsym:=tpropertysym(sym);
  204. repeat
  205. propaccesslist:=hpropsym.propaccesslist[pap];
  206. if not propaccesslist.empty then
  207. break;
  208. hpropsym:=hpropsym.overridenpropsym;
  209. until not assigned(hpropsym);
  210. if not(assigned(propaccesslist) and assigned(propaccesslist.firstsym)) then
  211. begin
  212. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,unsetvalue));
  213. typvalue:=3;
  214. end
  215. else if propaccesslist.firstsym^.sym.typ=fieldvarsym then
  216. begin
  217. address:=0;
  218. hp:=propaccesslist.firstsym;
  219. def:=nil;
  220. while assigned(hp) do
  221. begin
  222. case hp^.sltype of
  223. sl_load :
  224. begin
  225. def:=tfieldvarsym(hp^.sym).vardef;
  226. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  227. end;
  228. sl_subscript :
  229. begin
  230. if not(assigned(def) and (def.typ=recorddef)) then
  231. internalerror(200402171);
  232. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  233. def:=tfieldvarsym(hp^.sym).vardef;
  234. end;
  235. sl_vec :
  236. begin
  237. if not(assigned(def) and (def.typ=arraydef)) then
  238. internalerror(200402172);
  239. def:=tarraydef(def).elementdef;
  240. {Hp.value is a Tconstexprint, which can be rather large,
  241. sanity check for longint overflow.}
  242. space:=(high(address)-address) div def.size;
  243. if int64(space)<hp^.value then
  244. internalerror(200706101);
  245. inc(address,int64(def.size*hp^.value));
  246. end;
  247. end;
  248. hp:=hp^.next;
  249. end;
  250. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,address));
  251. typvalue:=0;
  252. end
  253. else
  254. begin
  255. { When there was an error then procdef is not assigned }
  256. if not assigned(propaccesslist.procdef) then
  257. exit;
  258. if not(po_virtualmethod in tprocdef(propaccesslist.procdef).procoptions) then
  259. begin
  260. current_asmdata.asmlists[al_rtti].concat(Tai_const.createname(tprocdef(propaccesslist.procdef).mangledname,0));
  261. typvalue:=1;
  262. end
  263. else
  264. begin
  265. { virtual method, write vmt offset }
  266. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,
  267. tprocdef(propaccesslist.procdef)._class.vmtmethodoffset(tprocdef(propaccesslist.procdef).extnumber)));
  268. typvalue:=2;
  269. end;
  270. end;
  271. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  272. end;
  273. begin
  274. for i:=0 to st.SymList.Count-1 do
  275. begin
  276. sym:=tsym(st.SymList[i]);
  277. if (sym.typ=propertysym) and
  278. (sp_published in sym.symoptions) then
  279. begin
  280. if ppo_indexed in tpropertysym(sym).propoptions then
  281. proctypesinfo:=$40
  282. else
  283. proctypesinfo:=0;
  284. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tpropertysym(sym).propdef,fullrtti)));
  285. writeaccessproc(palt_read,0,0);
  286. writeaccessproc(palt_write,2,0);
  287. { is it stored ? }
  288. if not(ppo_stored in tpropertysym(sym).propoptions) then
  289. begin
  290. { no, so put a constant zero }
  291. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,0));
  292. proctypesinfo:=proctypesinfo or (3 shl 4);
  293. end
  294. else
  295. writeaccessproc(palt_stored,4,1); { maybe; if no procedure put a constant 1 (=true) }
  296. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  297. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  298. propnameitem:=TPropNameListItem(propnamelist.Find(tpropertysym(sym).name));
  299. if not assigned(propnameitem) then
  300. internalerror(200512201);
  301. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnameitem.propindex));
  302. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(proctypesinfo));
  303. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  304. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(tpropertysym(sym).realname));
  305. if (tf_requires_proper_alignment in target_info.flags) then
  306. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  307. end;
  308. end;
  309. end;
  310. procedure TRTTIWriter.write_rtti_data(def:tdef;rt:trttitype);
  311. procedure unknown_rtti(def:tstoreddef);
  312. begin
  313. current_asmdata.asmlists[al_rtti].concat(tai_const.create_8bit(tkUnknown));
  314. write_rtti_name(def);
  315. end;
  316. procedure variantdef_rtti(def:tvariantdef);
  317. begin
  318. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkVariant));
  319. end;
  320. procedure stringdef_rtti(def:tstringdef);
  321. begin
  322. case def.stringtype of
  323. st_ansistring:
  324. begin
  325. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkAString));
  326. write_rtti_name(def);
  327. end;
  328. st_widestring:
  329. begin
  330. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkWString));
  331. write_rtti_name(def);
  332. end;
  333. st_longstring:
  334. begin
  335. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkLString));
  336. write_rtti_name(def);
  337. end;
  338. st_shortstring:
  339. begin
  340. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkSString));
  341. write_rtti_name(def);
  342. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.len));
  343. if (tf_requires_proper_alignment in target_info.flags) then
  344. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  345. end;
  346. end;
  347. end;
  348. procedure enumdef_rtti(def:tenumdef);
  349. var
  350. hp : tenumsym;
  351. begin
  352. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkEnumeration));
  353. write_rtti_name(def);
  354. if (tf_requires_proper_alignment in target_info.flags) then
  355. current_asmdata.asmlists[al_rtti].concat(Cai_align.Create(sizeof(TConstPtrUInt)));
  356. case longint(def.size) of
  357. 1 :
  358. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  359. 2 :
  360. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
  361. 4 :
  362. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  363. end;
  364. if (tf_requires_proper_alignment in target_info.flags) then
  365. current_asmdata.asmlists[al_rtti].concat(Cai_align.Create(sizeof(TConstPtrUInt)));
  366. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.min));
  367. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.max));
  368. if assigned(def.basedef) then
  369. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.basedef,rt)))
  370. else
  371. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  372. hp:=tenumsym(def.firstenum);
  373. while assigned(hp) do
  374. begin
  375. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(hp.realname)));
  376. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(hp.realname));
  377. hp:=hp.nextenum;
  378. end;
  379. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  380. end;
  381. procedure orddef_rtti(def:torddef);
  382. procedure dointeger;
  383. const
  384. trans : array[tordtype] of byte =
  385. (otUByte{otNone},
  386. otUByte,otUWord,otULong,otUByte{otNone},
  387. otSByte,otSWord,otSLong,otUByte{otNone},
  388. otUByte,otUWord,otULong,otUByte,
  389. otUByte,otUWord,otUByte);
  390. begin
  391. write_rtti_name(def);
  392. if (tf_requires_proper_alignment in target_info.flags) then
  393. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  394. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(byte(trans[def.ordtype])));
  395. if (tf_requires_proper_alignment in target_info.flags) then
  396. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  397. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.low)));
  398. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.high)));
  399. end;
  400. begin
  401. case def.ordtype of
  402. s64bit :
  403. begin
  404. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkInt64));
  405. write_rtti_name(def);
  406. if (tf_requires_proper_alignment in target_info.flags) then
  407. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  408. { low }
  409. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  410. { high }
  411. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  412. end;
  413. u64bit :
  414. begin
  415. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkQWord));
  416. write_rtti_name(def);
  417. if (tf_requires_proper_alignment in target_info.flags) then
  418. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  419. { low }
  420. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(0));
  421. { high }
  422. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  423. end;
  424. bool8bit:
  425. begin
  426. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkBool));
  427. dointeger;
  428. end;
  429. uchar:
  430. begin
  431. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkChar));
  432. dointeger;
  433. end;
  434. uwidechar:
  435. begin
  436. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkWChar));
  437. dointeger;
  438. end;
  439. scurrency:
  440. begin
  441. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkFloat));
  442. write_rtti_name(def);
  443. if (tf_requires_proper_alignment in target_info.flags) then
  444. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  445. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(ftCurr));
  446. end;
  447. else
  448. begin
  449. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkInteger));
  450. dointeger;
  451. end;
  452. end;
  453. end;
  454. procedure floatdef_rtti(def:tfloatdef);
  455. const
  456. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  457. translate : array[tfloattype] of byte =
  458. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  459. begin
  460. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkFloat));
  461. write_rtti_name(def);
  462. if (tf_requires_proper_alignment in target_info.flags) then
  463. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  464. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(translate[def.floattype]));
  465. end;
  466. procedure setdef_rtti(def:tsetdef);
  467. begin
  468. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkSet));
  469. write_rtti_name(def);
  470. if (tf_requires_proper_alignment in target_info.flags) then
  471. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  472. case def.size of
  473. 1:
  474. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  475. 2:
  476. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
  477. 4:
  478. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  479. end;
  480. if (tf_requires_proper_alignment in target_info.flags) then
  481. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  482. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  483. end;
  484. procedure arraydef_rtti(def:tarraydef);
  485. begin
  486. if ado_IsDynamicArray in def.arrayoptions then
  487. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkdynarray))
  488. else
  489. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkarray));
  490. write_rtti_name(def);
  491. if (tf_requires_proper_alignment in target_info.flags) then
  492. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  493. { size of elements }
  494. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(def.elesize));
  495. if not(ado_IsDynamicArray in def.arrayoptions) then
  496. begin
  497. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(aint(def.elecount)));
  498. { element type }
  499. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  500. end
  501. else
  502. { write a delphi almost compatible dyn. array entry:
  503. there are two types, eltype and eltype2, the latter is nil if the element type needs
  504. no finalization, the former is always valid, delphi has this swapped, but for
  505. compatibility with older fpc versions we do it different, to be delphi compatible,
  506. the names are swapped in typinfo.pp
  507. }
  508. begin
  509. { element type }
  510. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  511. end;
  512. { variant type }
  513. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tstoreddef(def.elementdef).getvardef));
  514. if ado_IsDynamicArray in def.arrayoptions then
  515. begin
  516. { element type }
  517. if def.elementdef.needs_inittable then
  518. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)))
  519. else
  520. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(0));
  521. { dummy DynUnitName }
  522. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  523. end;
  524. end;
  525. procedure recorddef_rtti(def:trecorddef);
  526. var
  527. fieldcnt : longint;
  528. begin
  529. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkrecord));
  530. write_rtti_name(def);
  531. if (tf_requires_proper_alignment in target_info.flags) then
  532. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  533. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  534. fieldcnt:=fields_count(def.symtable,rt);
  535. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fieldcnt));
  536. fields_write_rtti_data(def.symtable,rt);
  537. end;
  538. procedure procvardef_rtti(def:tprocvardef);
  539. procedure write_para(parasym:tparavarsym);
  540. var
  541. paraspec : byte;
  542. begin
  543. { only store user visible parameters }
  544. if not(vo_is_hidden_para in parasym.varoptions) then
  545. begin
  546. case parasym.varspez of
  547. vs_value: paraspec := 0;
  548. vs_const: paraspec := pfConst;
  549. vs_var : paraspec := pfVar;
  550. vs_out : paraspec := pfOut;
  551. end;
  552. { write flags for current parameter }
  553. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(paraspec));
  554. { write name of current parameter }
  555. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(parasym.realname)));
  556. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(parasym.realname));
  557. { write name of type of current parameter }
  558. write_rtti_name(parasym.vardef);
  559. end;
  560. end;
  561. var
  562. methodkind : byte;
  563. i : integer;
  564. begin
  565. if po_methodpointer in def.procoptions then
  566. begin
  567. { write method id and name }
  568. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkmethod));
  569. write_rtti_name(def);
  570. if (tf_requires_proper_alignment in target_info.flags) then
  571. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  572. { write kind of method (can only be function or procedure)}
  573. if def.returndef = voidtype then
  574. methodkind := mkProcedure
  575. else
  576. methodkind := mkFunction;
  577. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(methodkind));
  578. { write parameter info. The parameters must be written in reverse order
  579. if this method uses right to left parameter pushing! }
  580. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.maxparacount));
  581. if def.proccalloption in pushleftright_pocalls then
  582. begin
  583. for i:=0 to def.paras.count-1 do
  584. write_para(tparavarsym(def.paras[i]));
  585. end
  586. else
  587. begin
  588. for i:=def.paras.count-1 downto 0 do
  589. write_para(tparavarsym(def.paras[i]));
  590. end;
  591. { write name of result type }
  592. write_rtti_name(def.returndef);
  593. end
  594. else
  595. begin
  596. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkprocvar));
  597. write_rtti_name(def);
  598. end;
  599. end;
  600. procedure objectdef_rtti(def:tobjectdef);
  601. procedure objectdef_rtti_class_init(def:tobjectdef);
  602. begin
  603. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  604. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fields_count(def.symtable,rt)));
  605. fields_write_rtti_data(def.symtable,rt);
  606. end;
  607. procedure objectdef_rtti_interface_init(def:tobjectdef);
  608. begin
  609. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  610. end;
  611. procedure objectdef_rtti_class_full(def:tobjectdef);
  612. var
  613. propnamelist : TFPHashObjectList;
  614. begin
  615. { Collect unique property names with nameindex }
  616. propnamelist:=TFPHashObjectList.Create;
  617. collect_propnamelist(propnamelist,def);
  618. if (oo_has_vmt in def.objectoptions) then
  619. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(def.vmt_mangledname,0))
  620. else
  621. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  622. { write parent typeinfo }
  623. if assigned(def.childof) and
  624. (oo_can_have_published in def.childof.objectoptions) then
  625. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.childof,fullrtti)))
  626. else
  627. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  628. { total number of unique properties }
  629. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnamelist.count));
  630. { write unit name }
  631. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  632. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(current_module.realmodulename^));
  633. if (tf_requires_proper_alignment in target_info.flags) then
  634. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  635. { write published properties for this object }
  636. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(published_properties_count(def.symtable)));
  637. if (tf_requires_proper_alignment in target_info.flags) then
  638. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  639. published_properties_write_rtti_data(propnamelist,def.symtable);
  640. propnamelist.free;
  641. end;
  642. procedure objectdef_rtti_interface_full(def:tobjectdef);
  643. var
  644. i : longint;
  645. propnamelist : TFPHashObjectList;
  646. begin
  647. { Collect unique property names with nameindex }
  648. propnamelist:=TFPHashObjectList.Create;
  649. collect_propnamelist(propnamelist,def);
  650. { write parent typeinfo }
  651. if assigned(def.childof) then
  652. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.childof,fullrtti)))
  653. else
  654. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  655. { interface: write flags, iid and iidstr }
  656. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(
  657. { ugly, but working }
  658. {$ifdef USE_PACKSET1}
  659. byte([
  660. {$else USE_PACKSET1}
  661. longint([
  662. {$endif USE_PACKSET1}
  663. TCompilerIntfFlag(ord(ifHasGuid)*ord(assigned(def.iidguid))),
  664. TCompilerIntfFlag(ord(ifHasStrGUID)*ord(assigned(def.iidstr))),
  665. TCompilerIntfFlag(ord(ifDispInterface)*ord(def.objecttype=odt_dispinterface))
  666. ])
  667. {
  668. ifDispatch, }
  669. ));
  670. if (tf_requires_proper_alignment in target_info.flags) then
  671. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  672. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.iidguid^.D1)));
  673. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(def.iidguid^.D2));
  674. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(def.iidguid^.D3));
  675. for i:=Low(def.iidguid^.D4) to High(def.iidguid^.D4) do
  676. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.iidguid^.D4[i]));
  677. { write unit name }
  678. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  679. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(current_module.realmodulename^));
  680. if (tf_requires_proper_alignment in target_info.flags) then
  681. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  682. { write iidstr }
  683. if assigned(def.iidstr) then
  684. begin
  685. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(def.iidstr^)));
  686. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(def.iidstr^));
  687. end
  688. else
  689. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  690. if (tf_requires_proper_alignment in target_info.flags) then
  691. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  692. { write published properties for this object }
  693. published_properties_write_rtti_data(propnamelist,def.symtable);
  694. propnamelist.free;
  695. end;
  696. begin
  697. case def.objecttype of
  698. odt_class:
  699. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkclass));
  700. odt_object:
  701. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkobject));
  702. odt_dispinterface,
  703. odt_interfacecom:
  704. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterface));
  705. odt_interfacecorba:
  706. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterfaceCorba));
  707. else
  708. internalerror(200611034);
  709. end;
  710. { generate the name }
  711. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(def.objrealname^)));
  712. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(def.objrealname^));
  713. if (tf_requires_proper_alignment in target_info.flags) then
  714. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  715. case rt of
  716. initrtti :
  717. begin
  718. if def.objecttype in [odt_class,odt_object] then
  719. objectdef_rtti_class_init(def)
  720. else
  721. objectdef_rtti_interface_init(def);
  722. end;
  723. fullrtti :
  724. begin
  725. if def.objecttype in [odt_class,odt_object] then
  726. objectdef_rtti_class_full(def)
  727. else
  728. objectdef_rtti_interface_full(def);
  729. end;
  730. end;
  731. end;
  732. begin
  733. case def.typ of
  734. variantdef :
  735. variantdef_rtti(tvariantdef(def));
  736. stringdef :
  737. stringdef_rtti(tstringdef(def));
  738. enumdef :
  739. enumdef_rtti(tenumdef(def));
  740. orddef :
  741. orddef_rtti(torddef(def));
  742. floatdef :
  743. floatdef_rtti(tfloatdef(def));
  744. setdef :
  745. setdef_rtti(tsetdef(def));
  746. procvardef :
  747. procvardef_rtti(tprocvardef(def));
  748. arraydef :
  749. begin
  750. if ado_IsBitPacked in tarraydef(def).arrayoptions then
  751. unknown_rtti(tstoreddef(def))
  752. else
  753. arraydef_rtti(tarraydef(def));
  754. end;
  755. recorddef :
  756. begin
  757. if trecorddef(def).is_packed then
  758. unknown_rtti(tstoreddef(def))
  759. else
  760. recorddef_rtti(trecorddef(def));
  761. end;
  762. objectdef :
  763. objectdef_rtti(tobjectdef(def));
  764. else
  765. unknown_rtti(tstoreddef(def));
  766. end;
  767. end;
  768. procedure TRTTIWriter.write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  769. procedure enumdef_rtti_ord2stringindex(def:Tenumdef);
  770. var rttilab:Tasmsymbol;
  771. t:Tenumsym;
  772. syms:^Tenumsym;
  773. offsets:^longint;
  774. sym_count,sym_alloc:longint;
  775. h,i,p,o,st:longint;
  776. mode:(lookup,search); {Modify with care, ordinal value of enum is written.}
  777. r:single; {Must be real type because of integer overflow risk.}
  778. begin
  779. {Random access needed, put in array.}
  780. getmem(syms,64*sizeof(Tenumsym));
  781. getmem(offsets,64*sizeof(longint));
  782. sym_count:=0;
  783. sym_alloc:=64;
  784. st:=0;
  785. t:=Tenumsym(def.firstenum);
  786. while assigned(t) do
  787. begin
  788. if sym_count>=sym_alloc then
  789. begin
  790. reallocmem(syms,2*sym_alloc*sizeof(Tenumsym));
  791. reallocmem(offsets,2*sym_alloc*sizeof(longint));
  792. sym_alloc:=sym_alloc*2;
  793. end;
  794. syms[sym_count]:=t;
  795. offsets[sym_count]:=st;
  796. inc(sym_count);
  797. st:=st+length(t.realname)+1;
  798. t:=t.nextenum;
  799. end;
  800. {Sort the syms by enum value}
  801. if sym_count>=2 then
  802. begin
  803. p:=1;
  804. while 2*p<sym_count do
  805. p:=2*p;
  806. while p<>0 do
  807. begin
  808. for h:=p to sym_count-1 do
  809. begin
  810. i:=h;
  811. t:=syms[i];
  812. o:=offsets[i];
  813. repeat
  814. if syms[i-p].value<=t.value then
  815. break;
  816. syms[i]:=syms[i-p];
  817. offsets[i]:=offsets[i-p];
  818. dec(i,p);
  819. until i<p;
  820. syms[i]:=t;
  821. offsets[i]:=o;
  822. end;
  823. p:=p shr 1;
  824. end;
  825. end;
  826. {Decide wether a lookup array is size efficient.}
  827. mode:=lookup;
  828. if sym_count>0 then
  829. begin
  830. i:=1;
  831. r:=0;
  832. h:=syms[0].value; {Next expected enum value is min.}
  833. while i<sym_count do
  834. begin
  835. {Calculate size of hole between values. Avoid integer overflows.}
  836. r:=r+(single(syms[i].value)-single(h))-1;
  837. h:=syms[i].value;
  838. inc(i);
  839. end;
  840. if r>sym_count then
  841. mode:=search; {Don't waste more than 50% space.}
  842. end;
  843. {Calculate start of string table.}
  844. st:=1;
  845. if assigned(def.typesym) then
  846. inc(st,length(def.typesym.realname)+1)
  847. else
  848. inc(st);
  849. if (tf_requires_proper_alignment in target_info.flags) then
  850. align(st,sizeof(Tconstptruint));
  851. inc(st);
  852. if (tf_requires_proper_alignment in target_info.flags) then
  853. align(st,sizeof(Tconstptruint));
  854. inc(st,8+sizeof(aint));
  855. { write rtti data }
  856. with current_asmdata do
  857. begin
  858. rttilab:=defineasmsymbol(Tstoreddef(def).rtti_mangledname(rt)+'_o2s',AB_GLOBAL,AT_DATA);
  859. maybe_new_object_file(asmlists[al_rtti]);
  860. new_section(asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(aint)));
  861. asmlists[al_rtti].concat(Tai_symbol.create_global(rttilab,0));
  862. asmlists[al_rtti].concat(Tai_const.create_32bit(longint(mode)));
  863. if mode=lookup then
  864. begin
  865. o:=syms[0].value; {Start with min value.}
  866. for i:=0 to sym_count-1 do
  867. begin
  868. while o<syms[i].value do
  869. begin
  870. asmlists[al_rtti].concat(Tai_const.create_aint(0));
  871. inc(o);
  872. end;
  873. inc(o);
  874. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  875. end;
  876. end
  877. else
  878. begin
  879. asmlists[al_rtti].concat(Tai_const.create_32bit(sym_count));
  880. for i:=0 to sym_count-1 do
  881. begin
  882. asmlists[al_rtti].concat(Tai_const.create_32bit(syms[i].value));
  883. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  884. end;
  885. end;
  886. asmlists[al_rtti].concat(Tai_symbol_end.create(rttilab));
  887. end;
  888. dispose(syms);
  889. dispose(offsets);
  890. end;
  891. procedure enumdef_rtti_string2ordindex(def:Tenumdef);
  892. var rttilab:Tasmsymbol;
  893. t:Tenumsym;
  894. syms:^Tenumsym;
  895. offsets:^longint;
  896. sym_count,sym_alloc:longint;
  897. h,i,p,o,st:longint;
  898. begin
  899. {Random access needed, put in array.}
  900. getmem(syms,64*sizeof(Tenumsym));
  901. getmem(offsets,64*sizeof(longint));
  902. sym_count:=0;
  903. sym_alloc:=64;
  904. st:=0;
  905. t:=Tenumsym(def.firstenum);
  906. while assigned(t) do
  907. begin
  908. if sym_count>=sym_alloc then
  909. begin
  910. reallocmem(syms,2*sym_alloc*sizeof(Tenumsym));
  911. reallocmem(offsets,2*sym_alloc*sizeof(longint));
  912. sym_alloc:=sym_alloc*2;
  913. end;
  914. syms[sym_count]:=t;
  915. offsets[sym_count]:=st;
  916. inc(sym_count);
  917. st:=st+length(t.realname)+1;
  918. t:=t.nextenum;
  919. end;
  920. {Sort the syms by enum name}
  921. if sym_count>=2 then
  922. begin
  923. p:=1;
  924. while 2*p<sym_count do
  925. p:=2*p;
  926. while p<>0 do
  927. begin
  928. for h:=p to sym_count-1 do
  929. begin
  930. i:=h;
  931. t:=syms[i];
  932. o:=offsets[i];
  933. repeat
  934. if syms[i-p].name<=t.name then
  935. break;
  936. syms[i]:=syms[i-p];
  937. offsets[i]:=offsets[i-p];
  938. dec(i,p);
  939. until i<p;
  940. syms[i]:=t;
  941. offsets[i]:=o;
  942. end;
  943. p:=p shr 1;
  944. end;
  945. end;
  946. {Calculate start of string table.}
  947. st:=1;
  948. if assigned(def.typesym) then
  949. inc(st,length(def.typesym.realname)+1)
  950. else
  951. inc(st);
  952. if (tf_requires_proper_alignment in target_info.flags) then
  953. align(st,sizeof(Tconstptruint));
  954. inc(st);
  955. if (tf_requires_proper_alignment in target_info.flags) then
  956. align(st,sizeof(Tconstptruint));
  957. inc(st,8+sizeof(aint));
  958. { write rtti data }
  959. with current_asmdata do
  960. begin
  961. rttilab:=defineasmsymbol(Tstoreddef(def).rtti_mangledname(rt)+'_s2o',AB_GLOBAL,AT_DATA);
  962. maybe_new_object_file(asmlists[al_rtti]);
  963. new_section(asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(aint)));
  964. asmlists[al_rtti].concat(Tai_symbol.create_global(rttilab,0));
  965. asmlists[al_rtti].concat(Tai_const.create_32bit(sym_count));
  966. for i:=0 to sym_count-1 do
  967. begin
  968. asmlists[al_rtti].concat(Tai_const.create_32bit(syms[i].value));
  969. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  970. end;
  971. asmlists[al_rtti].concat(Tai_symbol_end.create(rttilab));
  972. end;
  973. dispose(syms);
  974. dispose(offsets);
  975. end;
  976. begin
  977. case def.typ of
  978. enumdef:
  979. if rt=fullrtti then
  980. begin
  981. enumdef_rtti_ord2stringindex(Tenumdef(def));
  982. enumdef_rtti_string2ordindex(Tenumdef(def));
  983. end;
  984. end;
  985. end;
  986. procedure TRTTIWriter.write_child_rtti_data(def:tdef;rt:trttitype);
  987. begin
  988. case def.typ of
  989. enumdef :
  990. if assigned(tenumdef(def).basedef) then
  991. write_rtti(tenumdef(def).basedef,rt);
  992. setdef :
  993. write_rtti(tsetdef(def).elementdef,rt);
  994. arraydef :
  995. write_rtti(tarraydef(def).elementdef,rt);
  996. recorddef :
  997. fields_write_rtti(trecorddef(def).symtable,rt);
  998. objectdef :
  999. begin
  1000. if assigned(tobjectdef(def).childof) then
  1001. write_rtti(tobjectdef(def).childof,rt);
  1002. if rt=initrtti then
  1003. fields_write_rtti(tobjectdef(def).symtable,rt)
  1004. else
  1005. published_write_rtti(tobjectdef(def).symtable,rt);
  1006. end;
  1007. end;
  1008. end;
  1009. function TRTTIWriter.ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  1010. begin
  1011. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
  1012. end;
  1013. procedure TRTTIWriter.write_rtti(def:tdef;rt:trttitype);
  1014. var
  1015. rttilab : tasmsymbol;
  1016. begin
  1017. { only write rtti of definitions from the current module }
  1018. if not findunitsymtable(def.owner).iscurrentunit then
  1019. exit;
  1020. { prevent recursion }
  1021. if rttidefstate[rt] in def.defstates then
  1022. exit;
  1023. include(def.defstates,rttidefstate[rt]);
  1024. { write first all dependencies }
  1025. write_child_rtti_data(def,rt);
  1026. { write rtti data }
  1027. rttilab:=current_asmdata.DefineAsmSymbol(tstoreddef(def).rtti_mangledname(rt),AB_GLOBAL,AT_DATA);
  1028. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  1029. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(aint)));
  1030. current_asmdata.asmlists[al_rtti].concat(Tai_symbol.Create_global(rttilab,0));
  1031. write_rtti_data(def,rt);
  1032. current_asmdata.asmlists[al_rtti].concat(Tai_symbol_end.Create(rttilab));
  1033. write_rtti_extrasyms(def,rt,rttilab);
  1034. end;
  1035. function TRTTIWriter.get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  1036. begin
  1037. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
  1038. end;
  1039. function TRTTIWriter.get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  1040. begin
  1041. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_o2s');
  1042. end;
  1043. function TRTTIWriter.get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  1044. begin
  1045. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_s2o');
  1046. end;
  1047. end.