mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
stage2 ARM: implement field_parent_ptr
This commit is contained in:
parent
481bd4761a
commit
e2b029e2c8
@ -2681,9 +2681,24 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
|
||||
|
||||
fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
|
||||
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
|
||||
const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
|
||||
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airFieldParentPtr", .{});
|
||||
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
|
||||
const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
|
||||
const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
|
||||
const field_ptr = try self.resolveInst(extra.field_ptr);
|
||||
const struct_ty = self.air.getRefType(ty_pl.ty).childType();
|
||||
const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(extra.field_index, self.target.*));
|
||||
switch (field_ptr) {
|
||||
.ptr_stack_offset => |off| {
|
||||
break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
|
||||
},
|
||||
else => {
|
||||
const lhs_bind: ReadArg.Bind = .{ .mcv = field_ptr };
|
||||
const rhs_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = struct_field_offset } };
|
||||
|
||||
break :result try self.addSub(.sub, lhs_bind, rhs_bind, Type.usize, Type.usize, null);
|
||||
},
|
||||
}
|
||||
};
|
||||
return self.finishAir(inst, result, .{ extra.field_ptr, .none, .none });
|
||||
}
|
||||
|
||||
/// An argument to a Mir instruction which is read (and possibly also
|
||||
|
||||
@ -2,7 +2,6 @@ const expect = @import("std").testing.expect;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
test "@fieldParentPtr non-first field" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
@ -11,7 +10,6 @@ test "@fieldParentPtr non-first field" {
|
||||
}
|
||||
|
||||
test "@fieldParentPtr first field" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user