| ... | @@ -677,7 +677,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { | ... | @@ -677,7 +677,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 677 | .err_return_trace => @panic("TODO try self.airErrReturnTrace(inst)"), | 677 | .err_return_trace => @panic("TODO try self.airErrReturnTrace(inst)"), |
| 678 | .set_err_return_trace => @panic("TODO try self.airSetErrReturnTrace(inst)"), | 678 | .set_err_return_trace => @panic("TODO try self.airSetErrReturnTrace(inst)"), |
| 679 | | 679 | |
| 680 | .wrap_optional => @panic("TODO try self.airWrapOptional(inst)"), | 680 | .wrap_optional => try self.airWrapOptional(inst), |
| 681 | .wrap_errunion_payload => @panic("TODO try self.airWrapErrUnionPayload(inst)"), | 681 | .wrap_errunion_payload => @panic("TODO try self.airWrapErrUnionPayload(inst)"), |
| 682 | .wrap_errunion_err => try self.airWrapErrUnionErr(inst), | 682 | .wrap_errunion_err => try self.airWrapErrUnionErr(inst), |
| 683 | | 683 | |
| ... | @@ -2175,6 +2175,20 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2175,6 +2175,20 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void { |
| 2175 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); | 2175 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 2176 | } | 2176 | } |
| 2177 | | 2177 | |
| | 2178 | fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void { |
| | 2179 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| | 2180 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| | 2181 | const optional_ty = self.air.typeOfIndex(inst); |
| | 2182 | |
| | 2183 | // Optional with a zero-bit payload type is just a boolean true |
| | 2184 | if (optional_ty.abiSize(self.target.*) == 1) |
| | 2185 | break :result MCValue{ .immediate = 1 }; |
| | 2186 | |
| | 2187 | return self.fail("TODO implement wrap optional for {}", .{self.target.cpu.arch}); |
| | 2188 | }; |
| | 2189 | return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| | 2190 | } |
| | 2191 | |
| 2178 | // Common helper functions | 2192 | // Common helper functions |
| 2179 | | 2193 | |
| 2180 | /// Adds a Type to the .debug_info at the current position. The bytes will be populated later, | 2194 | /// Adds a Type to the .debug_info at the current position. The bytes will be populated later, |