aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorjoachimschmidt557 <joachim.schmidt557@outlook.com>2021-07-30 11:43:17 +0200
committerAndrew Kelley <andrew@ziglang.org>2021-07-30 13:22:33 -0400
commitf6b1fa9e29ccab77a54e92dc13a7eb8e407bdbbc (patch)
treedf1f5e36ddfd5354fd79746bc2a4af80daa29ded /src/codegen.zig
parente5e6ceda6a98cc89e63abb62beb8557ff9f3109e (diff)
downloadzig-f6b1fa9e29ccab77a54e92dc13a7eb8e407bdbbc.tar.gz
zig-f6b1fa9e29ccab77a54e92dc13a7eb8e407bdbbc.zip
stage2 codegen: genTypedValue for error unions and error sets
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index d16a87adca..0917f2c847 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -19,7 +19,6 @@ const DW = std.dwarf;
const leb128 = std.leb;
const log = std.log.scoped(.codegen);
const build_options = @import("build_options");
-const LazySrcLoc = Module.LazySrcLoc;
const RegisterManager = @import("register_manager.zig").RegisterManager;
const X8664Encoder = @import("codegen/x86_64.zig").Encoder;
@@ -4741,6 +4740,33 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
return self.fail("TODO non pointer optionals", .{});
},
+ .ErrorSet => {
+ switch (typed_value.val.tag()) {
+ .@"error" => {
+ const err_name = typed_value.val.castTag(.@"error").?.data.name;
+ const module = self.bin_file.options.module.?;
+ const global_error_set = module.global_error_set;
+ const error_index = global_error_set.get(err_name).?;
+ return MCValue{ .immediate = error_index };
+ },
+ else => {
+ // In this case we are rendering an error union which has a 0 bits payload.
+ return MCValue{ .immediate = 0 };
+ },
+ }
+ },
+ .ErrorUnion => {
+ const error_type = typed_value.ty.errorUnionSet();
+ const payload_type = typed_value.ty.errorUnionPayload();
+ const sub_val = typed_value.val.castTag(.error_union).?.data;
+
+ if (!payload_type.hasCodeGenBits()) {
+ // We use the error type directly as the type.
+ return self.genTypedValue(.{ .ty = error_type, .val = sub_val });
+ }
+
+ return self.fail("TODO implement error union const of type '{}'", .{typed_value.ty});
+ },
else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty}),
}
}