ncgld.pas 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate assembler for nodes that handle loads and assignments which
  4. are the same for all (most) processors
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgld;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. symtype,symsym,
  24. aasmdata,
  25. node,nld,cgutils;
  26. type
  27. tcgloadnode = class(tloadnode)
  28. protected
  29. procedure generate_nested_access(vs: tsym);virtual;
  30. procedure generate_absaddr_access(vs: tabsolutevarsym); virtual;
  31. procedure generate_threadvar_access(gvs: tstaticvarsym); virtual;
  32. function use_indirect_symbol(gvs: tstaticvarsym): boolean;
  33. public
  34. procedure pass_generate_code;override;
  35. procedure changereflocation(const ref: treference);
  36. end;
  37. tcgassignmentnode = class(tassignmentnode)
  38. protected
  39. function maybechangetemp(list: TAsmList; var n: tnode; const newref: treference): boolean;virtual;
  40. public
  41. procedure pass_generate_code;override;
  42. end;
  43. tcgarrayconstructornode = class(tarrayconstructornode)
  44. protected
  45. procedure makearrayref(var ref: treference; eledef: tdef);virtual;
  46. procedure advancearrayoffset(var ref: treference; elesize: asizeint);virtual;
  47. public
  48. procedure pass_generate_code;override;
  49. end;
  50. tcgrttinode = class(trttinode)
  51. procedure pass_generate_code;override;
  52. end;
  53. implementation
  54. uses
  55. cutils,
  56. systems,
  57. verbose,globals,constexp,fmodule,
  58. nutils,
  59. symtable,symconst,symdef,defutil,paramgr,ncon,nbas,ncgrtti,
  60. aasmbase,
  61. cgbase,pass_2,
  62. procinfo,
  63. cpuinfo,
  64. cpubase,parabase,
  65. tgobj,
  66. cgobj,hlcgobj,
  67. ncgbas,ncgflw,
  68. wpobase;
  69. {*****************************************************************************
  70. SSA (for memory temps) support
  71. *****************************************************************************}
  72. type
  73. preplacerefrec = ^treplacerefrec;
  74. treplacerefrec = record
  75. old, new: preference;
  76. ressym: tsym;
  77. end;
  78. function doreplaceref(var n: tnode; para: pointer): foreachnoderesult;
  79. var
  80. rr: preplacerefrec absolute para;
  81. begin
  82. result := fen_false;
  83. case n.nodetype of
  84. loadn:
  85. begin
  86. { regular variable }
  87. if (tabstractvarsym(tloadnode(n).symtableentry).varoptions * [vo_is_dll_var, vo_is_thread_var] = []) and
  88. not assigned(tloadnode(n).left) and
  89. { not function result, or no exit in function }
  90. (((tloadnode(n).symtableentry <> rr^.ressym) and
  91. not(vo_is_funcret in tabstractvarsym(tloadnode(n).symtableentry).varoptions)) or
  92. not(fc_exit in flowcontrol)) and
  93. { stored in memory... }
  94. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.loc in [LOC_REFERENCE]) and
  95. { ... at the place we are looking for }
  96. references_equal(tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.reference,rr^.old^) and
  97. { its address cannot have escaped the current routine }
  98. not(tabstractvarsym(tloadnode(n).symtableentry).addr_taken) and
  99. { it is not accessed in nested procedures }
  100. not(tabstractvarsym(tloadnode(n).symtableentry).different_scope) then
  101. begin
  102. { relocate variable }
  103. tcgloadnode(n).changereflocation(rr^.new^);
  104. result := fen_norecurse_true;
  105. end;
  106. end;
  107. temprefn:
  108. begin
  109. if (ti_valid in ttemprefnode(n).tempflags) and
  110. { memory temp... }
  111. (ttemprefnode(n).tempinfo^.location.loc in [LOC_REFERENCE]) and
  112. { ... at the place we are looking for }
  113. references_equal(ttemprefnode(n).tempinfo^.location.reference,rr^.old^) and
  114. { its address cannot have escaped the current routine }
  115. not(ti_addr_taken in ttemprefnode(n).tempflags) then
  116. begin
  117. { relocate the temp }
  118. tcgtemprefnode(n).changelocation(rr^.new^);
  119. result := fen_norecurse_true;
  120. end;
  121. end;
  122. { Subscriptn must be rejected, otherwise we may replace an
  123. an entire record with a temp for its first field, mantis #13948)
  124. Exception: the field's size is the same as the entire record
  125. The same goes for array indexing
  126. }
  127. subscriptn,
  128. vecn:
  129. if not(tunarynode(n).left.resultdef.typ in [recorddef,objectdef,arraydef,stringdef]) or
  130. { make sure we don't try to call resultdef.size for types that
  131. don't have a compile-time size such as open arrays }
  132. is_special_array(tunarynode(n).left.resultdef) or
  133. (tunarynode(n).left.resultdef.size<>tunarynode(n).resultdef.size) then
  134. result := fen_norecurse_false;
  135. { optimize the searching a bit }
  136. derefn,addrn,
  137. calln,inlinen,casen,
  138. addn,subn,muln,
  139. andn,orn,xorn,
  140. ltn,lten,gtn,gten,equaln,unequaln,
  141. slashn,divn,shrn,shln,notn,
  142. inn,
  143. asn,isn:
  144. result := fen_norecurse_false;
  145. else
  146. ;
  147. end;
  148. end;
  149. function tcgassignmentnode.maybechangetemp(list: TAsmList; var n: tnode; const newref: treference): boolean;
  150. var
  151. rr: treplacerefrec;
  152. begin
  153. result := false;
  154. { only do for -O2 or higher (breaks debugging since }
  155. { variables move to different memory locations) }
  156. if not(cs_opt_level2 in current_settings.optimizerswitches) or
  157. { must be a copy to a memory location ... }
  158. (n.location.loc <> LOC_REFERENCE) or
  159. { not inside a control flow statement and no goto's in sight }
  160. ([fc_inflowcontrol,fc_gotolabel] * flowcontrol <> []) or
  161. { not for refcounted types, because those locations are }
  162. { still used later on in initialisation/finalisation code }
  163. is_managed_type(n.resultdef) or
  164. { source and destination are temps (= not global variables) }
  165. { and both point to the start of a temp, and the source is a }
  166. { non-persistent temp (otherwise we need some kind of copy- }
  167. { on-write support in case later on both are still used) }
  168. not tg.isstartoftemp(newref) or
  169. not tg.isstartoftemp(n.location.reference) or
  170. (tg.gettypeoftemp(newref) <> tt_normal) or
  171. not (tg.gettypeoftemp(n.location.reference) in [tt_normal,tt_persistent]) or
  172. { and both have the same size }
  173. (tg.sizeoftemp(current_asmdata.CurrAsmList,newref) <> tg.sizeoftemp(current_asmdata.CurrAsmList,n.location.reference)) then
  174. exit;
  175. { find the source of the old reference (loadnode or tempnode) }
  176. { and replace it with the new reference }
  177. rr.old := @n.location.reference;
  178. rr.new := @newref;
  179. rr.ressym := nil;
  180. if assigned(current_procinfo.procdef.funcretsym) and
  181. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs <> 0) then
  182. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  183. rr.ressym:=tsym(current_procinfo.procdef.parast.Find('self'))
  184. else
  185. rr.ressym:=current_procinfo.procdef.funcretsym;
  186. { if source not found, don't do anything }
  187. if not foreachnodestatic(n,@doreplaceref,@rr) then
  188. exit;
  189. n.location.reference := newref;
  190. result:=true;
  191. end;
  192. {*****************************************************************************
  193. SecondLoad
  194. *****************************************************************************}
  195. procedure tcgloadnode.changereflocation(const ref: treference);
  196. var
  197. oldtemptype: ttemptype;
  198. begin
  199. if (location.loc<>LOC_REFERENCE) then
  200. internalerror(2007020812);
  201. if not tg.istemp(location.reference) then
  202. internalerror(2007020813);
  203. oldtemptype:=tg.gettypeoftemp(location.reference);
  204. if (oldtemptype = tt_persistent) then
  205. tg.ChangeTempType(current_asmdata.CurrAsmList,location.reference,tt_normal);
  206. tg.ungettemp(current_asmdata.CurrAsmList,location.reference);
  207. location.reference:=ref;
  208. tg.ChangeTempType(current_asmdata.CurrAsmList,location.reference,oldtemptype);
  209. tabstractnormalvarsym(symtableentry).localloc:=location;
  210. end;
  211. procedure tcgloadnode.generate_nested_access(vs: tsym);
  212. var
  213. { paramter declared as tsym to reduce interface unit dependencies }
  214. lvs: tabstractnormalvarsym absolute vs;
  215. begin
  216. secondpass(left);
  217. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  218. internalerror(200309286);
  219. if lvs.localloc.loc<>LOC_REFERENCE then
  220. internalerror(200409241);
  221. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,lvs.localloc.reference.offset,ctempposinvalid,lvs.localloc.reference.alignment,lvs.localloc.reference.volatility);
  222. end;
  223. procedure tcgloadnode.generate_absaddr_access(vs: tabsolutevarsym);
  224. begin
  225. location.reference.offset:=asizeint(vs.addroffset);
  226. location.reference.volatility:=[vol_read,vol_write];
  227. end;
  228. procedure tcgloadnode.generate_threadvar_access(gvs: tstaticvarsym);
  229. var
  230. respara,
  231. paraloc1 : tcgpara;
  232. fieldptrdef,
  233. pvd : tdef;
  234. endrelocatelab,
  235. norelocatelab : tasmlabel;
  236. tvref,
  237. href : treference;
  238. hregister, hreg_tv_rec : tregister;
  239. tv_rec : trecorddef;
  240. tv_index_field,
  241. tv_non_mt_data_field: tsym;
  242. tmpresloc: tlocation;
  243. issystemunit,
  244. indirect : boolean;
  245. size_opt : boolean;
  246. begin
  247. if (tf_section_threadvars in target_info.flags) then
  248. begin
  249. if gvs.localloc.loc=LOC_INVALID then
  250. if not(vo_is_weak_external in gvs.varoptions) then
  251. reference_reset_symbol(location.reference,current_asmdata.RefAsmSymbol(gvs.mangledname,AT_TLS,use_indirect_symbol(gvs)),0,location.reference.alignment,[])
  252. else
  253. reference_reset_symbol(location.reference,current_asmdata.WeakRefAsmSymbol(gvs.mangledname,AT_TLS),0,location.reference.alignment,[])
  254. else
  255. location:=gvs.localloc;
  256. end
  257. else
  258. begin
  259. {
  260. Thread var loading is optimized to first check if
  261. a relocate function is available. When the function
  262. is available it is called to retrieve the address.
  263. Otherwise the address is loaded with the symbol
  264. }
  265. tv_rec:=get_threadvar_record(resultdef,tv_index_field,tv_non_mt_data_field);
  266. fieldptrdef:=cpointerdef.getreusable(resultdef);
  267. current_asmdata.getjumplabel(norelocatelab);
  268. current_asmdata.getjumplabel(endrelocatelab);
  269. { make sure hregister can't allocate the register necessary for the parameter }
  270. pvd:=search_system_type('TRELOCATETHREADVARHANDLER').typedef;
  271. if pvd.typ<>procvardef then
  272. internalerror(2012120901);
  273. { FPC_THREADVAR_RELOCATE is nil? }
  274. issystemunit:=(
  275. assigned(current_module.globalsymtable) and
  276. (current_module.globalsymtable=systemunit)
  277. ) or
  278. (
  279. not assigned(current_module.globalsymtable) and
  280. (current_module.localsymtable=systemunit)
  281. );
  282. indirect:=(tf_supports_packages in target_info.flags) and
  283. (target_info.system in systems_indirect_var_imports) and
  284. (cs_imported_data in localswitches) and
  285. not issystemunit;
  286. if not(vo_is_weak_external in gvs.varoptions) then
  287. reference_reset_symbol(tvref,current_asmdata.RefAsmSymbol(gvs.mangledname,AT_DATA,use_indirect_symbol(gvs)),0,sizeof(pint),[])
  288. else
  289. reference_reset_symbol(tvref,current_asmdata.WeakRefAsmSymbol(gvs.mangledname,AT_DATA),0,sizeof(pint),[]);
  290. { Enable size optimization with -Os or PIC code is generated and PIC uses GOT }
  291. size_opt:=(cs_opt_size in current_settings.optimizerswitches)
  292. or ((cs_create_pic in current_settings.moduleswitches) and (tf_pic_uses_got in target_info.flags));
  293. hreg_tv_rec:=NR_INVALID;
  294. if size_opt then
  295. begin
  296. { Load a pointer to the thread var record into a register. }
  297. { This register will be used in both multithreaded and non-multithreaded cases. }
  298. hreg_tv_rec:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cpointerdef.getreusable(tv_rec));
  299. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,tv_rec,cpointerdef.getreusable(tv_rec),tvref,hreg_tv_rec);
  300. reference_reset_base(tvref,hreg_tv_rec,0,ctempposinvalid,tvref.alignment,tvref.volatility)
  301. end;
  302. paraloc1.init;
  303. paramanager.getcgtempparaloc(current_asmdata.CurrAsmList,tprocvardef(pvd),1,paraloc1);
  304. hregister:=hlcg.getaddressregister(current_asmdata.CurrAsmList,pvd);
  305. reference_reset_symbol(href,current_asmdata.RefAsmSymbol('FPC_THREADVAR_RELOCATE',AT_DATA,indirect),0,pvd.alignment,[]);
  306. if not issystemunit then
  307. current_module.add_extern_asmsym('FPC_THREADVAR_RELOCATE',AB_EXTERNAL,AT_DATA);
  308. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,pvd,pvd,href,hregister);
  309. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,pvd,OC_EQ,0,hregister,norelocatelab);
  310. { no, call it with the index of the threadvar as parameter }
  311. href:=tvref;
  312. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,
  313. tv_rec,
  314. tfieldvarsym(tv_index_field),href);
  315. hlcg.a_load_ref_cgpara(current_asmdata.CurrAsmList,tfieldvarsym(tv_index_field).vardef,href,paraloc1);
  316. { Dealloc the threadvar record register before calling the helper function to allow }
  317. { the register allocator to assign non-mandatory real registers for hreg_tv_rec. }
  318. if size_opt then
  319. cg.a_reg_dealloc(current_asmdata.CurrAsmList,hreg_tv_rec);
  320. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  321. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  322. { result is the address of the threadvar }
  323. respara:=hlcg.a_call_reg(current_asmdata.CurrAsmList,tprocvardef(pvd),hregister,[@paraloc1]);
  324. paraloc1.done;
  325. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  326. { load the address of the result in hregister }
  327. hregister:=hlcg.getaddressregister(current_asmdata.CurrAsmList,fieldptrdef);
  328. location_reset(tmpresloc,LOC_REGISTER,def_cgsize(fieldptrdef));
  329. tmpresloc.register:=hregister;
  330. hlcg.gen_load_cgpara_loc(current_asmdata.CurrAsmList,fieldptrdef,respara,tmpresloc,true);
  331. respara.resetiftemp;
  332. hlcg.a_jmp_always(current_asmdata.CurrAsmList,endrelocatelab);
  333. { no relocation needed, load the address of the variable only, the
  334. layout of a threadvar is:
  335. 0 - Threadvar index
  336. sizeof(pint) - Threadvar value in single threading }
  337. hlcg.a_label(current_asmdata.CurrAsmList,norelocatelab);
  338. href:=tvref;
  339. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,
  340. tv_rec,
  341. tfieldvarsym(tv_non_mt_data_field),href);
  342. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,resultdef,fieldptrdef,href,hregister);
  343. hlcg.a_label(current_asmdata.CurrAsmList,endrelocatelab);
  344. hlcg.reference_reset_base(location.reference,fieldptrdef,hregister,0,ctempposinvalid,resultdef.alignment,[]);
  345. end;
  346. end;
  347. function tcgloadnode.use_indirect_symbol(gvs:tstaticvarsym):boolean;
  348. begin
  349. { we are using a direct reference if any of the following is true:
  350. - the target does not support packages
  351. - the target does not use indirect references
  352. - the variable is declared as (weak) external
  353. - G- is set
  354. - the variable is located inside the same unit }
  355. result:=(tf_supports_packages in target_info.flags) and
  356. (target_info.system in systems_indirect_var_imports) and
  357. (gvs.varoptions*[vo_is_external,vo_is_weak_external]=[]) and
  358. (gvs.owner.symtabletype in [globalsymtable,staticsymtable]) and
  359. (cs_imported_data in localswitches) and
  360. not sym_is_owned_by(gvs,current_module.globalsymtable) and
  361. (
  362. (current_module.globalsymtable=current_module.localsymtable) or
  363. not sym_is_owned_by(gvs,current_module.localsymtable)
  364. );
  365. end;
  366. procedure tcgloadnode.pass_generate_code;
  367. var
  368. hregister : tregister;
  369. vs : tabstractnormalvarsym;
  370. gvs : tstaticvarsym;
  371. vmtdef : tpointerdef;
  372. vmtentry: tfieldvarsym;
  373. pd : tprocdef;
  374. href : treference;
  375. newsize : tcgsize;
  376. vd : tdef;
  377. alignment: longint;
  378. indirect : boolean;
  379. name : TSymStr;
  380. begin
  381. { we don't know the size of all arrays }
  382. newsize:=def_cgsize(resultdef);
  383. { alignment is overridden per case below }
  384. location_reset_ref(location,LOC_REFERENCE,newsize,resultdef.alignment,[]);
  385. case symtableentry.typ of
  386. absolutevarsym :
  387. begin
  388. { this is only for toasm and toaddr }
  389. case tabsolutevarsym(symtableentry).abstyp of
  390. toaddr :
  391. generate_absaddr_access(tabsolutevarsym(symtableentry));
  392. toasm :
  393. location.reference.symbol:=current_asmdata.RefAsmSymbol(tabsolutevarsym(symtableentry).mangledname,AT_DATA);
  394. else
  395. internalerror(200310283);
  396. end;
  397. end;
  398. constsym:
  399. begin
  400. if tconstsym(symtableentry).consttyp=constresourcestring then
  401. begin
  402. location_reset_ref(location,LOC_CREFERENCE,def_cgsize(cansistringtype),cansistringtype.size,[]);
  403. indirect:=(tf_supports_packages in target_info.flags) and
  404. (target_info.system in systems_indirect_var_imports) and
  405. (cs_imported_data in localswitches) and
  406. (symtableentry.owner.moduleid<>current_module.moduleid);
  407. name:=make_mangledname('RESSTR',symtableentry.owner,symtableentry.name);
  408. location.reference.symbol:=current_asmdata.RefAsmSymbol(name,AT_DATA,indirect);
  409. if symtableentry.owner.moduleid<>current_module.moduleid then
  410. current_module.addimportedsym(symtableentry);
  411. vd:=search_system_type('TRESOURCESTRINGRECORD').typedef;
  412. hlcg.g_set_addr_nonbitpacked_field_ref(
  413. current_asmdata.CurrAsmList,
  414. trecorddef(vd),
  415. tfieldvarsym(search_struct_member(trecorddef(vd),'CURRENTVALUE')),
  416. location.reference);
  417. end
  418. else
  419. internalerror(22798);
  420. end;
  421. staticvarsym :
  422. begin
  423. gvs:=tstaticvarsym(symtableentry);
  424. if (vo_is_dll_var in gvs.varoptions) then
  425. { DLL variable }
  426. begin
  427. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  428. if not(vo_is_weak_external in gvs.varoptions) then
  429. location.reference.symbol:=current_asmdata.RefAsmSymbol(tstaticvarsym(symtableentry).mangledname,AT_DATA)
  430. else
  431. location.reference.symbol:=current_asmdata.WeakRefAsmSymbol(tstaticvarsym(symtableentry).mangledname,AT_DATA);
  432. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,location.reference,hregister);
  433. reference_reset_base(location.reference,hregister,0,ctempposinvalid,location.reference.alignment,[]);
  434. end
  435. { Thread variable }
  436. else if (vo_is_thread_var in gvs.varoptions) then
  437. generate_threadvar_access(gvs)
  438. { Normal (or external) variable }
  439. else
  440. begin
  441. if gvs.localloc.loc=LOC_INVALID then
  442. begin
  443. { static data is currently always volatile }
  444. if not(vo_is_weak_external in gvs.varoptions) then
  445. reference_reset_symbol(location.reference,current_asmdata.RefAsmSymbol(gvs.mangledname,AT_DATA,use_indirect_symbol(gvs)),0,location.reference.alignment,[])
  446. else
  447. reference_reset_symbol(location.reference,current_asmdata.WeakRefAsmSymbol(gvs.mangledname,AT_DATA),0,location.reference.alignment,[])
  448. end
  449. else
  450. location:=gvs.localloc;
  451. end;
  452. { make const a LOC_CREFERENCE }
  453. if (gvs.varspez=vs_const) and
  454. (location.loc=LOC_REFERENCE) then
  455. location.loc:=LOC_CREFERENCE;
  456. end;
  457. paravarsym,
  458. localvarsym :
  459. begin
  460. vs:=tabstractnormalvarsym(symtableentry);
  461. { Nested variable }
  462. if assigned(left) then
  463. generate_nested_access(vs)
  464. else
  465. location:=vs.localloc;
  466. { handle call by reference variables when they are not
  467. already copied to local copies. Also ignore the reference
  468. when we need to load the self pointer for objects }
  469. if is_addr_param_load then
  470. begin
  471. if (location.loc in [LOC_CREGISTER,LOC_REGISTER]) then
  472. hregister:=location.register
  473. else
  474. begin
  475. vd:=cpointerdef.getreusable(resultdef);
  476. hregister:=hlcg.getaddressregister(current_asmdata.CurrAsmList,vd);
  477. { we need to load only an address }
  478. location.size:=int_cgsize(vd.size);
  479. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,vd,vd,location,hregister);
  480. end;
  481. { assume packed records may always be unaligned }
  482. if not(resultdef.typ in [recorddef,objectdef]) or
  483. (tabstractrecordsymtable(tabstractrecorddef(resultdef).symtable).usefieldalignment<>1) then
  484. begin
  485. alignment:=min(min(min(resultdef.alignment,current_settings.alignment.localalignmax),current_settings.alignment.constalignmax),current_settings.alignment.varalignmax);
  486. location_reset_ref(location,LOC_REFERENCE,newsize,alignment,[]);
  487. end
  488. else
  489. location_reset_ref(location,LOC_REFERENCE,newsize,1,[]);
  490. hlcg.reference_reset_base(location.reference,voidpointertype,hregister,0,ctempposinvalid,location.reference.alignment,[]);
  491. end;
  492. { make const a LOC_CREFERENCE }
  493. if (vs.varspez=vs_const) and
  494. (location.loc=LOC_REFERENCE) then
  495. location.loc:=LOC_CREFERENCE;
  496. end;
  497. procsym:
  498. begin
  499. if not assigned(procdef) then
  500. internalerror(200312011);
  501. if assigned(left) and
  502. (resultdef.typ in [symconst.procdef,procvardef]) and
  503. not tabstractprocdef(resultdef).is_addressonly then
  504. begin
  505. location_reset(location,LOC_CREGISTER,int_cgsize(voidpointertype.size*2));
  506. secondpass(left);
  507. { load class instance/classrefdef address }
  508. if left.location.loc=LOC_CONSTANT then
  509. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  510. { vd will contain the type of the self pointer (self in
  511. case of a class/classref, address of self in case of
  512. an object, frame pointer or pointer to parentfpstruct
  513. in case of nested procsym load }
  514. vd:=nil;
  515. case left.location.loc of
  516. LOC_CREGISTER,
  517. LOC_REGISTER:
  518. begin
  519. { this is not possible for objects }
  520. if is_object(left.resultdef) then
  521. internalerror(200304234);
  522. location.registerhi:=left.location.register;
  523. vd:=left.resultdef;
  524. end;
  525. LOC_CREFERENCE,
  526. LOC_REFERENCE:
  527. begin
  528. if is_implicit_pointer_object_type(left.resultdef) or
  529. (left.resultdef.typ=classrefdef) or
  530. is_nested_pd(procdef) then
  531. begin
  532. vd:=left.resultdef;
  533. location.registerhi:=hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef);
  534. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location.reference,location.registerhi)
  535. end
  536. else
  537. begin
  538. vd:=cpointerdef.getreusable(left.resultdef);
  539. location.registerhi:=hlcg.getaddressregister(current_asmdata.CurrAsmList,vd);
  540. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.resultdef,vd,left.location.reference,location.registerhi);
  541. end;
  542. location_freetemp(current_asmdata.CurrAsmList,left.location);
  543. end;
  544. else
  545. internalerror(200610311);
  546. end;
  547. { virtual method ? }
  548. if (po_virtualmethod in procdef.procoptions) and
  549. not(loadnf_inherited in loadnodeflags) and
  550. not is_objectpascal_helper(procdef.struct) then
  551. begin
  552. if (not assigned(current_procinfo) or
  553. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  554. tobjectdef(procdef.struct).register_vmt_call(procdef.extnumber);
  555. {$ifdef vtentry}
  556. if not is_interface(procdef.struct) then
  557. begin
  558. inc(current_asmdata.NextVTEntryNr);
  559. current_asmdata.CurrAsmList.Concat(tai_symbol.CreateName('VTREF'+tostr(current_asmdata.NextVTEntryNr)+'_'+procdef._class.vmt_mangledname+'$$'+tostr(vmtoffset div sizeof(pint)),AT_FUNCTION,0,voidpointerdef));
  560. end;
  561. {$endif vtentry}
  562. if (left.resultdef.typ=objectdef) and
  563. assigned(tobjectdef(left.resultdef).vmt_field) then
  564. begin
  565. { vmt pointer is a pointer to the vmt record }
  566. hlcg.reference_reset_base(href,vd,location.registerhi,0,ctempposinvalid,vd.alignment,[]);
  567. vmtdef:=cpointerdef.getreusable(tobjectdef(left.resultdef).vmt_def);
  568. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,tobjectdef(left.resultdef),tfieldvarsym(tobjectdef(left.resultdef).vmt_field),href);
  569. hregister:=hlcg.getaddressregister(current_asmdata.CurrAsmList,vmtdef);
  570. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,tfieldvarsym(tobjectdef(left.resultdef).vmt_field).vardef,vmtdef,href,hregister);
  571. end
  572. else if left.resultdef.typ=classrefdef then
  573. begin
  574. { classrefdef is a pointer to the vmt already }
  575. hregister:=location.registerhi;
  576. vmtdef:=cpointerdef.getreusable(tobjectdef(tclassrefdef(left.resultdef).pointeddef).vmt_def);
  577. hlcg.g_ptrtypecast_reg(current_asmdata.CurrAsmList,left.resultdef,vmtdef,hregister);
  578. end
  579. else if is_any_interface_kind(left.resultdef) then
  580. begin
  581. { an interface is a pointer to a pointer to a vmt }
  582. hlcg.reference_reset_base(href,vd,location.registerhi,0,ctempposinvalid,vd.alignment,[]);
  583. vmtdef:=cpointerdef.getreusable(tobjectdef(left.resultdef).vmt_def);
  584. hregister:=hlcg.getaddressregister(current_asmdata.CurrAsmList,vmtdef);
  585. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,vmtdef,vmtdef,href,hregister);
  586. end
  587. else
  588. internalerror(2015112501);
  589. { load method address }
  590. vmtentry:=tabstractrecordsymtable(trecorddef(vmtdef.pointeddef).symtable).findfieldbyoffset(
  591. tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber));
  592. hlcg.reference_reset_base(href,vmtdef,hregister,0,ctempposinvalid,vmtdef.alignment,[]);
  593. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,vmtentry.vardef);
  594. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,tabstractrecorddef(vmtdef.pointeddef),vmtentry,href);
  595. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,vmtentry.vardef,vmtentry.vardef,href,location.register);
  596. end
  597. else
  598. begin
  599. { load address of the function }
  600. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION),0,procdef.address_type.alignment,[]);
  601. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cprocvardef.getreusableprocaddr(procdef,pc_address_only));
  602. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,procdef,cprocvardef.getreusableprocaddr(procdef,pc_address_only),href,location.register);
  603. end;
  604. { to get methodpointers stored correctly, code and self register must be swapped on
  605. big endian targets }
  606. if target_info.endian=endian_big then
  607. begin
  608. hregister:=location.register;
  609. location.register:=location.registerhi;
  610. location.registerhi:=hregister;
  611. end;
  612. end
  613. else
  614. begin
  615. pd:=tprocdef(tprocsym(symtableentry).ProcdefList[0]);
  616. { def_cgsize does not work for tprocdef, so we use pd.address_type }
  617. location.size:=def_cgsize(pd.address_type);
  618. if not(po_weakexternal in pd.procoptions) then
  619. location.reference.symbol:=current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION)
  620. else
  621. location.reference.symbol:=current_asmdata.WeakRefAsmSymbol(procdef.mangledname,AT_FUNCTION);
  622. end;
  623. end;
  624. labelsym :
  625. if assigned(tlabelsym(symtableentry).asmblocklabel) then
  626. location.reference.symbol:=tlabelsym(symtableentry).asmblocklabel
  627. else
  628. location.reference.symbol:=tcglabelnode((tlabelsym(symtableentry).code)).getasmlabel;
  629. else internalerror(200510032);
  630. end;
  631. end;
  632. {*****************************************************************************
  633. SecondAssignment
  634. *****************************************************************************}
  635. procedure tcgassignmentnode.pass_generate_code;
  636. var
  637. shuffle : pmmshuffle;
  638. hlabel : tasmlabel;
  639. href : treference;
  640. releaseright : boolean;
  641. alignmentrequirement,
  642. len : tcgint;
  643. r : tregister;
  644. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  645. r64 : tregister64;
  646. {$endif}
  647. oldflowcontrol : tflowcontrol;
  648. begin
  649. { previously, managed types were handled in firstpass
  650. newer FPCs however can identify situations when
  651. assignments of managed types require no special code and the
  652. value could be just copied so this could should be able also to handle
  653. managed types without any special "managing code"}
  654. location_reset(location,LOC_VOID,OS_NO);
  655. {
  656. in most cases we can process first the right node which contains
  657. the most complex code. Exceptions for this are:
  658. - result is in flags, loading left will then destroy the flags
  659. - result is a jump, loading left must be already done before the jump is made
  660. - result need reference count, when left points to a value used in
  661. right then decreasing the refcnt on left can possibly release
  662. the memory before right increased the refcnt, result is that an
  663. empty value is assigned
  664. But not when the result is in the flags, then
  665. loading the left node afterwards can destroy the flags.
  666. }
  667. if not(right.expectloc in [LOC_FLAGS,LOC_JUMP]) and
  668. (node_complexity(right)>node_complexity(left)) then
  669. begin
  670. secondpass(right);
  671. if codegenerror then
  672. exit;
  673. secondpass(left);
  674. if codegenerror then
  675. exit;
  676. end
  677. else
  678. begin
  679. { calculate left sides }
  680. secondpass(left);
  681. if codegenerror then
  682. exit;
  683. { tell the SSA/SSL code that the left side was handled first so
  684. ni SSL is done
  685. }
  686. oldflowcontrol:=flowcontrol;
  687. include(flowcontrol,fc_lefthandled);
  688. secondpass(right);
  689. flowcontrol:=oldflowcontrol;
  690. if codegenerror then
  691. exit;
  692. end;
  693. releaseright:=
  694. (left.nodetype<>temprefn) or
  695. not(ti_const in ttemprefnode(left).tempflags);
  696. { shortstring assignments are handled separately }
  697. if is_shortstring(left.resultdef) then
  698. begin
  699. {
  700. we can get here only in the following situations
  701. for the right node:
  702. - empty constant string
  703. - char
  704. }
  705. { The addn is replaced by a blockn or calln that already returns
  706. a shortstring }
  707. if is_shortstring(right.resultdef) and
  708. (right.nodetype in [blockn,calln]) then
  709. begin
  710. { verify that we indeed have nothing to do }
  711. if not(nf_assign_done_in_right in flags) then
  712. internalerror(2015042201);
  713. end
  714. { empty constant string }
  715. else if (right.nodetype=stringconstn) and
  716. (tstringconstnode(right).len=0) then
  717. begin
  718. hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(left.resultdef),tpointerdef(charpointertype),left.location.reference);
  719. hlcg.a_load_const_ref(current_asmdata.CurrAsmList,cansichartype,0,left.location.reference);
  720. end
  721. { char loading }
  722. else if is_char(right.resultdef) then
  723. begin
  724. if right.nodetype=ordconstn then
  725. begin
  726. hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(left.resultdef),cpointerdef.getreusable(u16inttype),left.location.reference);
  727. if (target_info.endian = endian_little) then
  728. hlcg.a_load_const_ref(current_asmdata.CurrAsmList,u16inttype,(tordconstnode(right).value.svalue shl 8) or 1,
  729. setalignment(left.location.reference,1))
  730. else
  731. hlcg.a_load_const_ref(current_asmdata.CurrAsmList,u16inttype,tordconstnode(right).value.svalue or (1 shl 8),
  732. setalignment(left.location.reference,1));
  733. end
  734. else
  735. begin
  736. href:=left.location.reference;
  737. hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(left.resultdef),tpointerdef(charpointertype),href);
  738. hlcg.a_load_const_ref(current_asmdata.CurrAsmList,cansichartype,1,href);
  739. inc(href.offset,1);
  740. href.alignment:=1;
  741. case right.location.loc of
  742. LOC_REGISTER,
  743. LOC_CREGISTER :
  744. begin
  745. {$ifndef cpuhighleveltarget}
  746. r:=cg.makeregsize(current_asmdata.CurrAsmList,right.location.register,OS_8);
  747. {$else not cpuhighleveltarget}
  748. r:=hlcg.getintregister(current_asmdata.CurrAsmList,u8inttype);
  749. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,cansichartype,u8inttype,right.location.register,r);
  750. {$endif cpuhighleveltarget}
  751. hlcg.a_load_reg_ref(current_asmdata.CurrAsmList,u8inttype,u8inttype,r,href);
  752. end;
  753. LOC_REFERENCE,
  754. LOC_CREFERENCE :
  755. hlcg.a_load_ref_ref(current_asmdata.CurrAsmList,cansichartype,cansichartype,right.location.reference,href);
  756. else
  757. internalerror(200205111);
  758. end;
  759. end;
  760. end
  761. else
  762. internalerror(2002042410);
  763. end
  764. { try to reuse memory locations instead of copying }
  765. { copy to a memory location ... }
  766. else if (right.location.loc = LOC_REFERENCE) and
  767. maybechangetemp(current_asmdata.CurrAsmList,left,right.location.reference) then
  768. begin
  769. { if it worked, we're done }
  770. end
  771. else
  772. begin
  773. { SSA support }
  774. hlcg.maybe_change_load_node_reg(current_asmdata.CurrAsmList,left,false);
  775. hlcg.maybe_change_load_node_reg(current_asmdata.CurrAsmList,right,true);
  776. case right.location.loc of
  777. LOC_CONSTANT :
  778. begin
  779. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  780. if (left.location.size in [OS_64,OS_S64]) or (right.location.size in [OS_64,OS_S64]) then
  781. cg64.a_load64_const_loc(current_asmdata.CurrAsmList,right.location.value64,left.location)
  782. else
  783. {$endif not cpu64bitalu and not cpuhighleveltarget}
  784. hlcg.a_load_const_loc(current_asmdata.CurrAsmList,left.resultdef,right.location.value,left.location);
  785. end;
  786. LOC_REFERENCE,
  787. LOC_CREFERENCE :
  788. begin
  789. case left.location.loc of
  790. LOC_REGISTER,
  791. LOC_CREGISTER :
  792. begin
  793. {$ifndef cpuhighleveltarget}
  794. {$ifdef cpu64bitalu}
  795. if left.location.size in [OS_128,OS_S128] then
  796. cg128.a_load128_ref_reg(current_asmdata.CurrAsmList,right.location.reference,left.location.register128)
  797. else
  798. {$else cpu64bitalu}
  799. if left.location.size in [OS_64,OS_S64] then
  800. cg64.a_load64_ref_reg(current_asmdata.CurrAsmList,right.location.reference,left.location.register64)
  801. else
  802. {$endif cpu64bitalu}
  803. {$endif not cpuhighleveltarget}
  804. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.reference,left.location.register);
  805. end;
  806. LOC_FPUREGISTER,
  807. LOC_CFPUREGISTER :
  808. begin
  809. hlcg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,
  810. right.resultdef,left.resultdef,
  811. right.location.reference,
  812. left.location.register);
  813. end;
  814. LOC_REFERENCE,
  815. LOC_CREFERENCE :
  816. begin
  817. if (left.resultdef.typ=floatdef) and
  818. (right.resultdef.typ=floatdef) and
  819. ((left.location.size<>right.location.size)
  820. { on newer (1993+ :)) x86 cpus, use the fpu to copy extended values }
  821. {$ifdef x86}
  822. or ({$ifndef x86_64}(current_settings.cputype>=cpu_Pentium) and{$endif x86_64} (is_extended(right.resultdef)))
  823. {$endif x86}
  824. )then
  825. begin
  826. { assume that all float types can be handed by the
  827. fpu if one can be handled by the fpu }
  828. if not use_vectorfpu(left.resultdef) or
  829. not use_vectorfpu(right.resultdef) then
  830. hlcg.a_loadfpu_ref_ref(current_asmdata.CurrAsmList,
  831. right.resultdef,left.resultdef,
  832. right.location.reference,left.location.reference)
  833. else
  834. hlcg.a_loadmm_ref_ref(current_asmdata.CurrAsmList,
  835. right.resultdef,left.resultdef,
  836. right.location.reference,left.location.reference,mms_movescalar)
  837. end
  838. else
  839. begin
  840. { TODO: HACK: unaligned test, maybe remove all unaligned locations (array of char) from the compiler}
  841. { Use unaligned copy when the offset is not aligned }
  842. len:=left.resultdef.size;
  843. { can be 0 in case of formaldef on JVM target }
  844. if len=0 then
  845. len:=sizeof(pint);
  846. { data smaller than an aint has less alignment requirements }
  847. { max(1,...) avoids div by zero in case of an empty record }
  848. alignmentrequirement:=min(max(1,len),sizeof(aint));
  849. if (right.location.reference.offset mod alignmentrequirement<>0) or
  850. (left.location.reference.offset mod alignmentrequirement<>0) or
  851. (right.resultdef.alignment<alignmentrequirement) or
  852. ((right.location.reference.alignment<>0) and
  853. (right.location.reference.alignment<alignmentrequirement)) or
  854. ((left.location.reference.alignment<>0) and
  855. (left.location.reference.alignment<alignmentrequirement)) then
  856. hlcg.g_concatcopy_unaligned(current_asmdata.CurrAsmList,left.resultdef,right.location.reference,left.location.reference)
  857. else
  858. hlcg.g_concatcopy(current_asmdata.CurrAsmList,left.resultdef,right.location.reference,left.location.reference);
  859. end;
  860. end;
  861. LOC_MMREGISTER,
  862. LOC_CMMREGISTER:
  863. begin
  864. {$if defined(x86) and not defined(llvm)}
  865. if (right.resultdef.typ=floatdef) and
  866. not use_vectorfpu(right.resultdef) then
  867. begin
  868. { perform size conversion if needed (the mm-code cannot }
  869. { convert an extended into a double/single, since sse }
  870. { doesn't support extended) }
  871. r:=cg.getfpuregister(current_asmdata.CurrAsmList,right.location.size);
  872. tg.gethltemp(current_asmdata.CurrAsmList,left.resultdef,left.resultdef.size,tt_normal,href);
  873. cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,right.location.size,right.location.size,right.location.reference,r);
  874. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,r,href);
  875. if releaseright then
  876. location_freetemp(current_asmdata.CurrAsmList,right.location);
  877. releaseright:=true;
  878. location_reset_ref(right.location,LOC_REFERENCE,left.location.size,0,[]);
  879. right.location.reference:=href;
  880. right.resultdef:=left.resultdef;
  881. end;
  882. {$endif}
  883. hlcg.a_loadmm_ref_reg(current_asmdata.CurrAsmList,
  884. right.resultdef,
  885. left.resultdef,
  886. right.location.reference,
  887. left.location.register,mms_movescalar);
  888. end;
  889. LOC_SUBSETREG,
  890. LOC_CSUBSETREG:
  891. hlcg.a_load_ref_subsetreg(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.reference,left.location.sreg);
  892. LOC_SUBSETREF,
  893. LOC_CSUBSETREF:
  894. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  895. if right.location.size in [OS_64,OS_S64] then
  896. cg64.a_load64_ref_subsetref(current_asmdata.CurrAsmList,right.location.reference,left.location.sref)
  897. else
  898. {$endif not cpu64bitalu and not cpuhighleveltarget}
  899. hlcg.a_load_ref_subsetref(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.reference,left.location.sref);
  900. else
  901. internalerror(200203284);
  902. end;
  903. end;
  904. {$ifdef SUPPORT_MMX}
  905. LOC_CMMXREGISTER,
  906. LOC_MMXREGISTER:
  907. begin
  908. if left.location.loc=LOC_CMMXREGISTER then
  909. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,OS_M64,OS_M64,right.location.register,left.location.register,nil)
  910. else
  911. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,OS_M64,OS_M64,right.location.register,left.location.reference,nil);
  912. end;
  913. {$endif SUPPORT_MMX}
  914. LOC_MMREGISTER,
  915. LOC_CMMREGISTER:
  916. begin
  917. if (is_vector(left.resultdef)) then
  918. shuffle := nil
  919. else
  920. shuffle := mms_movescalar;
  921. case left.location.loc of
  922. LOC_CMMREGISTER,
  923. LOC_MMREGISTER:
  924. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.register,left.location.register, shuffle);
  925. LOC_REFERENCE,
  926. LOC_CREFERENCE:
  927. hlcg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.register,left.location.reference, shuffle);
  928. else
  929. internalerror(2009112601);
  930. end;
  931. end;
  932. LOC_REGISTER,
  933. LOC_CREGISTER :
  934. begin
  935. {$ifndef cpuhighleveltarget}
  936. {$ifdef cpu64bitalu}
  937. if left.location.size in [OS_128,OS_S128] then
  938. cg128.a_load128_reg_loc(current_asmdata.CurrAsmList,
  939. right.location.register128,left.location)
  940. else
  941. {$else cpu64bitalu}
  942. { also OS_F64 in case of mmreg -> intreg }
  943. if left.location.size in [OS_64,OS_S64,OS_F64] then
  944. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,
  945. right.location.register64,left.location)
  946. else
  947. {$endif cpu64bitalu}
  948. {$endif not cpuhighleveltarget}
  949. {$ifdef i8086}
  950. { prefer a_load_loc_ref, because it supports i8086-specific types
  951. that use registerhi (like 6-byte method pointers)
  952. (todo: maybe we should add a_load_loc_loc?) }
  953. if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  954. hlcg.a_load_loc_ref(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location,left.location.reference)
  955. else
  956. {$endif i8086}
  957. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location.register,left.location);
  958. end;
  959. LOC_FPUREGISTER,
  960. LOC_CFPUREGISTER :
  961. begin
  962. { we can't do direct moves between fpu and mm registers }
  963. if left.location.loc in [LOC_MMREGISTER,LOC_CMMREGISTER] then
  964. begin
  965. {$if defined(x86) and not defined(llvm)}
  966. if not use_vectorfpu(right.resultdef) then
  967. begin
  968. { perform size conversion if needed (the mm-code cannot convert an }
  969. { extended into a double/single, since sse doesn't support extended) }
  970. tg.gethltemp(current_asmdata.CurrAsmList,left.resultdef,left.resultdef.size,tt_normal,href);
  971. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,right.location.register,href);
  972. location_reset_ref(right.location,LOC_REFERENCE,left.location.size,0,[]);
  973. right.location.reference:=href;
  974. right.resultdef:=left.resultdef;
  975. end;
  976. {$endif}
  977. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,right.location,right.resultdef,false);
  978. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,
  979. right.resultdef,left.resultdef,
  980. right.location.register,left.location.register,mms_movescalar);
  981. end
  982. else
  983. hlcg.a_loadfpu_reg_loc(current_asmdata.CurrAsmList,
  984. right.resultdef,left.resultdef,
  985. right.location.register,left.location);
  986. end;
  987. LOC_SUBSETREG,
  988. LOC_CSUBSETREG:
  989. begin
  990. hlcg.a_load_subsetreg_loc(current_asmdata.CurrAsmList,
  991. right.resultdef,left.resultdef,right.location.sreg,left.location);
  992. end;
  993. LOC_SUBSETREF,
  994. LOC_CSUBSETREF:
  995. begin
  996. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  997. if right.location.size in [OS_64,OS_S64] then
  998. cg64.a_load64_subsetref_loc(current_asmdata.CurrAsmList,right.location.sref,left.location)
  999. else
  1000. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1001. hlcg.a_load_subsetref_loc(current_asmdata.CurrAsmList,
  1002. right.resultdef,left.resultdef,right.location.sref,left.location);
  1003. end;
  1004. LOC_JUMP :
  1005. begin
  1006. current_asmdata.getjumplabel(hlabel);
  1007. hlcg.a_label(current_asmdata.CurrAsmList,right.location.truelabel);
  1008. if is_pasbool(left.resultdef) then
  1009. begin
  1010. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1011. if left.location.size in [OS_64,OS_S64] then
  1012. cg64.a_load64_const_loc(current_asmdata.CurrAsmList,1,left.location)
  1013. else
  1014. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1015. hlcg.a_load_const_loc(current_asmdata.CurrAsmList,left.resultdef,1,left.location)
  1016. end
  1017. else
  1018. begin
  1019. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1020. if left.location.size in [OS_64,OS_S64] then
  1021. cg64.a_load64_const_loc(current_asmdata.CurrAsmList,-1,left.location)
  1022. else
  1023. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1024. hlcg.a_load_const_loc(current_asmdata.CurrAsmList,left.resultdef,-1,left.location);
  1025. end;
  1026. hlcg.a_jmp_always(current_asmdata.CurrAsmList,hlabel);
  1027. hlcg.a_label(current_asmdata.CurrAsmList,right.location.falselabel);
  1028. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1029. if left.location.size in [OS_64,OS_S64] then
  1030. cg64.a_load64_const_loc(current_asmdata.CurrAsmList,0,left.location)
  1031. else
  1032. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1033. hlcg.a_load_const_loc(current_asmdata.CurrAsmList,left.resultdef,0,left.location);
  1034. hlcg.a_label(current_asmdata.CurrAsmList,hlabel);
  1035. end;
  1036. {$ifdef cpuflags}
  1037. LOC_FLAGS :
  1038. begin
  1039. if is_pasbool(left.resultdef) then
  1040. begin
  1041. case left.location.loc of
  1042. LOC_REGISTER,LOC_CREGISTER:
  1043. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1044. if left.location.size in [OS_S64,OS_64] then
  1045. begin
  1046. cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,left.location.register64.reglo);
  1047. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1048. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,left.location.register64.reghi);
  1049. end
  1050. else
  1051. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1052. begin
  1053. cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.register);
  1054. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1055. end;
  1056. LOC_REFERENCE:
  1057. { i8086 and i386 have hacks in their code generators so that they can
  1058. deal with 64 bit locations in this parcticular case }
  1059. {$if not defined(cpu64bitalu) and not defined(x86) and not defined(cpuhighleveltarget)}
  1060. if left.location.size in [OS_S64,OS_64] then
  1061. begin
  1062. r64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  1063. r64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  1064. cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,r64.reglo);
  1065. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1066. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,r64.reghi);
  1067. cg64.a_load64_reg_ref(current_asmdata.CurrAsmList,r64,left.location.reference);
  1068. end
  1069. else
  1070. {$endif not cpu64bitalu and not x86 and not cpuhighleveltarget}
  1071. begin
  1072. cg.g_flags2ref(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.reference);
  1073. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1074. end;
  1075. LOC_SUBSETREG,LOC_SUBSETREF:
  1076. begin
  1077. r:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
  1078. cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,r);
  1079. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1080. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,r,left.location);
  1081. end;
  1082. else
  1083. internalerror(200203273);
  1084. end;
  1085. end
  1086. else
  1087. begin
  1088. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1089. if left.location.size in [OS_S64,OS_64] then
  1090. begin
  1091. r64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  1092. r64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  1093. cg.g_flags2reg(current_asmdata.CurrAsmList,OS_32,right.location.resflags,r64.reglo);
  1094. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1095. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,r64.reghi);
  1096. cg64.a_op64_reg_reg(current_asmdata.CurrAsmList,OP_NEG,OS_S64,
  1097. r64,r64);
  1098. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,r64,left.location);
  1099. end
  1100. else
  1101. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1102. begin
  1103. r:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
  1104. cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,r);
  1105. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  1106. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,left.location.size,r,r);
  1107. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,r,left.location);
  1108. end
  1109. end;
  1110. end;
  1111. {$endif cpuflags}
  1112. LOC_VOID:
  1113. ;
  1114. else
  1115. internalerror(2019050706);
  1116. end;
  1117. end;
  1118. if releaseright then
  1119. location_freetemp(current_asmdata.CurrAsmList,right.location);
  1120. end;
  1121. {*****************************************************************************
  1122. SecondArrayConstruct
  1123. *****************************************************************************}
  1124. const
  1125. vtInteger = 0;
  1126. vtBoolean = 1;
  1127. vtChar = 2;
  1128. vtExtended = 3;
  1129. vtString = 4;
  1130. vtPointer = 5;
  1131. vtPChar = 6;
  1132. vtObject = 7;
  1133. vtClass = 8;
  1134. vtWideChar = 9;
  1135. vtPWideChar = 10;
  1136. vtAnsiString32 = 11;
  1137. vtCurrency = 12;
  1138. vtVariant = 13;
  1139. vtInterface = 14;
  1140. vtWideString = 15;
  1141. vtInt64 = 16;
  1142. vtQWord = 17;
  1143. vtUnicodeString = 18;
  1144. vtAnsiString16 = 19;
  1145. vtAnsiString64 = 20;
  1146. procedure tcgarrayconstructornode.makearrayref(var ref: treference; eledef: tdef);
  1147. begin
  1148. { do nothing by default }
  1149. end;
  1150. procedure tcgarrayconstructornode.advancearrayoffset(var ref: treference; elesize: asizeint);
  1151. begin
  1152. ref.alignment:=newalignment(ref.alignment,elesize);
  1153. inc(ref.offset,elesize);
  1154. end;
  1155. procedure tcgarrayconstructornode.pass_generate_code;
  1156. var
  1157. hp : tarrayconstructornode;
  1158. href,
  1159. fref : treference;
  1160. lt : tdef;
  1161. paraloc : tcgparalocation;
  1162. varvtypefield,
  1163. varfield : tfieldvarsym;
  1164. vtype : longint;
  1165. eledef: tdef;
  1166. elesize : longint;
  1167. tmpreg : tregister;
  1168. vaddr : boolean;
  1169. freetemp,
  1170. dovariant: boolean;
  1171. begin
  1172. if is_packed_array(resultdef) then
  1173. internalerror(200608042);
  1174. dovariant:=
  1175. ((nf_forcevaria in flags) or is_variant_array(resultdef)) and
  1176. not(target_info.system in systems_managed_vm);
  1177. eledef:=tarraydef(resultdef).elementdef;
  1178. elesize:=eledef.size;
  1179. if dovariant then
  1180. varvtypefield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VTYPE'))
  1181. else
  1182. varvtypefield:=nil;
  1183. { alignment is filled in by tg.gethltemp below }
  1184. location_reset_ref(location,LOC_CREFERENCE,OS_NO,0,[]);
  1185. fillchar(paraloc,sizeof(paraloc),0);
  1186. { Allocate always a temp, also if no elements are required, to
  1187. be sure that location is valid (PFV) }
  1188. { on the JVM platform, an array can have 0 elements; since the length
  1189. of the array is part of the array itself, make sure we allocate one
  1190. of the proper length to avoid getting unexpected results later --
  1191. allocating a temp of size 0 also forces it to be size 4 on regular
  1192. targets }
  1193. tg.gethltemp(current_asmdata.CurrAsmList,resultdef,(tarraydef(resultdef).highrange+1)*elesize,tt_normal,location.reference);
  1194. href:=location.reference;
  1195. makearrayref(href,eledef);
  1196. { Process nodes in array constructor }
  1197. hp:=self;
  1198. while assigned(hp) do
  1199. begin
  1200. if assigned(hp.left) then
  1201. begin
  1202. freetemp:=true;
  1203. secondpass(hp.left);
  1204. if (hp.left.location.loc=LOC_JUMP)<>
  1205. (hp.left.expectloc=LOC_JUMP) then
  1206. internalerror(2007103101);
  1207. { Move flags and jump in register }
  1208. if hp.left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  1209. hlcg.location_force_reg(current_asmdata.CurrAsmList,hp.left.location,hp.left.resultdef,hp.left.resultdef,false);
  1210. if dovariant then
  1211. begin
  1212. { find the correct vtype value }
  1213. vtype:=$ff;
  1214. varfield:=nil;
  1215. vaddr:=false;
  1216. lt:=hp.left.resultdef;
  1217. case lt.typ of
  1218. enumdef,
  1219. orddef :
  1220. begin
  1221. if is_64bit(lt) then
  1222. begin
  1223. case torddef(lt).ordtype of
  1224. scurrency:
  1225. begin
  1226. vtype:=vtCurrency;
  1227. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VCURRENCY'));
  1228. end;
  1229. s64bit:
  1230. begin
  1231. vtype:=vtInt64;
  1232. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINT64'));
  1233. end;
  1234. u64bit:
  1235. begin
  1236. vtype:=vtQWord;
  1237. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VQWORD'));
  1238. end;
  1239. else
  1240. ;
  1241. end;
  1242. freetemp:=false;
  1243. vaddr:=true;
  1244. end
  1245. else if (lt.typ=enumdef) or
  1246. is_integer(lt) then
  1247. begin
  1248. vtype:=vtInteger;
  1249. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINTEGER'));
  1250. end
  1251. else
  1252. if is_boolean(lt) then
  1253. begin
  1254. vtype:=vtBoolean;
  1255. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINTEGER'));
  1256. end
  1257. else
  1258. if (lt.typ=orddef) then
  1259. begin
  1260. case torddef(lt).ordtype of
  1261. uchar:
  1262. begin
  1263. vtype:=vtChar;
  1264. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINTEGER'));
  1265. end;
  1266. uwidechar:
  1267. begin
  1268. vtype:=vtWideChar;
  1269. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINTEGER'));
  1270. end;
  1271. else
  1272. ;
  1273. end;
  1274. end;
  1275. end;
  1276. floatdef :
  1277. begin
  1278. if is_currency(lt) then
  1279. begin
  1280. vtype:=vtCurrency;
  1281. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VCURRENCY'));
  1282. end
  1283. else
  1284. begin
  1285. vtype:=vtExtended;
  1286. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VEXTENDED'));
  1287. end;
  1288. freetemp:=false;
  1289. vaddr:=true;
  1290. end;
  1291. procvardef,
  1292. pointerdef :
  1293. begin
  1294. if is_pchar(lt) then
  1295. begin
  1296. vtype:=vtPChar;
  1297. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VPCHAR'));
  1298. end
  1299. else if is_pwidechar(lt) then
  1300. begin
  1301. vtype:=vtPWideChar;
  1302. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VPWIDECHAR'));
  1303. end
  1304. else
  1305. begin
  1306. vtype:=vtPointer;
  1307. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VPOINTER'));
  1308. end;
  1309. end;
  1310. variantdef :
  1311. begin
  1312. vtype:=vtVariant;
  1313. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VVARIANT'));
  1314. vaddr:=true;
  1315. freetemp:=false;
  1316. end;
  1317. classrefdef :
  1318. begin
  1319. vtype:=vtClass;
  1320. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VCLASS'));
  1321. end;
  1322. objectdef :
  1323. if is_interface(lt) then
  1324. begin
  1325. vtype:=vtInterface;
  1326. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VINTERFACE'));
  1327. end
  1328. { vtObject really means a class based on TObject }
  1329. else if is_class(lt) then
  1330. begin
  1331. vtype:=vtObject;
  1332. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VOBJECT'));
  1333. end
  1334. else
  1335. internalerror(200505171);
  1336. stringdef :
  1337. begin
  1338. if is_shortstring(lt) then
  1339. begin
  1340. vtype:=vtString;
  1341. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VSTRING'));
  1342. vaddr:=true;
  1343. freetemp:=false;
  1344. end
  1345. else
  1346. if is_ansistring(lt) then
  1347. begin
  1348. vtype:=vtAnsiString;
  1349. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VANSISTRING'));
  1350. freetemp:=false;
  1351. end
  1352. else
  1353. if is_widestring(lt) then
  1354. begin
  1355. vtype:=vtWideString;
  1356. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VWIDESTRING'));
  1357. freetemp:=false;
  1358. end
  1359. else
  1360. if is_unicodestring(lt) then
  1361. begin
  1362. vtype:=vtUnicodeString;
  1363. varfield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VUNICODESTRING'));
  1364. freetemp:=false;
  1365. end;
  1366. end;
  1367. else
  1368. ;
  1369. end;
  1370. if vtype=$ff then
  1371. internalerror(14357);
  1372. if not assigned(varfield) then
  1373. internalerror(2015102901);
  1374. { write changing field update href to the next element }
  1375. fref:=href;
  1376. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,trecorddef(eledef),varfield,fref);
  1377. if vaddr then
  1378. begin
  1379. hlcg.location_force_mem(current_asmdata.CurrAsmList,hp.left.location,lt);
  1380. tmpreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cpointerdef.getreusable(lt));
  1381. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,hp.left.resultdef,cpointerdef.getreusable(lt),hp.left.location.reference,tmpreg);
  1382. hlcg.a_load_reg_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(lt),varfield.vardef,tmpreg,fref);
  1383. end
  1384. else
  1385. hlcg.a_load_loc_ref(current_asmdata.CurrAsmList,hp.left.resultdef,varfield.vardef,hp.left.location,fref);
  1386. { update href to the vtype field and write it }
  1387. fref:=href;
  1388. hlcg.g_set_addr_nonbitpacked_field_ref(current_asmdata.CurrAsmList,trecorddef(eledef),varvtypefield,fref);
  1389. hlcg.a_load_const_ref(current_asmdata.CurrAsmList,varvtypefield.vardef,vtype,fref);
  1390. { goto next array element }
  1391. advancearrayoffset(href,elesize);
  1392. end
  1393. else
  1394. { normal array constructor of the same type }
  1395. begin
  1396. if is_managed_type(resultdef) then
  1397. freetemp:=false;
  1398. case hp.left.location.loc of
  1399. LOC_MMREGISTER,
  1400. LOC_CMMREGISTER:
  1401. hlcg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,hp.left.resultdef,hp.left.resultdef,
  1402. hp.left.location.register,href,mms_movescalar);
  1403. LOC_FPUREGISTER,
  1404. LOC_CFPUREGISTER :
  1405. hlcg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,hp.left.resultdef,hp.left.resultdef,hp.left.location.register,href);
  1406. LOC_REFERENCE,
  1407. LOC_CREFERENCE :
  1408. begin
  1409. if is_shortstring(hp.left.resultdef) then
  1410. hlcg.g_copyshortstring(current_asmdata.CurrAsmList,hp.left.location.reference,href,
  1411. Tstringdef(hp.left.resultdef))
  1412. else
  1413. hlcg.g_concatcopy(current_asmdata.CurrAsmList,eledef,hp.left.location.reference,href);
  1414. end;
  1415. else
  1416. begin
  1417. {$ifndef cpuhighleveltarget}
  1418. {$ifdef cpu64bitalu}
  1419. if hp.left.location.size in [OS_128,OS_S128] then
  1420. cg128.a_load128_loc_ref(current_asmdata.CurrAsmList,hp.left.location,href)
  1421. else
  1422. {$else cpu64bitalu}
  1423. if hp.left.location.size in [OS_64,OS_S64] then
  1424. cg64.a_load64_loc_ref(current_asmdata.CurrAsmList,hp.left.location,href)
  1425. else
  1426. {$endif cpu64bitalu}
  1427. {$endif not cpuhighleveltarget}
  1428. hlcg.a_load_loc_ref(current_asmdata.CurrAsmList,eledef,eledef,hp.left.location,href);
  1429. end;
  1430. end;
  1431. advancearrayoffset(href,elesize);
  1432. end;
  1433. if freetemp then
  1434. location_freetemp(current_asmdata.CurrAsmList,hp.left.location);
  1435. end;
  1436. { load next entry }
  1437. hp:=tarrayconstructornode(hp.right);
  1438. end;
  1439. end;
  1440. {*****************************************************************************
  1441. SecondRTTI
  1442. *****************************************************************************}
  1443. procedure tcgrttinode.pass_generate_code;
  1444. var
  1445. indirect : boolean;
  1446. begin
  1447. indirect := (tf_supports_packages in target_info.flags) and
  1448. (target_info.system in systems_indirect_var_imports) and
  1449. (cs_imported_data in localswitches) and
  1450. (rttidef.owner.moduleid<>current_module.moduleid);
  1451. location_reset_ref(location,LOC_CREFERENCE,OS_NO,sizeof(pint),[]);
  1452. case rttidatatype of
  1453. rdt_normal:
  1454. location.reference.symbol:=RTTIWriter.get_rtti_label(rttidef,rttitype,indirect);
  1455. rdt_ord2str:
  1456. location.reference.symbol:=RTTIWriter.get_rtti_label_ord2str(rttidef,rttitype,indirect);
  1457. rdt_str2ord:
  1458. location.reference.symbol:=RTTIWriter.get_rtti_label_str2ord(rttidef,rttitype,indirect);
  1459. end;
  1460. end;
  1461. begin
  1462. cloadnode:=tcgloadnode;
  1463. cassignmentnode:=tcgassignmentnode;
  1464. carrayconstructornode:=tcgarrayconstructornode;
  1465. crttinode:=tcgrttinode;
  1466. end.