authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-08 21:04:38+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-08 21:04:38+01:00
logc256603eaef162e7df004d3508bbd4f2ec3470eb
tree60fd2c37a73f090facfacb89e72e394be37d07ed
parent37fea3e3ddc1f7d266d95789c3b1005291bcb96b
parent8fe9d2f9867101fc8d6a91c6e10c6f3b644ce6a8
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10839 from joachimschmidt557/stage2-arm

stage2 ARM: genTypedValue for all integer types

7 files changed, 27 insertions(+), 27 deletions(-)

src/arch/arm/CodeGen.zig+27-8
......@@ -1703,9 +1703,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
17031703 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, self.target.*));
17041704 const struct_field_ty = struct_ty.structFieldType(index);
17051705 const struct_field_size = @intCast(u32, struct_field_ty.abiSize(self.target.*));
1706 const adjusted_field_offset = struct_size - struct_field_offset - struct_field_size;
1707
17061708 switch (mcv) {
1709 .dead, .unreach => unreachable,
1710 .stack_argument_offset => |off| {
1711 break :result MCValue{ .stack_argument_offset = off + adjusted_field_offset };
1712 },
17071713 .stack_offset => |off| {
1708 break :result MCValue{ .stack_offset = off + struct_size - struct_field_offset - struct_field_size };
1714 break :result MCValue{ .stack_offset = off + adjusted_field_offset };
1715 },
1716 .memory => |addr| {
1717 break :result MCValue{ .memory = addr + adjusted_field_offset };
17091718 },
17101719 else => return self.fail("TODO implement codegen struct_field_val for {}", .{mcv}),
17111720 }
......@@ -3180,7 +3189,6 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
31803189fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
31813190 switch (mcv) {
31823191 .dead => unreachable,
3183 .ptr_stack_offset => unreachable,
31843192 .ptr_embedded_in_code => unreachable,
31853193 .unreach, .none => return, // Nothing to do.
31863194 .undef => {
......@@ -3194,6 +3202,10 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
31943202 else => return self.fail("TODO implement memset", .{}),
31953203 }
31963204 },
3205 .ptr_stack_offset => {
3206 const reg = try self.copyToTmpRegister(ty, mcv);
3207 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
3208 },
31973209 .compare_flags_unsigned,
31983210 .compare_flags_signed,
31993211 .immediate,
......@@ -3858,9 +3870,7 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCVa
38583870 const got_addr = got.p_vaddr + decl.link.elf.offset_table_index * ptr_bytes;
38593871 return MCValue{ .memory = got_addr };
38603872 } else if (self.bin_file.cast(link.File.MachO)) |_| {
3861 // TODO I'm hacking my way through here by repurposing .memory for storing
3862 // index to the GOT target symbol index.
3863 return MCValue{ .memory = decl.link.macho.local_sym_index };
3873 unreachable; // unsupported architecture for MachO
38643874 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
38653875 const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes;
38663876 return MCValue{ .memory = got_addr };
......@@ -3929,10 +3939,19 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
39293939 },
39303940 .Int => {
39313941 const info = typed_value.ty.intInfo(self.target.*);
3932 if (info.bits > ptr_bits or info.signedness == .signed) {
3933 return self.fail("TODO const int bigger than ptr and signed int", .{});
3942 if (info.bits <= ptr_bits) {
3943 const unsigned = switch (info.signedness) {
3944 .signed => blk: {
3945 const signed = @intCast(i32, typed_value.val.toSignedInt());
3946 break :blk @bitCast(u32, signed);
3947 },
3948 .unsigned => @intCast(u32, typed_value.val.toUnsignedInt()),
3949 };
3950
3951 return MCValue{ .immediate = unsigned };
3952 } else {
3953 return self.lowerUnnamedConst(typed_value);
39343954 }
3935 return MCValue{ .immediate = @intCast(u32, typed_value.val.toUnsignedInt()) };
39363955 },
39373956 .Bool => {
39383957 return MCValue{ .immediate = @boolToInt(typed_value.val.toBool()) };
test/behavior/align.zig-2
......@@ -93,8 +93,6 @@ test "@ptrCast preserves alignment of bigger source" {
9393}
9494
9595test "alignstack" {
96 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
97
9896 try expect(fnWithAlignedStack() == 1234);
9997}
10098
test/behavior/bugs/1277.zig-1
......@@ -12,6 +12,5 @@ fn f() i32 {
1212}
1313
1414test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
15 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1615 try std.testing.expect(s.f.?() == 1234);
1716}
test/behavior/bugs/1310.zig-1
......@@ -23,6 +23,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
2323}
2424
2525test "fixed" {
26 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
2726 try expect(agent_callback(undefined, undefined) == 11);
2827}
test/behavior/bugs/2006.zig-1
......@@ -7,7 +7,6 @@ const S = struct {
77};
88test "bug 2006" {
99 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1110 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1211 var a: S = undefined;
1312 a = S{ .p = undefined };
test/behavior/cast.zig-4
......@@ -35,8 +35,6 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
3535}
3636
3737test "resolve undefined with integer" {
38 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
39
4038 try testResolveUndefWithInt(true, 1234);
4139 comptime try testResolveUndefWithInt(true, 1234);
4240}
......@@ -205,8 +203,6 @@ test "implicit cast from *[N]T to [*c]T" {
205203}
206204
207205test "*usize to *void" {
208 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
209
210206 var i = @as(usize, 0);
211207 var v = @ptrCast(*void, &i);
212208 v.* = {};
test/behavior/struct.zig-10
......@@ -114,8 +114,6 @@ test "struct byval assign" {
114114}
115115
116116test "call struct static method" {
117 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
118
119117 const result = StructWithNoFields.add(3, 4);
120118 try expect(result == 7);
121119}
......@@ -176,16 +174,12 @@ const MemberFnTestFoo = struct {
176174};
177175
178176test "call member function directly" {
179 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
180
181177 const instance = MemberFnTestFoo{ .x = 1234 };
182178 const result = MemberFnTestFoo.member(instance);
183179 try expect(result == 1234);
184180}
185181
186182test "store member function in variable" {
187 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
188
189183 const instance = MemberFnTestFoo{ .x = 1234 };
190184 const memberFn = MemberFnTestFoo.member;
191185 const result = memberFn(instance);
......@@ -193,8 +187,6 @@ test "store member function in variable" {
193187}
194188
195189test "member functions" {
196 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
197
198190 const r = MemberFnRand{ .seed = 1234 };
199191 try expect(r.getSeed() == 1234);
200192}
......@@ -244,8 +236,6 @@ test "call method with mutable reference to struct with no fields" {
244236}
245237
246238test "usingnamespace within struct scope" {
247 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
248
249239 const S = struct {
250240 usingnamespace struct {
251241 pub fn inner() i32 {