ncgmem.pas 50 KB

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