authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-05-06 22:14:32+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-05-16 22:48:49+07:00
log0b54649cac53c5eebb573547bafbd4ec3a32443c
treee2881a65b92a2331e9cd849f9e7219f0c190d6bd
parent3ab66343709147f17c6035fc298ffcc0088f0e1d

stage2: sparc64: Implement error value generation


1 files changed, 28 insertions(+), 0 deletions(-)

src/arch/sparc64/CodeGen.zig+28
......@@ -1808,6 +1808,34 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
18081808 return self.fail("TODO implement int genTypedValue of > 64 bits", .{});
18091809 }
18101810 },
1811 .ErrorSet => {
1812 const err_name = typed_value.val.castTag(.@"error").?.data.name;
1813 const module = self.bin_file.options.module.?;
1814 const global_error_set = module.global_error_set;
1815 const error_index = global_error_set.get(err_name).?;
1816 return MCValue{ .immediate = error_index };
1817 },
1818 .ErrorUnion => {
1819 const error_type = typed_value.ty.errorUnionSet();
1820 const payload_type = typed_value.ty.errorUnionPayload();
1821
1822 if (typed_value.val.castTag(.eu_payload)) |pl| {
1823 if (!payload_type.hasRuntimeBits()) {
1824 // We use the error type directly as the type.
1825 return MCValue{ .immediate = 0 };
1826 }
1827
1828 _ = pl;
1829 return self.fail("TODO implement error union const of type '{}' (non-error)", .{typed_value.ty.fmtDebug()});
1830 } else {
1831 if (!payload_type.hasRuntimeBits()) {
1832 // We use the error type directly as the type.
1833 return self.genTypedValue(.{ .ty = error_type, .val = typed_value.val });
1834 }
1835
1836 return self.fail("TODO implement error union const of type '{}' (error)", .{typed_value.ty.fmtDebug()});
1837 }
1838 },
18111839 .ComptimeInt => unreachable, // semantic analysis prevents this
18121840 .ComptimeFloat => unreachable, // semantic analysis prevents this
18131841 else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty.fmtDebug()}),