nllvmtcon.pas 22 KB

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