ncgmem.pas 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate assembler for memory related nodes which are
  4. 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 ncgmem;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,cgbase,cgutils,cpuinfo,cpubase,
  23. symtype,
  24. node,nmem;
  25. type
  26. tcgloadvmtaddrnode = class(tloadvmtaddrnode)
  27. procedure pass_generate_code;override;
  28. end;
  29. tcgloadparentfpnode = class(tloadparentfpnode)
  30. procedure pass_generate_code;override;
  31. end;
  32. tcgaddrnode = class(taddrnode)
  33. procedure pass_generate_code;override;
  34. end;
  35. tcgderefnode = class(tderefnode)
  36. procedure pass_generate_code;override;
  37. end;
  38. tcgsubscriptnode = class(tsubscriptnode)
  39. procedure pass_generate_code;override;
  40. end;
  41. tcgwithnode = class(twithnode)
  42. procedure pass_generate_code;override;
  43. end;
  44. tcgvecnode = class(tvecnode)
  45. function get_mul_size : aint;
  46. private
  47. procedure rangecheck_array;
  48. procedure rangecheck_string;
  49. protected
  50. {# This routine is used to calculate the address of the reference.
  51. On entry reg contains the index in the array,
  52. and l contains the size of each element in the array.
  53. This routine should update location.reference correctly,
  54. so it points to the correct address.
  55. }
  56. procedure update_reference_reg_mul(maybe_const_reg: tregister;regsize: tdef; l: aint);virtual;
  57. procedure update_reference_reg_packed(maybe_const_reg: tregister; regsize: tdef; l: aint);virtual;
  58. procedure update_reference_offset(var ref: treference; index, mulsize: aint); virtual;
  59. procedure second_wideansistring;virtual;
  60. procedure second_dynamicarray;virtual;
  61. function valid_index_size(size: tcgsize): boolean;virtual;
  62. public
  63. procedure pass_generate_code;override;
  64. end;
  65. implementation
  66. uses
  67. systems,
  68. cutils,cclasses,verbose,globals,constexp,
  69. symconst,symbase,symdef,symsym,symcpu,symtable,defutil,paramgr,
  70. aasmbase,aasmtai,aasmdata,
  71. procinfo,pass_2,parabase,
  72. pass_1,nld,ncon,nadd,ncnv,nutils,
  73. cgobj,hlcgobj,
  74. tgobj,ncgutil,objcgutl,
  75. defcmp
  76. ;
  77. {*****************************************************************************
  78. TCGLOADVMTADDRNODE
  79. *****************************************************************************}
  80. procedure tcgloadvmtaddrnode.pass_generate_code;
  81. var
  82. href : treference;
  83. pool : THashSet;
  84. entry : PHashSetItem;
  85. begin
  86. location_reset(location,LOC_REGISTER,def_cgsize(voidpointertype));
  87. if (left.nodetype=typen) then
  88. begin
  89. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,voidpointertype);
  90. if not is_objcclass(left.resultdef) then
  91. begin
  92. reference_reset_symbol(href,
  93. current_asmdata.RefAsmSymbol(tobjectdef(tclassrefdef(resultdef).pointeddef).vmt_mangledname,AT_DATA),0,
  94. voidpointertype.size);
  95. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,voidpointertype,voidpointertype,href,location.register);
  96. end
  97. else
  98. begin
  99. pool:=current_asmdata.ConstPools[sp_objcclassnamerefs];
  100. entry:=pool.FindOrAdd(@tobjectdef(left.resultdef).objextname^[1],length(tobjectdef(left.resultdef).objextname^));
  101. if (target_info.system in systems_objc_nfabi) then
  102. begin
  103. { find/add necessary classref/classname pool entries }
  104. objcfinishclassrefnfpoolentry(entry,tobjectdef(left.resultdef));
  105. end
  106. else
  107. begin
  108. { find/add necessary classref/classname pool entries }
  109. objcfinishstringrefpoolentry(entry,sp_objcclassnames,sec_objc_cls_refs,sec_objc_class_names);
  110. end;
  111. reference_reset_symbol(href,tasmlabel(entry^.Data),0,voidpointertype.size);
  112. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,voidpointertype,voidpointertype,href,location.register);
  113. end;
  114. end
  115. else
  116. begin
  117. { left contains self, load vmt from self }
  118. secondpass(left);
  119. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(left.resultdef),left.location,location.register);
  120. end;
  121. end;
  122. {*****************************************************************************
  123. TCGLOADPARENTFPNODE
  124. *****************************************************************************}
  125. procedure tcgloadparentfpnode.pass_generate_code;
  126. var
  127. currpi : tprocinfo;
  128. hsym : tparavarsym;
  129. href : treference;
  130. begin
  131. if (current_procinfo.procdef.parast.symtablelevel=parentpd.parast.symtablelevel) then
  132. begin
  133. location_reset(location,LOC_REGISTER,def_cgsize(parentfpvoidpointertype));
  134. location.register:=current_procinfo.framepointer;
  135. end
  136. else
  137. begin
  138. currpi:=current_procinfo;
  139. location_reset(location,LOC_REGISTER,def_cgsize(parentfpvoidpointertype));
  140. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,parentfpvoidpointertype);
  141. { load framepointer of current proc }
  142. hsym:=tparavarsym(currpi.procdef.parast.Find('parentfp'));
  143. if not assigned(hsym) then
  144. internalerror(200309281);
  145. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,parentfpvoidpointertype,parentfpvoidpointertype,hsym.localloc,location.register);
  146. { walk parents }
  147. while (currpi.procdef.owner.symtablelevel>parentpd.parast.symtablelevel) do
  148. begin
  149. currpi:=currpi.parent;
  150. if not assigned(currpi) then
  151. internalerror(200311201);
  152. hsym:=tparavarsym(currpi.procdef.parast.Find('parentfp'));
  153. if not assigned(hsym) then
  154. internalerror(200309282);
  155. if hsym.localloc.loc<>LOC_REFERENCE then
  156. internalerror(200309283);
  157. hlcg.reference_reset_base(href,parentfpvoidpointertype,location.register,hsym.localloc.reference.offset,sizeof(pint));
  158. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,parentfpvoidpointertype,parentfpvoidpointertype,href,location.register);
  159. end;
  160. end;
  161. end;
  162. {*****************************************************************************
  163. TCGADDRNODE
  164. *****************************************************************************}
  165. procedure tcgaddrnode.pass_generate_code;
  166. begin
  167. secondpass(left);
  168. location_reset(location,LOC_REGISTER,int_cgsize(resultdef.size));
  169. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,resultdef);
  170. if not(left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  171. { on x86_64-win64, array of chars can be returned in registers, however,
  172. when passing these arrays to other functions, the compiler wants to take
  173. the address of the array so when the addrnode has been created internally,
  174. we have to force the data into memory, see also tw14388.pp
  175. }
  176. if nf_internal in flags then
  177. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef)
  178. else
  179. internalerror(2006111510);
  180. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.resultdef,resultdef,left.location.reference,location.register);
  181. end;
  182. {*****************************************************************************
  183. TCGDEREFNODE
  184. *****************************************************************************}
  185. procedure tcgderefnode.pass_generate_code;
  186. var
  187. paraloc1 : tcgpara;
  188. pd : tprocdef;
  189. sym : tsym;
  190. st : tsymtable;
  191. hp : pnode;
  192. hp2 : tnode;
  193. extraoffset : tcgint;
  194. begin
  195. sym:=nil;
  196. { assume natural alignment, except for packed records }
  197. if not(resultdef.typ in [recorddef,objectdef]) or
  198. (tabstractrecordsymtable(tabstractrecorddef(resultdef).symtable).usefieldalignment<>1) then
  199. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),resultdef.alignment)
  200. else
  201. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),1);
  202. { can we fold an add/sub node into the offset of the deref node? }
  203. extraoffset:=0;
  204. hp:=actualtargetnode(@left);
  205. if (hp^.nodetype=subn) and is_constintnode(taddnode(hp^).right) then
  206. begin
  207. extraoffset:=-tcgint(tordconstnode(taddnode(hp^).right).value);
  208. replacenode(hp^,taddnode(hp^).left);
  209. end
  210. else if (hp^.nodetype=addn) and is_constintnode(taddnode(hp^).right) then
  211. begin
  212. extraoffset:=tcgint(tordconstnode(taddnode(hp^).right).value);
  213. replacenode(hp^,taddnode(hp^).left);
  214. end
  215. else if (hp^.nodetype=addn) and is_constintnode(taddnode(hp^).left) then
  216. begin
  217. extraoffset:=tcgint(tordconstnode(taddnode(hp^).left).value);
  218. replacenode(hp^,taddnode(hp^).right);
  219. end;
  220. secondpass(left);
  221. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE,LOC_CONSTANT]) then
  222. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  223. case left.location.loc of
  224. LOC_CREGISTER,
  225. LOC_REGISTER:
  226. begin
  227. hlcg.maybe_change_load_node_reg(current_asmdata.CurrAsmList,left,true);
  228. {$ifdef cpu_uses_separate_address_registers}
  229. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  230. begin
  231. location.reference.base := cg.getaddressregister(current_asmdata.CurrAsmList);
  232. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,
  233. location.reference.base);
  234. end
  235. else
  236. {$endif}
  237. location.reference.base := left.location.register;
  238. end;
  239. LOC_CREFERENCE,
  240. LOC_REFERENCE:
  241. begin
  242. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  243. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location,location.reference.base);
  244. end;
  245. LOC_CONSTANT:
  246. begin
  247. location.reference.offset:=left.location.value;
  248. end;
  249. else
  250. internalerror(200507031);
  251. end;
  252. location.reference.offset:=location.reference.offset+extraoffset;
  253. if (cs_use_heaptrc in current_settings.globalswitches) and
  254. (cs_checkpointer in current_settings.localswitches) and
  255. not(cs_compilesystem in current_settings.moduleswitches) and
  256. {$ifdef x86}
  257. (tcpupointerdef(left.resultdef).x86pointertyp = tcpupointerdefclass(cpointerdef).default_x86_data_pointer_type) and
  258. {$endif x86}
  259. not(nf_no_checkpointer in flags) and
  260. { can be NR_NO in case of LOC_CONSTANT }
  261. (location.reference.base<>NR_NO) then
  262. begin
  263. if not searchsym_in_named_module('HEAPTRC','CHECKPOINTER',sym,st) or
  264. (sym.typ<>procsym) then
  265. internalerror(2012010601);
  266. pd:=tprocdef(tprocsym(sym).ProcdefList[0]);
  267. paraloc1.init;
  268. paramanager.getintparaloc(pd,1,paraloc1);
  269. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,left.resultdef,location.reference.base,paraloc1);
  270. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  271. paraloc1.done;
  272. hlcg.allocallcpuregisters(current_asmdata.CurrAsmList);
  273. hlcg.a_call_name(current_asmdata.CurrAsmList,pd,'FPC_CHECKPOINTER',nil,false);
  274. hlcg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  275. end;
  276. end;
  277. {*****************************************************************************
  278. TCGSUBSCRIPTNODE
  279. *****************************************************************************}
  280. procedure tcgsubscriptnode.pass_generate_code;
  281. var
  282. asmsym: tasmsymbol;
  283. paraloc1 : tcgpara;
  284. tmpref: treference;
  285. sref: tsubsetreference;
  286. awordoffset,
  287. offsetcorrection : aint;
  288. pd : tprocdef;
  289. sym : tsym;
  290. st : tsymtable;
  291. begin
  292. sym:=nil;
  293. secondpass(left);
  294. if codegenerror then
  295. exit;
  296. paraloc1.init;
  297. { several object types must be dereferenced implicitly }
  298. if is_implicit_pointer_object_type(left.resultdef) then
  299. begin
  300. if (not is_managed_type(left.resultdef)) or
  301. (target_info.system in systems_garbage_collected_managed_types) then
  302. begin
  303. { the contents of a class are aligned to a sizeof(pointer) }
  304. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),voidpointertype.size);
  305. case left.location.loc of
  306. LOC_CREGISTER,
  307. LOC_REGISTER:
  308. begin
  309. {$ifdef cpu_uses_separate_address_registers}
  310. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  311. begin
  312. location.reference.base:=rg.getaddressregister(current_asmdata.CurrAsmList);
  313. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,
  314. left.location.register,location.reference.base);
  315. end
  316. else
  317. {$endif}
  318. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  319. end;
  320. LOC_CREFERENCE,
  321. LOC_REFERENCE,
  322. { tricky type casting of parameters can cause these locations, see tb0592.pp on x86_64-linux }
  323. LOC_SUBSETREG,
  324. LOC_CSUBSETREG,
  325. LOC_SUBSETREF,
  326. LOC_CSUBSETREF:
  327. begin
  328. hlcg.reference_reset_base(location.reference,left.resultdef,
  329. hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  330. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location,location.reference.base);
  331. end;
  332. LOC_CONSTANT:
  333. begin
  334. { can happen with @classtype(pointerconst).field }
  335. location.reference.offset:=left.location.value;
  336. end;
  337. else
  338. internalerror(2009092401);
  339. end;
  340. { implicit deferencing }
  341. if (cs_use_heaptrc in current_settings.globalswitches) and
  342. (cs_checkpointer in current_settings.localswitches) and
  343. not(cs_compilesystem in current_settings.moduleswitches) then
  344. begin
  345. if not searchsym_in_named_module('HEAPTRC','CHECKPOINTER',sym,st) or
  346. (sym.typ<>procsym) then
  347. internalerror(2012010602);
  348. pd:=tprocdef(tprocsym(sym).ProcdefList[0]);
  349. paramanager.getintparaloc(pd,1,paraloc1);
  350. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,left.resultdef,location.reference.base,paraloc1);
  351. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  352. hlcg.allocallcpuregisters(current_asmdata.CurrAsmList);
  353. hlcg.a_call_name(current_asmdata.CurrAsmList,pd,'FPC_CHECKPOINTER',nil,false);
  354. hlcg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  355. end;
  356. end
  357. else
  358. { reference-counted implicit pointer object types don't have
  359. fields -> cannot be subscripted (calls are handled via call
  360. nodes) }
  361. internalerror(2011011901);
  362. end
  363. else
  364. begin
  365. location_copy(location,left.location);
  366. { some abi's require that functions return (some) records in }
  367. { registers }
  368. case location.loc of
  369. LOC_REFERENCE,
  370. LOC_CREFERENCE:
  371. ;
  372. LOC_CONSTANT,
  373. LOC_REGISTER,
  374. LOC_CREGISTER,
  375. { if a floating point value is casted into a record, it
  376. can happen that we get here an fpu or mm register }
  377. LOC_MMREGISTER,
  378. LOC_FPUREGISTER,
  379. LOC_CMMREGISTER,
  380. LOC_CFPUREGISTER:
  381. begin
  382. { in case the result is not something that can be put
  383. into an integer register (e.g.
  384. function_returning_record().non_regable_field, or
  385. a function returning a value > sizeof(intreg))
  386. -> force to memory
  387. }
  388. if not tstoreddef(left.resultdef).is_intregable or
  389. not tstoreddef(resultdef).is_intregable or
  390. { if the field spans multiple registers, we must force the record into
  391. memory as well }
  392. ((left.location.size in [OS_PAIR,OS_SPAIR]) and
  393. (vs.fieldoffset div sizeof(aword)<>(vs.fieldoffset+vs.getsize-1) div sizeof(aword))) or
  394. (location.loc in [LOC_MMREGISTER,LOC_FPUREGISTER,LOC_CMMREGISTER,LOC_CFPUREGISTER,
  395. { actually, we should be able to "subscript" a constant, but this would require some code
  396. which enables dumping and reading constants from a temporary memory buffer. This
  397. must be done a CPU dependent way, so it is not easy and probably not worth the effort (FK)
  398. }
  399. LOC_CONSTANT]) then
  400. hlcg.location_force_mem(current_asmdata.CurrAsmList,location,left.resultdef)
  401. else
  402. begin
  403. if (left.location.loc = LOC_REGISTER) then
  404. location.loc := LOC_SUBSETREG
  405. else
  406. location.loc := LOC_CSUBSETREG;
  407. location.size:=def_cgsize(resultdef);
  408. offsetcorrection:=0;
  409. if (left.location.size in [OS_PAIR,OS_SPAIR]) then
  410. begin
  411. if not is_packed_record_or_object(left.resultdef) then
  412. awordoffset:=sizeof(aword)
  413. else
  414. awordoffset:=sizeof(aword)*8;
  415. if (vs.fieldoffset>=awordoffset) xor (target_info.endian=endian_big) then
  416. location.sreg.subsetreg := left.location.registerhi
  417. else
  418. location.sreg.subsetreg := left.location.register;
  419. if vs.fieldoffset>=awordoffset then
  420. offsetcorrection := sizeof(aword)*8;
  421. location.sreg.subsetregsize := OS_INT;
  422. end
  423. else
  424. begin
  425. location.sreg.subsetreg := left.location.register;
  426. location.sreg.subsetregsize := left.location.size;
  427. end;
  428. if not is_packed_record_or_object(left.resultdef) then
  429. begin
  430. if (target_info.endian = ENDIAN_BIG) then
  431. location.sreg.startbit := (tcgsize2size[location.sreg.subsetregsize] - tcgsize2size[location.size] - vs.fieldoffset) * 8+offsetcorrection
  432. else
  433. location.sreg.startbit := (vs.fieldoffset * 8)-offsetcorrection;
  434. location.sreg.bitlen := tcgsize2size[location.size] * 8;
  435. end
  436. else
  437. begin
  438. location.sreg.bitlen := resultdef.packedbitsize;
  439. if (target_info.endian = ENDIAN_BIG) then
  440. location.sreg.startbit := (tcgsize2size[location.sreg.subsetregsize]*8 - location.sreg.bitlen) - vs.fieldoffset+offsetcorrection
  441. else
  442. location.sreg.startbit := vs.fieldoffset-offsetcorrection;
  443. end;
  444. end;
  445. end;
  446. LOC_SUBSETREG,
  447. LOC_CSUBSETREG:
  448. begin
  449. location.size:=def_cgsize(resultdef);
  450. if not is_packed_record_or_object(left.resultdef) then
  451. begin
  452. if (target_info.endian = ENDIAN_BIG) then
  453. inc(location.sreg.startbit, (left.resultdef.size - tcgsize2size[location.size] - vs.fieldoffset) * 8)
  454. else
  455. inc(location.sreg.startbit, vs.fieldoffset * 8);
  456. location.sreg.bitlen := tcgsize2size[location.size] * 8;
  457. end
  458. else
  459. begin
  460. location.sreg.bitlen := resultdef.packedbitsize;
  461. if (target_info.endian = ENDIAN_BIG) then
  462. inc(location.sreg.startbit, left.location.sreg.bitlen - location.sreg.bitlen - vs.fieldoffset)
  463. else
  464. inc(location.sreg.startbit, vs.fieldoffset);
  465. end;
  466. end;
  467. else
  468. internalerror(2006031901);
  469. end;
  470. end;
  471. if is_objc_class_or_protocol(left.resultdef) and
  472. (target_info.system in systems_objc_nfabi) then
  473. begin
  474. if (location.loc<>LOC_REFERENCE) or
  475. (location.reference.index<>NR_NO) then
  476. internalerror(2009092402);
  477. { the actual field offset is stored in memory (to solve the
  478. "fragile base class" problem: this way the layout of base
  479. classes can be changed without breaking programs compiled against
  480. earlier versions)
  481. }
  482. asmsym:=current_asmdata.RefAsmSymbol(vs.mangledname);
  483. reference_reset_symbol(tmpref,asmsym,0,sizeof(pint));
  484. location.reference.index:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
  485. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,ptruinttype,ptruinttype,tmpref,location.reference.index);
  486. { always packrecords C -> natural alignment }
  487. location.reference.alignment:=vs.vardef.alignment;
  488. end
  489. else if is_java_class_or_interface(left.resultdef) or
  490. ((target_info.system in systems_jvm) and
  491. (left.resultdef.typ=recorddef)) then
  492. begin
  493. if (location.loc<>LOC_REFERENCE) or
  494. (location.reference.index<>NR_NO) or
  495. assigned(location.reference.symbol) then
  496. internalerror(2011011301);
  497. location.reference.symbol:=current_asmdata.RefAsmSymbol(vs.mangledname);
  498. end
  499. else if (location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  500. begin
  501. if not is_packed_record_or_object(left.resultdef) then
  502. begin
  503. inc(location.reference.offset,vs.fieldoffset);
  504. location.reference.alignment:=newalignment(location.reference.alignment,vs.fieldoffset);
  505. end
  506. else if (vs.fieldoffset mod 8 = 0) and
  507. (resultdef.packedbitsize mod 8 = 0) and
  508. { is different in case of e.g. packenum 2 and an enum }
  509. { which fits in 8 bits }
  510. (resultdef.size*8 = resultdef.packedbitsize) then
  511. begin
  512. inc(location.reference.offset,vs.fieldoffset div 8);
  513. location.reference.alignment:=newalignment(location.reference.alignment,vs.fieldoffset div 8);
  514. end
  515. else
  516. begin
  517. sref.ref:=location.reference;
  518. sref.ref.alignment:=1;
  519. sref.bitindexreg:=NR_NO;
  520. inc(sref.ref.offset,vs.fieldoffset div 8);
  521. sref.startbit:=vs.fieldoffset mod 8;
  522. sref.bitlen:=resultdef.packedbitsize;
  523. if (left.location.loc=LOC_REFERENCE) then
  524. location.loc:=LOC_SUBSETREF
  525. else
  526. location.loc:=LOC_CSUBSETREF;
  527. location.sref:=sref;
  528. end;
  529. { also update the size of the location }
  530. location.size:=def_cgsize(resultdef);
  531. end;
  532. paraloc1.done;
  533. end;
  534. {*****************************************************************************
  535. TCGWITHNODE
  536. *****************************************************************************}
  537. procedure tcgwithnode.pass_generate_code;
  538. begin
  539. location_reset(location,LOC_VOID,OS_NO);
  540. if assigned(left) then
  541. secondpass(left);
  542. end;
  543. {*****************************************************************************
  544. TCGVECNODE
  545. *****************************************************************************}
  546. function tcgvecnode.get_mul_size : aint;
  547. begin
  548. if nf_memindex in flags then
  549. get_mul_size:=1
  550. else
  551. begin
  552. if (left.resultdef.typ=arraydef) then
  553. if not is_packed_array(left.resultdef) then
  554. get_mul_size:=tarraydef(left.resultdef).elesize
  555. else
  556. get_mul_size:=tarraydef(left.resultdef).elepackedbitsize
  557. else
  558. get_mul_size:=resultdef.size;
  559. end
  560. end;
  561. { this routine must, like any other routine, not change the contents }
  562. { of base/index registers of references, as these may be regvars. }
  563. { The register allocator can coalesce one LOC_REGISTER being moved }
  564. { into another (as their live ranges won't overlap), but not a }
  565. { LOC_CREGISTER moved into a LOC_(C)REGISTER most of the time (as }
  566. { the live range of the LOC_CREGISTER will most likely overlap the }
  567. { the live range of the target LOC_(C)REGISTER) }
  568. { The passed register may be a LOC_CREGISTER as well. }
  569. procedure tcgvecnode.update_reference_reg_mul(maybe_const_reg: tregister; regsize: tdef; l: aint);
  570. var
  571. hreg: tregister;
  572. begin
  573. if l<>1 then
  574. begin
  575. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  576. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_ADDR,l,maybe_const_reg,hreg);
  577. maybe_const_reg:=hreg;
  578. end;
  579. if location.reference.base=NR_NO then
  580. location.reference.base:=maybe_const_reg
  581. else if location.reference.index=NR_NO then
  582. location.reference.index:=maybe_const_reg
  583. else
  584. begin
  585. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  586. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,location.reference,hreg);
  587. reference_reset_base(location.reference,hreg,0,location.reference.alignment);
  588. { insert new index register }
  589. location.reference.index:=maybe_const_reg;
  590. end;
  591. { update alignment }
  592. if (location.reference.alignment=0) then
  593. internalerror(2009020704);
  594. location.reference.alignment:=newalignment(location.reference.alignment,l);
  595. end;
  596. { see remarks for tcgvecnode.update_reference_reg_mul above }
  597. procedure tcgvecnode.update_reference_reg_packed(maybe_const_reg: tregister; regsize: tdef; l:aint);
  598. var
  599. sref: tsubsetreference;
  600. offsetreg, hreg: tregister;
  601. alignpower: aint;
  602. temp : longint;
  603. begin
  604. { only orddefs are bitpacked. Even then we only need special code in }
  605. { case the bitpacked *byte size* is not a power of two, otherwise }
  606. { everything can be handled using the the regular array code. }
  607. if ((l mod 8) = 0) and
  608. (ispowerof2(l div 8,temp) or
  609. not is_ordinal(resultdef)
  610. {$ifndef cpu64bitalu}
  611. or is_64bitint(resultdef)
  612. {$endif not cpu64bitalu}
  613. ) then
  614. begin
  615. update_reference_reg_mul(maybe_const_reg,regsize,l div 8);
  616. exit;
  617. end;
  618. if (l > 8*sizeof(aint)) then
  619. internalerror(200608051);
  620. sref.ref := location.reference;
  621. hreg := cg.getaddressregister(current_asmdata.CurrAsmList);
  622. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,tarraydef(left.resultdef).lowrange,maybe_const_reg,hreg);
  623. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_INT,l,hreg);
  624. { keep alignment for index }
  625. sref.ref.alignment := left.resultdef.alignment;
  626. if not ispowerof2(packedbitsloadsize(l),temp) then
  627. internalerror(2006081201);
  628. alignpower:=temp;
  629. offsetreg := cg.getaddressregister(current_asmdata.CurrAsmList);
  630. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_ADDR,3+alignpower,hreg,offsetreg);
  631. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHL,OS_ADDR,alignpower,offsetreg);
  632. if (sref.ref.base = NR_NO) then
  633. sref.ref.base := offsetreg
  634. else if (sref.ref.index = NR_NO) then
  635. sref.ref.index := offsetreg
  636. else
  637. begin
  638. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_ADD,OS_ADDR,sref.ref.base,offsetreg);
  639. sref.ref.base := offsetreg;
  640. end;
  641. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,(1 shl (3+alignpower))-1,hreg);
  642. sref.bitindexreg := hreg;
  643. sref.startbit := 0;
  644. sref.bitlen := resultdef.packedbitsize;
  645. if (left.location.loc = LOC_REFERENCE) then
  646. location.loc := LOC_SUBSETREF
  647. else
  648. location.loc := LOC_CSUBSETREF;
  649. location.sref := sref;
  650. end;
  651. procedure tcgvecnode.update_reference_offset(var ref: treference; index, mulsize: aint);
  652. begin
  653. inc(ref.offset,index*mulsize);
  654. end;
  655. procedure tcgvecnode.second_wideansistring;
  656. begin
  657. end;
  658. procedure tcgvecnode.second_dynamicarray;
  659. begin
  660. end;
  661. function tcgvecnode.valid_index_size(size: tcgsize): boolean;
  662. begin
  663. result:=
  664. tcgsize2signed[size]=tcgsize2signed[OS_ADDR];
  665. end;
  666. procedure tcgvecnode.rangecheck_array;
  667. var
  668. hightree : tnode;
  669. poslabel,
  670. neglabel : tasmlabel;
  671. hreg : tregister;
  672. paraloc1,paraloc2 : tcgpara;
  673. pd : tprocdef;
  674. begin
  675. { omit range checking when this is an array access to a pointer which has been
  676. typecasted from an array }
  677. if (ado_isconvertedpointer in tarraydef(left.resultdef).arrayoptions) then
  678. exit;
  679. paraloc1.init;
  680. paraloc2.init;
  681. if is_open_array(left.resultdef) or
  682. is_array_of_const(left.resultdef) then
  683. begin
  684. { cdecl functions don't have high() so we can not check the range }
  685. { (can't use current_procdef, since it may be a nested procedure) }
  686. if not(tprocdef(tparasymtable(tparavarsym(tloadnode(get_open_const_array(left)).symtableentry).owner).defowner).proccalloption in cdecl_pocalls) then
  687. begin
  688. { Get high value }
  689. hightree:=load_high_value_node(tparavarsym(tloadnode(get_open_const_array(left)).symtableentry));
  690. { it must be available }
  691. if not assigned(hightree) then
  692. internalerror(200212201);
  693. firstpass(hightree);
  694. secondpass(hightree);
  695. { generate compares }
  696. if (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  697. hreg:=cg.makeregsize(current_asmdata.CurrAsmList,right.location.register,OS_INT)
  698. else
  699. begin
  700. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  701. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,right.resultdef,osuinttype,right.location,hreg);
  702. end;
  703. current_asmdata.getjumplabel(neglabel);
  704. current_asmdata.getjumplabel(poslabel);
  705. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_LT,0,hreg,poslabel);
  706. cg.a_cmp_loc_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_BE,hightree.location,hreg,neglabel);
  707. cg.a_label(current_asmdata.CurrAsmList,poslabel);
  708. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RANGEERROR',false);
  709. cg.a_label(current_asmdata.CurrAsmList,neglabel);
  710. { release hightree }
  711. hightree.free;
  712. end;
  713. end
  714. else
  715. if is_dynamic_array(left.resultdef) then
  716. begin
  717. pd:=search_system_proc('fpc_dynarray_rangecheck');
  718. paramanager.getintparaloc(pd,1,paraloc1);
  719. paramanager.getintparaloc(pd,2,paraloc2);
  720. if pd.is_pushleftright then
  721. begin
  722. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  723. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  724. end
  725. else
  726. begin
  727. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  728. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  729. end;
  730. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  731. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  732. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  733. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DYNARRAY_RANGECHECK',false);
  734. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  735. end;
  736. { for regular arrays, we don't have to do anything because the index has been
  737. type converted to the index type, which already inserted a range check if
  738. necessary }
  739. paraloc1.done;
  740. paraloc2.done;
  741. end;
  742. procedure tcgvecnode.rangecheck_string;
  743. var
  744. paraloc1,
  745. paraloc2: tcgpara;
  746. helpername: TIDString;
  747. pd: tprocdef;
  748. begin
  749. paraloc1.init;
  750. paraloc2.init;
  751. case tstringdef(left.resultdef).stringtype of
  752. { it's the same for ansi- and wide strings }
  753. st_unicodestring,
  754. st_widestring,
  755. st_ansistring:
  756. begin
  757. helpername:='fpc_'+tstringdef(left.resultdef).stringtypname+'_rangecheck';
  758. pd:=search_system_proc(helpername);
  759. paramanager.getintparaloc(pd,1,paraloc1);
  760. paramanager.getintparaloc(pd,2,paraloc2);
  761. if pd.is_pushleftright then
  762. begin
  763. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  764. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  765. end
  766. else
  767. begin
  768. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  769. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  770. end;
  771. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  772. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  773. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  774. cg.a_call_name(current_asmdata.CurrAsmList,helpername,false);
  775. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  776. end;
  777. st_shortstring:
  778. begin
  779. {!!!!!!!!!!!!!!!!!}
  780. { if this one is implemented making use of the high parameter for openshortstrings, update ncgutils.do_get_used_regvars() too (JM) }
  781. end;
  782. st_longstring:
  783. begin
  784. {!!!!!!!!!!!!!!!!!}
  785. end;
  786. end;
  787. paraloc1.done;
  788. paraloc2.done;
  789. end;
  790. procedure tcgvecnode.pass_generate_code;
  791. var
  792. offsetdec,
  793. extraoffset : aint;
  794. rightp : pnode;
  795. otl,ofl : tasmlabel;
  796. newsize : tcgsize;
  797. mulsize,
  798. bytemulsize,
  799. alignpow : aint;
  800. isjump : boolean;
  801. paraloc1,
  802. paraloc2 : tcgpara;
  803. subsetref : tsubsetreference;
  804. temp : longint;
  805. indexdef : tdef;
  806. begin
  807. paraloc1.init;
  808. paraloc2.init;
  809. mulsize:=get_mul_size;
  810. if not is_packed_array(left.resultdef) then
  811. bytemulsize:=mulsize
  812. else
  813. bytemulsize:=mulsize div 8;
  814. newsize:=def_cgsize(resultdef);
  815. secondpass(left);
  816. if left.location.loc=LOC_CREFERENCE then
  817. location_reset_ref(location,LOC_CREFERENCE,newsize,left.location.reference.alignment)
  818. else
  819. location_reset_ref(location,LOC_REFERENCE,newsize,left.location.reference.alignment);
  820. { an ansistring needs to be dereferenced }
  821. if is_ansistring(left.resultdef) or
  822. is_wide_or_unicode_string(left.resultdef) then
  823. begin
  824. if nf_callunique in flags then
  825. internalerror(200304236);
  826. {DM!!!!!}
  827. case left.location.loc of
  828. LOC_REGISTER,
  829. LOC_CREGISTER :
  830. begin
  831. {$ifdef m68k}
  832. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  833. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,location.reference.base);
  834. {$else m68k}
  835. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  836. {$endif m68k}
  837. end;
  838. LOC_CREFERENCE,
  839. LOC_REFERENCE :
  840. begin
  841. hlcg.reference_reset_base(location.reference,left.resultdef,hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  842. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location.reference,location.reference.base);
  843. end;
  844. LOC_CONSTANT:
  845. begin
  846. hlcg.reference_reset_base(location.reference,left.resultdef,NR_NO,left.location.value,location.reference.alignment);
  847. end;
  848. else
  849. internalerror(2002032218);
  850. end;
  851. if is_ansistring(left.resultdef) then
  852. offsetdec:=1
  853. else
  854. offsetdec:=2;
  855. location.reference.alignment:=offsetdec;
  856. { in ansistrings/widestrings S[1] is p<w>char(S)[0] }
  857. if not(cs_zerobasedstrings in current_settings.localswitches) then
  858. update_reference_offset(location.reference,-1,offsetdec);
  859. end
  860. else if is_dynamic_array(left.resultdef) then
  861. begin
  862. case left.location.loc of
  863. LOC_REGISTER,
  864. LOC_CREGISTER :
  865. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  866. LOC_REFERENCE,
  867. LOC_CREFERENCE :
  868. begin
  869. hlcg.reference_reset_base(location.reference,left.resultdef,hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  870. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,
  871. left.location.reference,location.reference.base);
  872. end;
  873. else
  874. internalerror(2002032219);
  875. end;
  876. { a dynarray points to the start of a memory block, which
  877. we assume to be always aligned to a multiple of the
  878. pointer size
  879. }
  880. location.reference.alignment:=voidpointertype.size;
  881. end
  882. else
  883. begin
  884. { may happen in case of function results }
  885. case left.location.loc of
  886. LOC_CSUBSETREG,
  887. LOC_CREGISTER,
  888. LOC_CMMREGISTER,
  889. LOC_SUBSETREG,
  890. LOC_REGISTER,
  891. LOC_MMREGISTER:
  892. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  893. end;
  894. location_copy(location,left.location);
  895. end;
  896. { location must be memory }
  897. if not(location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  898. internalerror(200411013);
  899. { offset can only differ from 0 if arraydef }
  900. if (left.resultdef.typ=arraydef) and
  901. not(is_dynamic_array(left.resultdef)) and
  902. (not(is_packed_array(left.resultdef)) or
  903. ((mulsize mod 8 = 0) and
  904. ispowerof2(mulsize div 8,temp)) or
  905. { only orddefs are bitpacked }
  906. not is_ordinal(resultdef)
  907. {$ifndef cpu64bitalu}
  908. or is_64bitint(resultdef)
  909. {$endif not cpu64bitalu}
  910. ) then
  911. update_reference_offset(location.reference,-tarraydef(left.resultdef).lowrange,bytemulsize);
  912. if right.nodetype=ordconstn then
  913. begin
  914. { offset can only differ from 0 if arraydef }
  915. if cs_check_range in current_settings.localswitches then
  916. begin
  917. secondpass(right);
  918. case left.resultdef.typ of
  919. arraydef :
  920. rangecheck_array;
  921. stringdef :
  922. rangecheck_string;
  923. end;
  924. end;
  925. if not(is_packed_array(left.resultdef)) or
  926. ((mulsize mod 8 = 0) and
  927. (ispowerof2(mulsize div 8,temp) or
  928. { only orddefs are bitpacked }
  929. not is_ordinal(resultdef))) then
  930. begin
  931. extraoffset:=tordconstnode(right).value.svalue;
  932. update_reference_offset(location.reference,extraoffset,bytemulsize);
  933. { adjust alignment after this change }
  934. location.reference.alignment:=newalignment(location.reference.alignment,extraoffset*bytemulsize);
  935. { don't do this for floats etc.; needed to properly set the }
  936. { size for bitpacked arrays (e.g. a bitpacked array of }
  937. { enums who are size 2 but fit in one byte -> in the array }
  938. { they will be one byte and have to be stored like that) }
  939. if is_packed_array(left.resultdef) and
  940. (tcgsize2size[newsize] <> bytemulsize) then
  941. newsize:=int_cgsize(bytemulsize);
  942. end
  943. else
  944. begin
  945. subsetref.ref := location.reference;
  946. subsetref.ref.alignment := left.resultdef.alignment;
  947. if not ispowerof2(packedbitsloadsize(resultdef.packedbitsize),temp) then
  948. internalerror(2006081212);
  949. alignpow:=temp;
  950. update_reference_offset(subsetref.ref,(mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) shr (3+alignpow),1 shl alignpow);
  951. subsetref.bitindexreg := NR_NO;
  952. subsetref.startbit := (mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) and ((1 shl (3+alignpow))-1);
  953. subsetref.bitlen := resultdef.packedbitsize;
  954. if (left.location.loc = LOC_REFERENCE) then
  955. location.loc := LOC_SUBSETREF
  956. else
  957. location.loc := LOC_CSUBSETREF;
  958. location.sref := subsetref;
  959. end;
  960. end
  961. else
  962. { not nodetype=ordconstn }
  963. begin
  964. if (cs_opt_level1 in current_settings.optimizerswitches) and
  965. { if we do range checking, we don't }
  966. { need that fancy code (it would be }
  967. { buggy) }
  968. not(cs_check_range in current_settings.localswitches) and
  969. (left.resultdef.typ=arraydef) and
  970. not is_packed_array(left.resultdef) then
  971. begin
  972. extraoffset:=0;
  973. rightp:=actualtargetnode(@right);
  974. if rightp^.nodetype=addn then
  975. begin
  976. if taddnode(rightp^).right.nodetype=ordconstn then
  977. begin
  978. extraoffset:=tordconstnode(taddnode(rightp^).right).value.svalue;
  979. replacenode(rightp^,taddnode(rightp^).left);
  980. end
  981. else if taddnode(rightp^).left.nodetype=ordconstn then
  982. begin
  983. extraoffset:=tordconstnode(taddnode(rightp^).left).value.svalue;
  984. replacenode(rightp^,taddnode(rightp^).right);
  985. end;
  986. end
  987. else if rightp^.nodetype=subn then
  988. begin
  989. if taddnode(rightp^).right.nodetype=ordconstn then
  990. begin
  991. extraoffset:=-tordconstnode(taddnode(rightp^).right).value.svalue;
  992. replacenode(rightp^,taddnode(rightp^).left);
  993. end;
  994. end;
  995. update_reference_offset(location.reference,extraoffset,mulsize);
  996. end;
  997. { calculate from left to right }
  998. if not(location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  999. internalerror(200304237);
  1000. isjump:=(right.expectloc=LOC_JUMP);
  1001. otl:=nil;
  1002. ofl:=nil;
  1003. if isjump then
  1004. begin
  1005. otl:=current_procinfo.CurrTrueLabel;
  1006. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  1007. ofl:=current_procinfo.CurrFalseLabel;
  1008. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  1009. end;
  1010. secondpass(right);
  1011. { if mulsize = 1, we won't have to modify the index }
  1012. if not(right.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  1013. not valid_index_size(right.location.size) then
  1014. begin
  1015. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,ptruinttype,true);
  1016. indexdef:=ptruinttype
  1017. end
  1018. else
  1019. indexdef:=right.resultdef;
  1020. if isjump then
  1021. begin
  1022. current_procinfo.CurrTrueLabel:=otl;
  1023. current_procinfo.CurrFalseLabel:=ofl;
  1024. end
  1025. else if (right.location.loc = LOC_JUMP) then
  1026. internalerror(2006010801);
  1027. { produce possible range check code: }
  1028. if cs_check_range in current_settings.localswitches then
  1029. begin
  1030. if left.resultdef.typ=arraydef then
  1031. rangecheck_array
  1032. else if (left.resultdef.typ=stringdef) then
  1033. rangecheck_string;
  1034. end;
  1035. { insert the register and the multiplication factor in the
  1036. reference }
  1037. if not is_packed_array(left.resultdef) then
  1038. update_reference_reg_mul(right.location.register,indexdef,mulsize)
  1039. else
  1040. update_reference_reg_packed(right.location.register,indexdef,mulsize);
  1041. end;
  1042. location.size:=newsize;
  1043. paraloc1.done;
  1044. paraloc2.done;
  1045. end;
  1046. begin
  1047. cloadvmtaddrnode:=tcgloadvmtaddrnode;
  1048. cloadparentfpnode:=tcgloadparentfpnode;
  1049. caddrnode:=tcgaddrnode;
  1050. cderefnode:=tcgderefnode;
  1051. csubscriptnode:=tcgsubscriptnode;
  1052. cwithnode:=tcgwithnode;
  1053. cvecnode:=tcgvecnode;
  1054. end.