| ... | @@ -2897,7 +2897,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2897,7 +2897,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2897 | const offset_reg_lock = self.register_manager.lockRegAssumeUnused(offset_reg); | 2897 | const offset_reg_lock = self.register_manager.lockRegAssumeUnused(offset_reg); |
| 2898 | defer self.register_manager.unlockReg(offset_reg_lock); | 2898 | defer self.register_manager.unlockReg(offset_reg_lock); |
| 2899 | | 2899 | |
| 2900 | const addr_reg = try self.register_manager.allocReg(null, gp); | 2900 | const addr_reg = (try self.register_manager.allocReg(null, gp)).to64(); |
| 2901 | switch (array) { | 2901 | switch (array) { |
| 2902 | .register => { | 2902 | .register => { |
| 2903 | const off = @intCast(i32, try self.allocMem( | 2903 | const off = @intCast(i32, try self.allocMem( |
| ... | @@ -2906,19 +2906,32 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2906,19 +2906,32 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2906 | array_ty.abiAlignment(self.target.*), | 2906 | array_ty.abiAlignment(self.target.*), |
| 2907 | )); | 2907 | )); |
| 2908 | try self.genSetStack(array_ty, off, array, .{}); | 2908 | try self.genSetStack(array_ty, off, array, .{}); |
| 2909 | try self.asmRegisterMemory(.lea, addr_reg.to64(), Memory.sib(.qword, .{ | 2909 | try self.asmRegisterMemory(.lea, addr_reg, Memory.sib(.qword, .{ |
| 2910 | .base = .rbp, | 2910 | .base = .rbp, |
| 2911 | .disp = -off, | 2911 | .disp = -off, |
| 2912 | })); | 2912 | })); |
| 2913 | }, | 2913 | }, |
| 2914 | .stack_offset => |off| { | 2914 | .stack_offset => |off| { |
| 2915 | try self.asmRegisterMemory(.lea, addr_reg.to64(), Memory.sib(.qword, .{ | 2915 | try self.asmRegisterMemory(.lea, addr_reg, Memory.sib(.qword, .{ |
| 2916 | .base = .rbp, | 2916 | .base = .rbp, |
| 2917 | .disp = -off, | 2917 | .disp = -off, |
| 2918 | })); | 2918 | })); |
| 2919 | }, | 2919 | }, |
| 2920 | .memory, .linker_load => { | 2920 | .memory => |addr| try self.genSetReg(Type.usize, addr_reg, .{ .immediate = addr }), |
| 2921 | try self.loadMemPtrIntoRegister(addr_reg, Type.usize, array); | 2921 | .linker_load => |load_struct| { |
| | 2922 | const atom_index = if (self.bin_file.cast(link.File.MachO)) |macho_file| blk: { |
| | 2923 | const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl); |
| | 2924 | break :blk macho_file.getAtom(atom).getSymbolIndex().?; |
| | 2925 | } else if (self.bin_file.cast(link.File.Coff)) |coff_file| blk: { |
| | 2926 | const atom = try coff_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl); |
| | 2927 | break :blk coff_file.getAtom(atom).getSymbolIndex().?; |
| | 2928 | } else unreachable; |
| | 2929 | |
| | 2930 | switch (load_struct.type) { |
| | 2931 | .import => unreachable, |
| | 2932 | .got => try self.asmMovLinker(addr_reg, atom_index, load_struct), |
| | 2933 | .direct => try self.asmLeaLinker(addr_reg, atom_index, load_struct), |
| | 2934 | } |
| 2922 | }, | 2935 | }, |
| 2923 | else => return self.fail("TODO implement array_elem_val when array is {}", .{array}), | 2936 | else => return self.fail("TODO implement array_elem_val when array is {}", .{array}), |
| 2924 | } | 2937 | } |