diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-02-08 21:04:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-08 21:04:38 +0100 |
| commit | c256603eaef162e7df004d3508bbd4f2ec3470eb (patch) | |
| tree | 60fd2c37a73f090facfacb89e72e394be37d07ed | |
| parent | 37fea3e3ddc1f7d266d95789c3b1005291bcb96b (diff) | |
| parent | 8fe9d2f9867101fc8d6a91c6e10c6f3b644ce6a8 (diff) | |
| download | zig-c256603eaef162e7df004d3508bbd4f2ec3470eb.tar.gz zig-c256603eaef162e7df004d3508bbd4f2ec3470eb.zip | |
Merge pull request #10839 from joachimschmidt557/stage2-arm
stage2 ARM: genTypedValue for all integer types
| -rw-r--r-- | src/arch/arm/CodeGen.zig | 35 | ||||
| -rw-r--r-- | test/behavior/align.zig | 2 | ||||
| -rw-r--r-- | test/behavior/bugs/1277.zig | 1 | ||||
| -rw-r--r-- | test/behavior/bugs/1310.zig | 1 | ||||
| -rw-r--r-- | test/behavior/bugs/2006.zig | 1 | ||||
| -rw-r--r-- | test/behavior/cast.zig | 4 | ||||
| -rw-r--r-- | test/behavior/struct.zig | 10 |
7 files changed, 27 insertions, 27 deletions
diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index fb473ef412..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}), } @@ -3180,7 +3189,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 +3202,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 +3870,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 +3939,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()) }; diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 1044742627..96278524c0 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -93,8 +93,6 @@ test "@ptrCast preserves alignment of bigger source" { } test "alignstack" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - try expect(fnWithAlignedStack() == 1234); } diff --git a/test/behavior/bugs/1277.zig b/test/behavior/bugs/1277.zig index 3b59ea36e8..46fa1d27d4 100644 --- a/test/behavior/bugs/1277.zig +++ b/test/behavior/bugs/1277.zig @@ -12,6 +12,5 @@ fn f() i32 { } test "don't emit an LLVM global for a const function when it's in an optional in a struct" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; try std.testing.expect(s.f.?() == 1234); } diff --git a/test/behavior/bugs/1310.zig b/test/behavior/bugs/1310.zig index 25509299fb..1f19ec20c2 100644 --- a/test/behavior/bugs/1310.zig +++ b/test/behavior/bugs/1310.zig @@ -23,6 +23,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 { } test "fixed" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; try expect(agent_callback(undefined, undefined) == 11); } diff --git a/test/behavior/bugs/2006.zig b/test/behavior/bugs/2006.zig index 15f74b4485..3719271bdf 100644 --- a/test/behavior/bugs/2006.zig +++ b/test/behavior/bugs/2006.zig @@ -7,7 +7,6 @@ const S = struct { }; test "bug 2006" { if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; var a: S = undefined; a = S{ .p = undefined }; diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index d8fbc5ed9e..79f75f773c 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -35,8 +35,6 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { } test "resolve undefined with integer" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - try testResolveUndefWithInt(true, 1234); comptime try testResolveUndefWithInt(true, 1234); } @@ -205,8 +203,6 @@ test "implicit cast from *[N]T to [*c]T" { } test "*usize to *void" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - var i = @as(usize, 0); var v = @ptrCast(*void, &i); v.* = {}; diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index e4b64a39d3..03be28b9d1 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -114,8 +114,6 @@ test "struct byval assign" { } test "call struct static method" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - const result = StructWithNoFields.add(3, 4); try expect(result == 7); } @@ -176,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); @@ -193,8 +187,6 @@ test "store member function in variable" { } test "member functions" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - const r = MemberFnRand{ .seed = 1234 }; try expect(r.getSeed() == 1234); } @@ -244,8 +236,6 @@ test "call method with mutable reference to struct with no fields" { } test "usingnamespace within struct scope" { - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - const S = struct { usingnamespace struct { pub fn inner() i32 { |
