authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-02 02:23:50-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-03 04:25:14-04:00
log31429a4e8649961624878d11e1bb330107013086
tree537b7225523fafa455f454a66934400a5186ba21
parent40ef796278bd5ba405099609e03bdeacab7d3154

codegen: handle variable and decl_ref_mut consistently


3 files changed, 39 insertions(+), 35 deletions(-)

src/codegen.zig+39-32
......@@ -341,14 +341,20 @@ pub fn generateSymbol(
341341 }
342342 return Result.ok;
343343 },
344 .variable => {
345 const decl = typed_value.val.castTag(.variable).?.data.owner_decl;
346 return lowerDeclRef(bin_file, src_loc, typed_value, decl, code, debug_output, reloc_info);
347 },
348 .decl_ref => {
349 const decl = typed_value.val.castTag(.decl_ref).?.data;
350 return lowerDeclRef(bin_file, src_loc, typed_value, decl, code, debug_output, reloc_info);
351 },
344 .variable, .decl_ref, .decl_ref_mut => |tag| return lowerDeclRef(
345 bin_file,
346 src_loc,
347 typed_value,
348 switch (tag) {
349 .variable => typed_value.val.castTag(.variable).?.data.owner_decl,
350 .decl_ref => typed_value.val.castTag(.decl_ref).?.data,
351 .decl_ref_mut => typed_value.val.castTag(.decl_ref_mut).?.data.decl_index,
352 else => unreachable,
353 },
354 code,
355 debug_output,
356 reloc_info,
357 ),
352358 .slice => {
353359 const slice = typed_value.val.castTag(.slice).?.data;
354360
......@@ -787,11 +793,11 @@ pub fn generateSymbol(
787793 },
788794 else => unreachable,
789795 },
790 else => |t| return Result{ .fail = try ErrorMsg.create(
796 else => |tag| return Result{ .fail = try ErrorMsg.create(
791797 bin_file.allocator,
792798 src_loc,
793799 "TODO implement generateSymbol for type '{s}'",
794 .{@tagName(t)},
800 .{@tagName(tag)},
795801 ) },
796802 }
797803}
......@@ -852,28 +858,26 @@ fn lowerParentPtr(
852858 reloc_info.offset(@intCast(u32, elem_ptr.index * elem_ptr.elem_ty.abiSize(target))),
853859 );
854860 },
855 .decl_ref => {
856 const decl_index = parent_ptr.castTag(.decl_ref).?.data;
857 return lowerDeclRef(
858 bin_file,
859 src_loc,
860 typed_value,
861 decl_index,
862 code,
863 debug_output,
864 reloc_info,
865 );
866 },
867 else => |t| {
868 return Result{
869 .fail = try ErrorMsg.create(
870 bin_file.allocator,
871 src_loc,
872 "TODO implement lowerParentPtr for type '{s}'",
873 .{@tagName(t)},
874 ),
875 };
876 },
861 .variable, .decl_ref, .decl_ref_mut => |tag| return lowerDeclRef(
862 bin_file,
863 src_loc,
864 typed_value,
865 switch (tag) {
866 .variable => parent_ptr.castTag(.variable).?.data.owner_decl,
867 .decl_ref => parent_ptr.castTag(.decl_ref).?.data,
868 .decl_ref_mut => parent_ptr.castTag(.decl_ref_mut).?.data.decl_index,
869 else => unreachable,
870 },
871 code,
872 debug_output,
873 reloc_info,
874 ),
875 else => |tag| return Result{ .fail = try ErrorMsg.create(
876 bin_file.allocator,
877 src_loc,
878 "TODO implement lowerParentPtr for type '{s}'",
879 .{@tagName(tag)},
880 ) },
877881 }
878882}
879883
......@@ -1126,6 +1130,9 @@ pub fn genTypedValue(
11261130 const ptr_bits = target.cpu.arch.ptrBitWidth();
11271131
11281132 if (!typed_value.ty.isSlice()) {
1133 if (typed_value.val.castTag(.variable)) |payload| {
1134 return genDeclRef(bin_file, src_loc, typed_value, payload.data.owner_decl);
1135 }
11291136 if (typed_value.val.castTag(.decl_ref)) |payload| {
11301137 return genDeclRef(bin_file, src_loc, typed_value, payload.data);
11311138 }
test/behavior/eval.zig-1
......@@ -1185,7 +1185,6 @@ test "equality of pointers to comptime const" {
11851185}
11861186
11871187test "storing an array of type in a field" {
1188 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
11891188 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
11901189 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
11911190 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/ptrcast.zig-2
......@@ -128,7 +128,6 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
128128test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
129129 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
130130 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
131 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
132131 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
133132 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
134133
......@@ -152,7 +151,6 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
152151test "lower reinterpreted comptime field ptr" {
153152 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
154153 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
155 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
156154 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
157155 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
158156