nllvmtcon.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. {
  2. Copyright (c) 2014 by Jonas Maebe
  3. Generates code for typed constant declarations for the LLVM target
  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 nllvmtcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,constexp,globtype,
  22. aasmbase,aasmtai,aasmcnst,aasmllvm,
  23. symconst,symtype,symdef,symsym,
  24. ngtcon;
  25. type
  26. tllvmaggregateinformation = class(taggregateinformation)
  27. private
  28. faggai: tai_aggregatetypedconst;
  29. fanonrecalignpos: longint;
  30. public
  31. constructor create(_def: tdef; _typ: ttypedconstkind); override;
  32. function prepare_next_field(nextfielddef: tdef): asizeint; override;
  33. property aggai: tai_aggregatetypedconst read faggai write faggai;
  34. property anonrecalignpos: longint read fanonrecalignpos write fanonrecalignpos;
  35. end;
  36. tllvmtypedconstplaceholder = class(ttypedconstplaceholder)
  37. agginfo: tllvmaggregateinformation;
  38. pos: longint;
  39. constructor create(info: tllvmaggregateinformation; p: longint; d: tdef);
  40. procedure replace(ai: tai; d: tdef); override;
  41. end;
  42. tllvmtai_typedconstbuilder = class(ttai_typedconstbuilder)
  43. protected type
  44. public
  45. { set the default value for caggregateinformation (= tllvmaggregateinformation) }
  46. class constructor classcreate;
  47. protected
  48. fqueued_tai,
  49. flast_added_tai: tai;
  50. fqueued_tai_opidx: longint;
  51. procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
  52. { outerai: the ai that should become fqueued_tai in case it's still nil,
  53. or that should be filled in the fqueued_tai_opidx of the current
  54. fqueued_tai if it's not nil
  55. innerai: the innermost ai (possibly an operand of outerai) in which
  56. newindex indicates which operand is empty and can be filled with the
  57. next queued tai }
  58. procedure update_queued_tai(resdef: tdef; outerai, innerai: tai; newindex: longint);
  59. function wrap_with_type(p: tai; def: tdef): tai;
  60. procedure do_emit_tai(p: tai; def: tdef); override;
  61. procedure mark_anon_aggregate_alignment; override;
  62. procedure insert_marked_aggregate_alignment(def: tdef); override;
  63. procedure maybe_emit_tail_padding(def: tdef); override;
  64. procedure begin_aggregate_internal(def: tdef; anonymous: boolean); override;
  65. procedure end_aggregate_internal(def: tdef; anonymous: boolean); override;
  66. function get_internal_data_section_start_label: tasmlabel; override;
  67. function get_internal_data_section_internal_label: tasmlabel; override;
  68. procedure do_emit_extended_in_aggregate(p: tai);
  69. public
  70. destructor destroy; override;
  71. procedure emit_tai(p: tai; def: tdef); override;
  72. procedure emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef); override;
  73. procedure emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef); override;
  74. procedure queue_init(todef: tdef); override;
  75. procedure queue_vecn(def: tdef; const index: tconstexprint); override;
  76. procedure queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym); override;
  77. procedure queue_typeconvn(fromdef, todef: tdef); override;
  78. procedure queue_emit_staticvar(vs: tstaticvarsym); override;
  79. procedure queue_emit_asmsym(sym: tasmsymbol; def: tdef); override;
  80. procedure queue_emit_ordconst(value: int64; def: tdef); override;
  81. function emit_placeholder(def: tdef): ttypedconstplaceholder; override;
  82. class function get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint; override;
  83. end;
  84. implementation
  85. uses
  86. verbose,systems,
  87. aasmdata,
  88. cpubase,cpuinfo,llvmbase,
  89. symbase,symtable,llvmdef,defutil;
  90. { tllvmaggregateinformation }
  91. constructor tllvmaggregateinformation.create(_def: tdef; _typ: ttypedconstkind);
  92. begin
  93. inherited;
  94. fanonrecalignpos:=-1;
  95. end;
  96. function tllvmaggregateinformation.prepare_next_field(nextfielddef: tdef): asizeint;
  97. begin
  98. result:=inherited;
  99. { in case we let LLVM align, don't add padding ourselves }
  100. if df_llvm_no_struct_packing in def.defoptions then
  101. result:=0;
  102. end;
  103. { tllvmtypedconstplaceholder }
  104. constructor tllvmtypedconstplaceholder.create(info: tllvmaggregateinformation; p: longint; d: tdef);
  105. begin
  106. inherited create(d);
  107. agginfo:=info;
  108. pos:=p;
  109. end;
  110. procedure tllvmtypedconstplaceholder.replace(ai: tai; d: tdef);
  111. var
  112. oldconst: tai_abstracttypedconst;
  113. begin
  114. if d<>def then
  115. internalerror(2015091002);
  116. oldconst:=agginfo.aggai.replacevalueatpos(
  117. tai_simpletypedconst.create(tck_simple,d,ai),pos
  118. );
  119. oldconst.free;
  120. end;
  121. { tllvmtai_typedconstbuilder }
  122. class constructor tllvmtai_typedconstbuilder.classcreate;
  123. begin
  124. caggregateinformation:=tllvmaggregateinformation;
  125. end;
  126. procedure tllvmtai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  127. var
  128. newasmlist: tasmlist;
  129. decl: taillvmdecl;
  130. begin
  131. newasmlist:=tasmlist.create;
  132. { llvm declaration with as initialisation data all the elements from the
  133. original asmlist }
  134. decl:=taillvmdecl.createdef(sym,def,fasmlist,section,alignment);
  135. if section=sec_user then
  136. decl.setsecname(secname);
  137. if tcalo_is_lab in options then
  138. include(decl.flags,ldf_unnamed_addr);
  139. { TODO: tcalo_no_dead_strip: add to @llvm.user meta-variable }
  140. newasmlist.concat(decl);
  141. fasmlist:=newasmlist;
  142. end;
  143. procedure tllvmtai_typedconstbuilder.update_queued_tai(resdef: tdef; outerai, innerai: tai; newindex: longint);
  144. begin
  145. { the outer tai must always be a typed constant (possibly a wrapper
  146. around a taillvm or so), in order for result type information to be
  147. available }
  148. if outerai.typ<>ait_typedconst then
  149. internalerror(2014060401);
  150. { is the result of the outermost expression different from the type of
  151. this typed const? -> insert type conversion }
  152. if not assigned(fqueued_tai) and
  153. (resdef<>fqueued_def) and
  154. (llvmencodetypename(resdef)<>llvmencodetypename(fqueued_def)) then
  155. queue_typeconvn(resdef,fqueued_def);
  156. if assigned(fqueued_tai) then
  157. begin
  158. taillvm(flast_added_tai).loadtai(fqueued_tai_opidx,outerai);
  159. { already flushed? }
  160. if fqueued_tai_opidx=-1 then
  161. internalerror(2014062201);
  162. end
  163. else
  164. begin
  165. fqueued_tai:=outerai;
  166. fqueued_def:=resdef;
  167. end;
  168. fqueued_tai_opidx:=newindex;
  169. flast_added_tai:=innerai;
  170. end;
  171. function tllvmtai_typedconstbuilder.wrap_with_type(p: tai; def: tdef): tai;
  172. begin
  173. result:=tai_simpletypedconst.create(tck_simple,def,p);
  174. end;
  175. destructor tllvmtai_typedconstbuilder.destroy;
  176. begin
  177. inherited destroy;
  178. end;
  179. procedure tllvmtai_typedconstbuilder.emit_tai(p: tai; def: tdef);
  180. var
  181. arrdef: tdef;
  182. begin
  183. { inside an aggregate, an 80 bit floating point number must be
  184. emitted as an array of 10 bytes to prevent ABI alignment and
  185. padding to 16 bytes }
  186. if (def.typ=floatdef) and
  187. (tfloatdef(def).floattype=s80real) and
  188. assigned(curagginfo) then
  189. do_emit_extended_in_aggregate(p)
  190. else
  191. inherited;
  192. end;
  193. procedure tllvmtai_typedconstbuilder.do_emit_tai(p: tai; def: tdef);
  194. var
  195. ai: tai;
  196. stc: tai_abstracttypedconst;
  197. kind: ttypedconstkind;
  198. info: tllvmaggregateinformation;
  199. begin
  200. if queue_is_active then
  201. begin
  202. kind:=tck_simple;
  203. { finalise the queued expression }
  204. ai:=tai_simpletypedconst.create(kind,def,p);
  205. { set the new index to -1, so we internalerror should we try to
  206. add anything further }
  207. update_queued_tai(def,ai,ai,-1);
  208. { and emit it }
  209. stc:=tai_abstracttypedconst(fqueued_tai);
  210. def:=fqueued_def;
  211. { ensure we don't try to emit this one again }
  212. fqueued_tai:=nil;
  213. end
  214. else
  215. stc:=tai_simpletypedconst.create(tck_simple,def,p);
  216. info:=tllvmaggregateinformation(curagginfo);
  217. { these elements can be aggregates themselves, e.g. a shortstring can
  218. be emitted as a series of bytes and string data arrays }
  219. kind:=aggregate_kind(def);
  220. if (kind<>tck_simple) then
  221. begin
  222. if not assigned(info) or
  223. (info.aggai.adetyp<>kind) then
  224. internalerror(2014052906);
  225. end;
  226. if assigned(info) then
  227. info.aggai.addvalue(stc)
  228. else
  229. inherited do_emit_tai(stc,def);
  230. end;
  231. procedure tllvmtai_typedconstbuilder.mark_anon_aggregate_alignment;
  232. var
  233. info: tllvmaggregateinformation;
  234. begin
  235. info:=tllvmaggregateinformation(curagginfo);
  236. info.anonrecalignpos:=info.aggai.valuecount;
  237. end;
  238. procedure tllvmtai_typedconstbuilder.insert_marked_aggregate_alignment(def: tdef);
  239. var
  240. info: tllvmaggregateinformation;
  241. fillbytes: asizeint;
  242. begin
  243. info:=tllvmaggregateinformation(curagginfo);
  244. if info.anonrecalignpos=-1 then
  245. internalerror(2014091501);
  246. fillbytes:=info.prepare_next_field(def);
  247. while fillbytes>0 do
  248. begin
  249. info.aggai.insertvaluebeforepos(tai_simpletypedconst.create(tck_simple,u8inttype,tai_const.create_8bit(0)),info.anonrecalignpos);
  250. dec(fillbytes);
  251. end;
  252. end;
  253. procedure tllvmtai_typedconstbuilder.maybe_emit_tail_padding(def: tdef);
  254. begin
  255. { in case we let LLVM align, don't add padding ourselves }
  256. if df_llvm_no_struct_packing in def.defoptions then
  257. exit;
  258. inherited;
  259. end;
  260. procedure tllvmtai_typedconstbuilder.emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef);
  261. begin
  262. if not pvdef.is_addressonly then
  263. pvdef:=cprocvardef.getreusableprocaddr(pvdef);
  264. emit_tai(p,pvdef);
  265. end;
  266. procedure tllvmtai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);
  267. var
  268. srsym : tsym;
  269. srsymtable: tsymtable;
  270. strrecdef : trecorddef;
  271. strdef: tdef;
  272. offset: pint;
  273. field: tfieldvarsym;
  274. dataptrdef: tdef;
  275. begin
  276. { nil pointer? }
  277. if not assigned(ll.lab) then
  278. begin
  279. if ll.ofs<>0 then
  280. internalerror(2015030701);
  281. inherited;
  282. exit;
  283. end;
  284. { if the returned offset is <> 0, then the string data
  285. starts at that offset -> translate to a field for the
  286. high level code generator }
  287. if ll.ofs<>0 then
  288. begin
  289. { get the recorddef for this string constant }
  290. if not searchsym_type(ctai_typedconstbuilder.get_dynstring_rec_name(st,winlikewidestring,strlength),srsym,srsymtable) then
  291. internalerror(2014080406);
  292. strrecdef:=trecorddef(ttypesym(srsym).typedef);
  293. { offset in the record of the the string data }
  294. offset:=ctai_typedconstbuilder.get_string_symofs(st,winlikewidestring);
  295. { field corresponding to this offset }
  296. field:=trecordsymtable(strrecdef.symtable).findfieldbyoffset(offset);
  297. { pointerdef to the string data array }
  298. dataptrdef:=cpointerdef.getreusable(field.vardef);
  299. { the fields of the resourcestring record are declared as ansistring }
  300. strdef:=get_dynstring_def_for_type(st,winlikewidestring);
  301. queue_init(strdef);
  302. queue_typeconvn(charptrdef,strdef);
  303. queue_subscriptn(strrecdef,field);
  304. queue_emit_asmsym(ll.lab,strrecdef);
  305. end
  306. else
  307. { since llvm doesn't support labels in the middle of structs, this
  308. offset should never be 0 }
  309. internalerror(2014080506);
  310. end;
  311. procedure tllvmtai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean);
  312. var
  313. agg: tai_aggregatetypedconst;
  314. tck: ttypedconstkind;
  315. curagg: tllvmaggregateinformation;
  316. begin
  317. tck:=aggregate_kind(def);
  318. if tck<>tck_simple then
  319. begin
  320. { create new typed const aggregate }
  321. agg:=tai_aggregatetypedconst.create(tck,def);
  322. { either add to the current typed const aggregate (if nested), or
  323. emit to the asmlist (if top level) }
  324. curagg:=tllvmaggregateinformation(curagginfo);
  325. { create aggregate information for this new aggregate }
  326. inherited;
  327. { only add the new aggregate to the previous aggregate now, because
  328. the inherited call may have had to add padding bytes first }
  329. if assigned(curagg) then
  330. curagg.aggai.addvalue(agg)
  331. else
  332. fasmlist.concat(agg);
  333. { set new current typed const aggregate }
  334. tllvmaggregateinformation(curagginfo).aggai:=agg
  335. end
  336. else
  337. inherited;
  338. end;
  339. procedure tllvmtai_typedconstbuilder.end_aggregate_internal(def: tdef; anonymous: boolean);
  340. var
  341. info: tllvmaggregateinformation;
  342. begin
  343. if aggregate_kind(def)<>tck_simple then
  344. begin
  345. info:=tllvmaggregateinformation(curagginfo);
  346. if not assigned(info) then
  347. internalerror(2014060101);
  348. info.aggai.finish;
  349. end;
  350. inherited;
  351. end;
  352. function tllvmtai_typedconstbuilder.get_internal_data_section_start_label: tasmlabel;
  353. begin
  354. { let llvm take care of everything by creating internal nameless
  355. constants }
  356. current_asmdata.getlocaldatalabel(result);
  357. end;
  358. function tllvmtai_typedconstbuilder.get_internal_data_section_internal_label: tasmlabel;
  359. begin
  360. current_asmdata.getlocaldatalabel(result);
  361. end;
  362. procedure tllvmtai_typedconstbuilder.do_emit_extended_in_aggregate(p: tai);
  363. type
  364. p80realval =^t80realval;
  365. t80realval = packed record
  366. case byte of
  367. 0: (v: ts80real);
  368. 1: (a: array[0..9] of byte);
  369. end;
  370. var
  371. arrdef: tdef;
  372. i: longint;
  373. realval: p80realval;
  374. begin
  375. { emit as an array of 10 bytes }
  376. arrdef:=carraydef.getreusable(u8inttype,10);
  377. maybe_begin_aggregate(arrdef);
  378. if (p.typ<>ait_realconst) then
  379. internalerror(2015062401);
  380. realval:=p80realval(@tai_realconst(p).value.s80val);
  381. if target_info.endian=source_info.endian then
  382. for i:=0 to 9 do
  383. emit_tai(tai_const.Create_8bit(realval^.a[i]),u8inttype)
  384. else
  385. for i:=9 downto 0 do
  386. emit_tai(tai_const.Create_8bit(realval^.a[i]),u8inttype);
  387. maybe_end_aggregate(arrdef);
  388. { free the original constant, since we didn't emit it }
  389. p.free;
  390. end;
  391. procedure tllvmtai_typedconstbuilder.queue_init(todef: tdef);
  392. begin
  393. inherited;
  394. fqueued_tai:=nil;
  395. flast_added_tai:=nil;
  396. fqueued_tai_opidx:=-1;
  397. end;
  398. procedure tllvmtai_typedconstbuilder.queue_vecn(def: tdef; const index: tconstexprint);
  399. var
  400. ai: taillvm;
  401. aityped: tai;
  402. eledef: tdef;
  403. begin
  404. { update range checking info }
  405. inherited;
  406. ai:=taillvm.getelementptr_reg_tai_size_const(NR_NO,nil,ptrsinttype,index.svalue,true);
  407. case def.typ of
  408. arraydef:
  409. eledef:=tarraydef(def).elementdef;
  410. stringdef:
  411. case tstringdef(def).stringtype of
  412. st_shortstring,
  413. st_longstring,
  414. st_ansistring:
  415. eledef:=cansichartype;
  416. st_widestring,
  417. st_unicodestring:
  418. eledef:=cwidechartype;
  419. else
  420. internalerror(2014062202);
  421. end;
  422. else
  423. internalerror(2014062203);
  424. end;
  425. aityped:=wrap_with_type(ai,cpointerdef.getreusable(eledef));
  426. update_queued_tai(cpointerdef.getreusable(eledef),aityped,ai,1);
  427. end;
  428. procedure tllvmtai_typedconstbuilder.queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym);
  429. var
  430. getllvmfieldaddr,
  431. getpascalfieldaddr,
  432. getllvmfieldaddrtyped: tai;
  433. llvmfielddef: tdef;
  434. begin
  435. { update range checking info }
  436. inherited;
  437. llvmfielddef:=tabstractrecordsymtable(def.symtable).llvmst[vs].def;
  438. { get the address of the llvm-struct field that corresponds to this
  439. Pascal field }
  440. getllvmfieldaddr:=taillvm.getelementptr_reg_tai_size_const(NR_NO,nil,s32inttype,vs.llvmfieldnr,true);
  441. { getelementptr doesn't contain its own resultdef, so encode it via a
  442. tai_simpletypedconst tai }
  443. getllvmfieldaddrtyped:=wrap_with_type(getllvmfieldaddr,cpointerdef.getreusable(llvmfielddef));
  444. { if it doesn't match the requested field exactly (variant record),
  445. fixup the result }
  446. getpascalfieldaddr:=getllvmfieldaddrtyped;
  447. if (vs.offsetfromllvmfield<>0) or
  448. (llvmfielddef<>vs.vardef) then
  449. begin
  450. { offset of real field relative to llvm-struct field <> 0? }
  451. if vs.offsetfromllvmfield<>0 then
  452. begin
  453. { convert to a pointer to a 1-sized element }
  454. if llvmfielddef.size<>1 then
  455. begin
  456. getpascalfieldaddr:=taillvm.op_reg_tai_size(la_bitcast,NR_NO,getpascalfieldaddr,u8inttype);
  457. { update the current fielddef of the expression }
  458. llvmfielddef:=u8inttype;
  459. end;
  460. { add the offset }
  461. getpascalfieldaddr:=taillvm.getelementptr_reg_tai_size_const(NR_NO,getpascalfieldaddr,ptrsinttype,vs.offsetfromllvmfield,true);
  462. { ... and set the result type of the getelementptr }
  463. getpascalfieldaddr:=wrap_with_type(getpascalfieldaddr,cpointerdef.getreusable(u8inttype));
  464. llvmfielddef:=u8inttype;
  465. end;
  466. { bitcast the data at the final offset to the right type }
  467. if llvmfielddef<>vs.vardef then
  468. getpascalfieldaddr:=wrap_with_type(taillvm.op_reg_tai_size(la_bitcast,NR_NO,getpascalfieldaddr,cpointerdef.getreusable(vs.vardef)),cpointerdef.getreusable(vs.vardef));
  469. end;
  470. update_queued_tai(cpointerdef.getreusable(vs.vardef),getpascalfieldaddr,getllvmfieldaddr,1);
  471. end;
  472. procedure tllvmtai_typedconstbuilder.queue_typeconvn(fromdef, todef: tdef);
  473. var
  474. ai: taillvm;
  475. typedai: tai;
  476. tmpintdef: tdef;
  477. op,
  478. firstop,
  479. secondop: tllvmop;
  480. begin
  481. inherited;
  482. { special case: procdef -> procvardef/pointerdef: must take address of
  483. the procdef }
  484. if (fromdef.typ=procdef) and
  485. (todef.typ<>procdef) then
  486. fromdef:=cprocvardef.getreusableprocaddr(tprocdef(fromdef));
  487. op:=llvmconvop(fromdef,todef);
  488. case op of
  489. la_ptrtoint_to_x,
  490. la_x_to_inttoptr:
  491. begin
  492. { convert via an integer with the same size as "x" }
  493. if op=la_ptrtoint_to_x then
  494. begin
  495. tmpintdef:=cgsize_orddef(def_cgsize(todef));
  496. firstop:=la_ptrtoint;
  497. secondop:=la_bitcast
  498. end
  499. else
  500. begin
  501. tmpintdef:=cgsize_orddef(def_cgsize(fromdef));
  502. firstop:=la_bitcast;
  503. secondop:=la_inttoptr;
  504. end;
  505. { since we have to queue operations from outer to inner, first queue
  506. the conversion from the tempintdef to the todef }
  507. ai:=taillvm.op_reg_tai_size(secondop,NR_NO,nil,todef);
  508. typedai:=wrap_with_type(ai,todef);
  509. update_queued_tai(todef,typedai,ai,1);
  510. todef:=tmpintdef;
  511. op:=firstop
  512. end;
  513. end;
  514. ai:=taillvm.op_reg_tai_size(op,NR_NO,nil,todef);
  515. typedai:=wrap_with_type(ai,todef);
  516. update_queued_tai(todef,typedai,ai,1);
  517. end;
  518. procedure tllvmtai_typedconstbuilder.queue_emit_staticvar(vs: tstaticvarsym);
  519. begin
  520. { we've already incorporated the offset via the inserted operations above,
  521. make sure it doesn't get emitted again as part of the tai_const for
  522. the tasmsymbol }
  523. fqueue_offset:=0;
  524. inherited;
  525. end;
  526. procedure tllvmtai_typedconstbuilder.queue_emit_asmsym(sym: tasmsymbol; def: tdef);
  527. begin
  528. { we've already incorporated the offset via the inserted operations above,
  529. make sure it doesn't get emitted again as part of the tai_const for
  530. the tasmsymbol }
  531. fqueue_offset:=0;
  532. inherited;
  533. end;
  534. procedure tllvmtai_typedconstbuilder.queue_emit_ordconst(value: int64; def: tdef);
  535. begin
  536. { no offset into an ordinal constant }
  537. if fqueue_offset<>0 then
  538. internalerror(2015030702);
  539. inherited;
  540. end;
  541. function tllvmtai_typedconstbuilder.emit_placeholder(def: tdef): ttypedconstplaceholder;
  542. var
  543. pos: longint;
  544. begin
  545. check_add_placeholder(def);
  546. { we can't support extended constants, because those are transformed into
  547. an array of bytes, so we can't easily replace them afterwards }
  548. if (def.typ=floatdef) and
  549. (tfloatdef(def).floattype=s80real) then
  550. internalerror(2015091003);
  551. pos:=tllvmaggregateinformation(curagginfo).aggai.valuecount;
  552. emit_tai(tai_marker.Create(mark_position),def);
  553. result:=tllvmtypedconstplaceholder.create(tllvmaggregateinformation(curagginfo),pos,def);
  554. end;
  555. class function tllvmtai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
  556. begin
  557. { LLVM does not support labels in the middle of a declaration }
  558. result:=get_string_header_size(typ,winlikewidestring);
  559. end;
  560. begin
  561. ctai_typedconstbuilder:=tllvmtai_typedconstbuilder;
  562. end.