nllvmtcon.pas 22 KB

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