nllvmtcon.pas 22 KB

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