From 6b0c950cb873f5fe65c0029140b91dfd8a7b1adb Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 8 Feb 2022 12:56:50 +0100 Subject: stage2 ARM: support all integer types in genTypedValue --- src/arch/arm/CodeGen.zig | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index fb473ef412..9e1e3d7f43 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -3180,7 +3180,6 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void { fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void { switch (mcv) { .dead => unreachable, - .ptr_stack_offset => unreachable, .ptr_embedded_in_code => unreachable, .unreach, .none => return, // Nothing to do. .undef => { @@ -3194,6 +3193,10 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro else => return self.fail("TODO implement memset", .{}), } }, + .ptr_stack_offset => { + const reg = try self.copyToTmpRegister(ty, mcv); + return self.genSetStack(ty, stack_offset, MCValue{ .register = reg }); + }, .compare_flags_unsigned, .compare_flags_signed, .immediate, @@ -3858,9 +3861,7 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCVa const got_addr = got.p_vaddr + decl.link.elf.offset_table_index * ptr_bytes; return MCValue{ .memory = got_addr }; } else if (self.bin_file.cast(link.File.MachO)) |_| { - // TODO I'm hacking my way through here by repurposing .memory for storing - // index to the GOT target symbol index. - return MCValue{ .memory = decl.link.macho.local_sym_index }; + unreachable; // unsupported architecture for MachO } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes; return MCValue{ .memory = got_addr }; @@ -3929,10 +3930,19 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { }, .Int => { const info = typed_value.ty.intInfo(self.target.*); - if (info.bits > ptr_bits or info.signedness == .signed) { - return self.fail("TODO const int bigger than ptr and signed int", .{}); + if (info.bits <= ptr_bits) { + const unsigned = switch (info.signedness) { + .signed => blk: { + const signed = @intCast(i32, typed_value.val.toSignedInt()); + break :blk @bitCast(u32, signed); + }, + .unsigned => @intCast(u32, typed_value.val.toUnsignedInt()), + }; + + return MCValue{ .immediate = unsigned }; + } else { + return self.lowerUnnamedConst(typed_value); } - return MCValue{ .immediate = @intCast(u32, typed_value.val.toUnsignedInt()) }; }, .Bool => { return MCValue{ .immediate = @boolToInt(typed_value.val.toBool()) }; -- cgit v1.2.3 From 8fe9d2f9867101fc8d6a91c6e10c6f3b644ce6a8 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 8 Feb 2022 13:21:54 +0100 Subject: stage2 ARM: airStructFieldVal for more MCValues --- src/arch/arm/CodeGen.zig | 11 ++++++++++- test/behavior/struct.zig | 4 ---- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/arch/arm/CodeGen.zig') diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 9e1e3d7f43..2116717cd1 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -1703,9 +1703,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, self.target.*)); const struct_field_ty = struct_ty.structFieldType(index); const struct_field_size = @intCast(u32, struct_field_ty.abiSize(self.target.*)); + const adjusted_field_offset = struct_size - struct_field_offset - struct_field_size; + switch (mcv) { + .dead, .unreach => unreachable, + .stack_argument_offset => |off| { + break :result MCValue{ .stack_argument_offset = off + adjusted_field_offset }; + }, .stack_offset => |off| { - break :result MCValue{ .stack_offset = off + struct_size - struct_field_offset - struct_field_size }; + break :result MCValue{ .stack_offset = off + adjusted_field_offset }; + }, + .memory => |addr| { + break :result MCValue{ .memory = addr + adjusted_field_offset }; }, else => return self.fail("TODO implement codegen struct_field_val for {}", .{mcv}), } diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 6a0ebb5123..03be28b9d1 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -174,16 +174,12 @@ const MemberFnTestFoo = struct { }; test "call member function directly" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - const instance = MemberFnTestFoo{ .x = 1234 }; const result = MemberFnTestFoo.member(instance); try expect(result == 1234); } test "store member function in variable" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - const instance = MemberFnTestFoo{ .x = 1234 }; const memberFn = MemberFnTestFoo.member; const result = memberFn(instance); -- cgit v1.2.3