nllvmtcon.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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 of C/ABI alignment, the padding gets added by LLVM }
  100. if tabstractrecordsymtable(tabstractrecorddef(def).symtable).usefieldalignment=C_alignment 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 of C/ABI alignment, the padding gets added by LLVM }
  256. if (is_record(def) or
  257. is_object(def)) and
  258. (tabstractrecordsymtable(tabstractrecorddef(def).symtable).usefieldalignment=C_alignment) then
  259. exit;
  260. inherited;
  261. end;
  262. procedure tllvmtai_typedconstbuilder.emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef);
  263. begin
  264. if not pvdef.is_addressonly then
  265. pvdef:=cprocvardef.getreusableprocaddr(pvdef);
  266. emit_tai(p,pvdef);
  267. end;
  268. procedure tllvmtai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);
  269. var
  270. srsym : tsym;
  271. srsymtable: tsymtable;
  272. strrecdef : trecorddef;
  273. offset: pint;
  274. field: tfieldvarsym;
  275. dataptrdef: tdef;
  276. begin
  277. { nil pointer? }
  278. if not assigned(ll.lab) then
  279. begin
  280. if ll.ofs<>0 then
  281. internalerror(2015030701);
  282. inherited;
  283. exit;
  284. end;
  285. { if the returned offset is <> 0, then the string data
  286. starts at that offset -> translate to a field for the
  287. high level code generator }
  288. if ll.ofs<>0 then
  289. begin
  290. { get the recorddef for this string constant }
  291. if not searchsym_type(ctai_typedconstbuilder.get_dynstring_rec_name(st,winlikewidestring,strlength),srsym,srsymtable) then
  292. internalerror(2014080406);
  293. strrecdef:=trecorddef(ttypesym(srsym).typedef);
  294. { offset in the record of the the string data }
  295. offset:=ctai_typedconstbuilder.get_string_symofs(st,winlikewidestring);
  296. { field corresponding to this offset }
  297. field:=trecordsymtable(strrecdef.symtable).findfieldbyoffset(offset);
  298. { pointerdef to the string data array }
  299. dataptrdef:=cpointerdef.getreusable(field.vardef);
  300. queue_init(charptrdef);
  301. queue_subscriptn(strrecdef,field);
  302. queue_emit_asmsym(ll.lab,strrecdef);
  303. end
  304. else
  305. { since llvm doesn't support labels in the middle of structs, this
  306. offset should never be 0 }
  307. internalerror(2014080506);
  308. end;
  309. procedure tllvmtai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean);
  310. var
  311. agg: tai_aggregatetypedconst;
  312. tck: ttypedconstkind;
  313. curagg: tllvmaggregateinformation;
  314. begin
  315. tck:=aggregate_kind(def);
  316. if tck<>tck_simple then
  317. begin
  318. { create new typed const aggregate }
  319. agg:=tai_aggregatetypedconst.create(tck,def);
  320. { either add to the current typed const aggregate (if nested), or
  321. emit to the asmlist (if top level) }
  322. curagg:=tllvmaggregateinformation(curagginfo);
  323. { create aggregate information for this new aggregate }
  324. inherited;
  325. { only add the new aggregate to the previous aggregate now, because
  326. the inherited call may have had to add padding bytes first }
  327. if assigned(curagg) then
  328. curagg.aggai.addvalue(agg)
  329. else
  330. fasmlist.concat(agg);
  331. { set new current typed const aggregate }
  332. tllvmaggregateinformation(curagginfo).aggai:=agg
  333. end
  334. else
  335. inherited;
  336. end;
  337. procedure tllvmtai_typedconstbuilder.end_aggregate_internal(def: tdef; anonymous: boolean);
  338. var
  339. info: tllvmaggregateinformation;
  340. begin
  341. if aggregate_kind(def)<>tck_simple then
  342. begin
  343. info:=tllvmaggregateinformation(curagginfo);
  344. if not assigned(info) then
  345. internalerror(2014060101);
  346. info.aggai.finish;
  347. end;
  348. inherited;
  349. end;
  350. function tllvmtai_typedconstbuilder.get_internal_data_section_start_label: tasmlabel;
  351. begin
  352. { let llvm take care of everything by creating internal nameless
  353. constants }
  354. current_asmdata.getlocaldatalabel(result);
  355. end;
  356. function tllvmtai_typedconstbuilder.get_internal_data_section_internal_label: tasmlabel;
  357. begin
  358. current_asmdata.getlocaldatalabel(result);
  359. end;
  360. procedure tllvmtai_typedconstbuilder.do_emit_extended_in_aggregate(p: tai);
  361. type
  362. p80realval =^t80realval;
  363. t80realval = packed record
  364. case byte of
  365. 0: (v: ts80real);
  366. 1: (a: array[0..9] of byte);
  367. end;
  368. var
  369. arrdef: tdef;
  370. i: longint;
  371. realval: p80realval;
  372. begin
  373. { emit as an array of 10 bytes }
  374. arrdef:=carraydef.getreusable(u8inttype,10);
  375. maybe_begin_aggregate(arrdef);
  376. if (p.typ<>ait_realconst) then
  377. internalerror(2015062401);
  378. realval:=p80realval(@tai_realconst(p).value.s80val);
  379. if target_info.endian=source_info.endian then
  380. for i:=0 to 9 do
  381. emit_tai(tai_const.Create_8bit(realval^.a[i]),u8inttype)
  382. else
  383. for i:=9 downto 0 do
  384. emit_tai(tai_const.Create_8bit(realval^.a[i]),u8inttype);
  385. maybe_end_aggregate(arrdef);
  386. { free the original constant, since we didn't emit it }
  387. p.free;
  388. end;
  389. procedure tllvmtai_typedconstbuilder.queue_init(todef: tdef);
  390. begin
  391. inherited;
  392. fqueued_tai:=nil;
  393. flast_added_tai:=nil;
  394. fqueued_tai_opidx:=-1;
  395. end;
  396. procedure tllvmtai_typedconstbuilder.queue_vecn(def: tdef; const index: tconstexprint);
  397. var
  398. ai: taillvm;
  399. aityped: tai;
  400. eledef: tdef;
  401. begin
  402. { update range checking info }
  403. inherited;
  404. ai:=taillvm.getelementptr_reg_tai_size_const(NR_NO,nil,ptrsinttype,index.svalue,true);
  405. case def.typ of
  406. arraydef:
  407. eledef:=tarraydef(def).elementdef;
  408. stringdef:
  409. case tstringdef(def).stringtype of
  410. st_shortstring,
  411. st_longstring,
  412. st_ansistring:
  413. eledef:=cansichartype;
  414. st_widestring,
  415. st_unicodestring:
  416. eledef:=cwidechartype;
  417. else
  418. internalerror(2014062202);
  419. end;
  420. else
  421. internalerror(2014062203);
  422. end;
  423. aityped:=wrap_with_type(ai,cpointerdef.getreusable(eledef));
  424. update_queued_tai(cpointerdef.getreusable(eledef),aityped,ai,1);
  425. end;
  426. procedure tllvmtai_typedconstbuilder.queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym);
  427. var
  428. getllvmfieldaddr,
  429. getpascalfieldaddr,
  430. getllvmfieldaddrtyped: tai;
  431. llvmfielddef: tdef;
  432. begin
  433. { update range checking info }
  434. inherited;
  435. llvmfielddef:=tabstractrecordsymtable(def.symtable).llvmst[vs].def;
  436. { get the address of the llvm-struct field that corresponds to this
  437. Pascal field }
  438. getllvmfieldaddr:=taillvm.getelementptr_reg_tai_size_const(NR_NO,nil,s32inttype,vs.llvmfieldnr,true);
  439. { getelementptr doesn't contain its own resultdef, so encode it via a
  440. tai_simpletypedconst tai }
  441. getllvmfieldaddrtyped:=wrap_with_type(getllvmfieldaddr,cpointerdef.getreusable(llvmfielddef));
  442. { if it doesn't match the requested field exactly (variant record),
  443. fixup the result }
  444. getpascalfieldaddr:=getllvmfieldaddrtyped;
  445. if (vs.offsetfromllvmfield<>0) or
  446. (llvmfielddef<>vs.vardef) then
  447. begin
  448. { offset of real field relative to llvm-struct field <> 0? }
  449. if vs.offsetfromllvmfield<>0 then
  450. begin
  451. { convert to a pointer to a 1-sized element }
  452. if llvmfielddef.size<>1 then
  453. begin
  454. getpascalfieldaddr:=taillvm.op_reg_tai_size(la_bitcast,NR_NO,getpascalfieldaddr,u8inttype);
  455. { update the current fielddef of the expression }
  456. llvmfielddef:=u8inttype;
  457. end;
  458. { add the offset }
  459. getpascalfieldaddr:=taillvm.getelementptr_reg_tai_size_const(NR_NO,getpascalfieldaddr,ptrsinttype,vs.offsetfromllvmfield,true);
  460. { ... and set the result type of the getelementptr }
  461. getpascalfieldaddr:=wrap_with_type(getpascalfieldaddr,cpointerdef.getreusable(u8inttype));
  462. llvmfielddef:=u8inttype;
  463. end;
  464. { bitcast the data at the final offset to the right type }
  465. if llvmfielddef<>vs.vardef then
  466. getpascalfieldaddr:=wrap_with_type(taillvm.op_reg_tai_size(la_bitcast,NR_NO,getpascalfieldaddr,cpointerdef.getreusable(vs.vardef)),cpointerdef.getreusable(vs.vardef));
  467. end;
  468. update_queued_tai(cpointerdef.getreusable(vs.vardef),getpascalfieldaddr,getllvmfieldaddr,1);
  469. end;
  470. procedure tllvmtai_typedconstbuilder.queue_typeconvn(fromdef, todef: tdef);
  471. var
  472. ai: taillvm;
  473. typedai: tai;
  474. tmpintdef: tdef;
  475. op,
  476. firstop,
  477. secondop: tllvmop;
  478. begin
  479. inherited;
  480. { special case: procdef -> procvardef/pointerdef: must take address of
  481. the procdef }
  482. if (fromdef.typ=procdef) and
  483. (todef.typ<>procdef) then
  484. fromdef:=cprocvardef.getreusableprocaddr(tprocdef(fromdef));
  485. op:=llvmconvop(fromdef,todef);
  486. case op of
  487. la_ptrtoint_to_x,
  488. la_x_to_inttoptr:
  489. begin
  490. { convert via an integer with the same size as "x" }
  491. if op=la_ptrtoint_to_x then
  492. begin
  493. tmpintdef:=cgsize_orddef(def_cgsize(todef));
  494. firstop:=la_ptrtoint;
  495. secondop:=la_bitcast
  496. end
  497. else
  498. begin
  499. tmpintdef:=cgsize_orddef(def_cgsize(fromdef));
  500. firstop:=la_bitcast;
  501. secondop:=la_inttoptr;
  502. end;
  503. { since we have to queue operations from outer to inner, first queue
  504. the conversion from the tempintdef to the todef }
  505. ai:=taillvm.op_reg_tai_size(secondop,NR_NO,nil,todef);
  506. typedai:=wrap_with_type(ai,todef);
  507. update_queued_tai(todef,typedai,ai,1);
  508. todef:=tmpintdef;
  509. op:=firstop
  510. end;
  511. end;
  512. ai:=taillvm.op_reg_tai_size(op,NR_NO,nil,todef);
  513. typedai:=wrap_with_type(ai,todef);
  514. update_queued_tai(todef,typedai,ai,1);
  515. end;
  516. procedure tllvmtai_typedconstbuilder.queue_emit_staticvar(vs: tstaticvarsym);
  517. begin
  518. { we've already incorporated the offset via the inserted operations above,
  519. make sure it doesn't get emitted again as part of the tai_const for
  520. the tasmsymbol }
  521. fqueue_offset:=0;
  522. inherited;
  523. end;
  524. procedure tllvmtai_typedconstbuilder.queue_emit_asmsym(sym: tasmsymbol; def: tdef);
  525. begin
  526. { we've already incorporated the offset via the inserted operations above,
  527. make sure it doesn't get emitted again as part of the tai_const for
  528. the tasmsymbol }
  529. fqueue_offset:=0;
  530. inherited;
  531. end;
  532. procedure tllvmtai_typedconstbuilder.queue_emit_ordconst(value: int64; def: tdef);
  533. begin
  534. { no offset into an ordinal constant }
  535. if fqueue_offset<>0 then
  536. internalerror(2015030702);
  537. inherited;
  538. end;
  539. function tllvmtai_typedconstbuilder.emit_placeholder(def: tdef): ttypedconstplaceholder;
  540. var
  541. pos: longint;
  542. begin
  543. check_add_placeholder(def);
  544. { we can't support extended constants, because those are transformed into
  545. an array of bytes, so we can't easily replace them afterwards }
  546. if (def.typ=floatdef) and
  547. (tfloatdef(def).floattype=s80real) then
  548. internalerror(2015091003);
  549. pos:=tllvmaggregateinformation(curagginfo).aggai.valuecount;
  550. emit_tai(tai_marker.Create(mark_position),def);
  551. result:=tllvmtypedconstplaceholder.create(tllvmaggregateinformation(curagginfo),pos,def);
  552. end;
  553. class function tllvmtai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
  554. begin
  555. { LLVM does not support labels in the middle of a declaration }
  556. result:=get_string_header_size(typ,winlikewidestring);
  557. end;
  558. begin
  559. ctai_typedconstbuilder:=tllvmtai_typedconstbuilder;
  560. end.