authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2021-07-30 11:43:17+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-30 13:22:33-04:00
logf6b1fa9e29ccab77a54e92dc13a7eb8e407bdbbc
treedf1f5e36ddfd5354fd79746bc2a4af80daa29ded
parente5e6ceda6a98cc89e63abb62beb8557ff9f3109e

stage2 codegen: genTypedValue for error unions and error sets


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

src/codegen.zig+27-1
...@@ -19,7 +19,6 @@ const DW = std.dwarf;...@@ -19,7 +19,6 @@ const DW = std.dwarf;
19const leb128 = std.leb;19const leb128 = std.leb;
20const log = std.log.scoped(.codegen);20const log = std.log.scoped(.codegen);
21const build_options = @import("build_options");21const build_options = @import("build_options");
22const LazySrcLoc = Module.LazySrcLoc;
23const RegisterManager = @import("register_manager.zig").RegisterManager;22const RegisterManager = @import("register_manager.zig").RegisterManager;
2423
25const X8664Encoder = @import("codegen/x86_64.zig").Encoder;24const X8664Encoder = @import("codegen/x86_64.zig").Encoder;
...@@ -4741,6 +4740,33 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -4741,6 +4740,33 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
4741 }4740 }
4742 return self.fail("TODO non pointer optionals", .{});4741 return self.fail("TODO non pointer optionals", .{});
4743 },4742 },
4743 .ErrorSet => {
4744 switch (typed_value.val.tag()) {
4745 .@"error" => {
4746 const err_name = typed_value.val.castTag(.@"error").?.data.name;
4747 const module = self.bin_file.options.module.?;
4748 const global_error_set = module.global_error_set;
4749 const error_index = global_error_set.get(err_name).?;
4750 return MCValue{ .immediate = error_index };
4751 },
4752 else => {
4753 // In this case we are rendering an error union which has a 0 bits payload.
4754 return MCValue{ .immediate = 0 };
4755 },
4756 }
4757 },
4758 .ErrorUnion => {
4759 const error_type = typed_value.ty.errorUnionSet();
4760 const payload_type = typed_value.ty.errorUnionPayload();
4761 const sub_val = typed_value.val.castTag(.error_union).?.data;
4762
4763 if (!payload_type.hasCodeGenBits()) {
4764 // We use the error type directly as the type.
4765 return self.genTypedValue(.{ .ty = error_type, .val = sub_val });
4766 }
4767
4768 return self.fail("TODO implement error union const of type '{}'", .{typed_value.ty});
4769 },
4744 else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty}),4770 else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty}),
4745 }4771 }
4746 }4772 }