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(...@@ -341,14 +341,20 @@ pub fn generateSymbol(
341 }341 }
342 return Result.ok;342 return Result.ok;
343 },343 },
344 .variable => {344 .variable, .decl_ref, .decl_ref_mut => |tag| return lowerDeclRef(
345 const decl = typed_value.val.castTag(.variable).?.data.owner_decl;345 bin_file,
346 return lowerDeclRef(bin_file, src_loc, typed_value, decl, code, debug_output, reloc_info);346 src_loc,
347 },347 typed_value,
348 .decl_ref => {348 switch (tag) {
349 const decl = typed_value.val.castTag(.decl_ref).?.data;349 .variable => typed_value.val.castTag(.variable).?.data.owner_decl,
350 return lowerDeclRef(bin_file, src_loc, typed_value, decl, code, debug_output, reloc_info);350 .decl_ref => typed_value.val.castTag(.decl_ref).?.data,
351 },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 ),
352 .slice => {358 .slice => {
353 const slice = typed_value.val.castTag(.slice).?.data;359 const slice = typed_value.val.castTag(.slice).?.data;
354360
...@@ -787,11 +793,11 @@ pub fn generateSymbol(...@@ -787,11 +793,11 @@ pub fn generateSymbol(
787 },793 },
788 else => unreachable,794 else => unreachable,
789 },795 },
790 else => |t| return Result{ .fail = try ErrorMsg.create(796 else => |tag| return Result{ .fail = try ErrorMsg.create(
791 bin_file.allocator,797 bin_file.allocator,
792 src_loc,798 src_loc,
793 "TODO implement generateSymbol for type '{s}'",799 "TODO implement generateSymbol for type '{s}'",
794 .{@tagName(t)},800 .{@tagName(tag)},
795 ) },801 ) },
796 }802 }
797}803}
...@@ -852,28 +858,26 @@ fn lowerParentPtr(...@@ -852,28 +858,26 @@ fn lowerParentPtr(
852 reloc_info.offset(@intCast(u32, elem_ptr.index * elem_ptr.elem_ty.abiSize(target))),858 reloc_info.offset(@intCast(u32, elem_ptr.index * elem_ptr.elem_ty.abiSize(target))),
853 );859 );
854 },860 },
855 .decl_ref => {861 .variable, .decl_ref, .decl_ref_mut => |tag| return lowerDeclRef(
856 const decl_index = parent_ptr.castTag(.decl_ref).?.data;862 bin_file,
857 return lowerDeclRef(863 src_loc,
858 bin_file,864 typed_value,
859 src_loc,865 switch (tag) {
860 typed_value,866 .variable => parent_ptr.castTag(.variable).?.data.owner_decl,
861 decl_index,867 .decl_ref => parent_ptr.castTag(.decl_ref).?.data,
862 code,868 .decl_ref_mut => parent_ptr.castTag(.decl_ref_mut).?.data.decl_index,
863 debug_output,869 else => unreachable,
864 reloc_info,870 },
865 );871 code,
866 },872 debug_output,
867 else => |t| {873 reloc_info,
868 return Result{874 ),
869 .fail = try ErrorMsg.create(875 else => |tag| return Result{ .fail = try ErrorMsg.create(
870 bin_file.allocator,876 bin_file.allocator,
871 src_loc,877 src_loc,
872 "TODO implement lowerParentPtr for type '{s}'",878 "TODO implement lowerParentPtr for type '{s}'",
873 .{@tagName(t)},879 .{@tagName(tag)},
874 ),880 ) },
875 };
876 },
877 }881 }
878}882}
879883
...@@ -1126,6 +1130,9 @@ pub fn genTypedValue(...@@ -1126,6 +1130,9 @@ pub fn genTypedValue(
1126 const ptr_bits = target.cpu.arch.ptrBitWidth();1130 const ptr_bits = target.cpu.arch.ptrBitWidth();
11271131
1128 if (!typed_value.ty.isSlice()) {1132 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 }
1129 if (typed_value.val.castTag(.decl_ref)) |payload| {1136 if (typed_value.val.castTag(.decl_ref)) |payload| {
1130 return genDeclRef(bin_file, src_loc, typed_value, payload.data);1137 return genDeclRef(bin_file, src_loc, typed_value, payload.data);
1131 }1138 }
test/behavior/eval.zig-1
...@@ -1185,7 +1185,6 @@ test "equality of pointers to comptime const" {...@@ -1185,7 +1185,6 @@ test "equality of pointers to comptime const" {
1185}1185}
11861186
1187test "storing an array of type in a field" {1187test "storing an array of type in a field" {
1188 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1189 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1188 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1190 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1189 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1191 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1190 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/ptrcast.zig-2
...@@ -128,7 +128,6 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {...@@ -128,7 +128,6 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
128test "lower reinterpreted comptime field ptr (with under-aligned fields)" {128test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
129 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO129 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
130 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO130 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
131 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
132 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO131 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
133 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO132 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)" {...@@ -152,7 +151,6 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
152test "lower reinterpreted comptime field ptr" {151test "lower reinterpreted comptime field ptr" {
153 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO152 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
154 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO153 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
155 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
156 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO154 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
157 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO155 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
158156