| ... | @@ -19,7 +19,6 @@ const DW = std.dwarf; | ... | @@ -19,7 +19,6 @@ const DW = std.dwarf; |
| 19 | const leb128 = std.leb; | 19 | const leb128 = std.leb; |
| 20 | const log = std.log.scoped(.codegen); | 20 | const log = std.log.scoped(.codegen); |
| 21 | const build_options = @import("build_options"); | 21 | const build_options = @import("build_options"); |
| 22 | const LazySrcLoc = Module.LazySrcLoc; | | |
| 23 | const RegisterManager = @import("register_manager.zig").RegisterManager; | 22 | const RegisterManager = @import("register_manager.zig").RegisterManager; |
| 24 | | 23 | |
| 25 | const X8664Encoder = @import("codegen/x86_64.zig").Encoder; | 24 | const 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 | } |