| ... | @@ -22,6 +22,8 @@ const Liveness = @import("../../Liveness.zig"); | ... | @@ -22,6 +22,8 @@ const Liveness = @import("../../Liveness.zig"); |
| 22 | const Mir = @import("Mir.zig"); | 22 | const Mir = @import("Mir.zig"); |
| 23 | const Emit = @import("Emit.zig"); | 23 | const Emit = @import("Emit.zig"); |
| 24 | const abi = @import("abi.zig"); | 24 | const abi = @import("abi.zig"); |
| | 25 | const errUnionPayloadOffset = codegen.errUnionPayloadOffset; |
| | 26 | const errUnionErrOffset = codegen.errUnionErrOffset; |
| 25 | | 27 | |
| 26 | /// Wasm Value, created when generating an instruction | 28 | /// Wasm Value, created when generating an instruction |
| 27 | const WValue = union(enum) { | 29 | const WValue = union(enum) { |
| ... | @@ -2931,7 +2933,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!W | ... | @@ -2931,7 +2933,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!W |
| 2931 | try self.emitWValue(operand); | 2933 | try self.emitWValue(operand); |
| 2932 | if (pl_ty.hasRuntimeBitsIgnoreComptime()) { | 2934 | if (pl_ty.hasRuntimeBitsIgnoreComptime()) { |
| 2933 | try self.addMemArg(.i32_load16_u, .{ | 2935 | try self.addMemArg(.i32_load16_u, .{ |
| 2934 | .offset = operand.offset() + errUnionErrorOffset(pl_ty, self.target), | 2936 | .offset = operand.offset() + @intCast(u32, errUnionErrOffset(pl_ty, self.target)), |
| 2935 | .alignment = Type.anyerror.abiAlignment(self.target), | 2937 | .alignment = Type.anyerror.abiAlignment(self.target), |
| 2936 | }); | 2938 | }); |
| 2937 | } | 2939 | } |
| ... | @@ -2959,7 +2961,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index, op_is_ptr: bool) | ... | @@ -2959,7 +2961,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index, op_is_ptr: bool) |
| 2959 | | 2961 | |
| 2960 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) return WValue{ .none = {} }; | 2962 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) return WValue{ .none = {} }; |
| 2961 | | 2963 | |
| 2962 | const pl_offset = errUnionPayloadOffset(payload_ty, self.target); | 2964 | const pl_offset = @intCast(u32, errUnionPayloadOffset(payload_ty, self.target)); |
| 2963 | if (op_is_ptr or isByRef(payload_ty, self.target)) { | 2965 | if (op_is_ptr or isByRef(payload_ty, self.target)) { |
| 2964 | return self.buildPointerOffset(operand, pl_offset, .new); | 2966 | return self.buildPointerOffset(operand, pl_offset, .new); |
| 2965 | } | 2967 | } |
| ... | @@ -2983,7 +2985,7 @@ fn airUnwrapErrUnionError(self: *Self, inst: Air.Inst.Index, op_is_ptr: bool) In | ... | @@ -2983,7 +2985,7 @@ fn airUnwrapErrUnionError(self: *Self, inst: Air.Inst.Index, op_is_ptr: bool) In |
| 2983 | return operand; | 2985 | return operand; |
| 2984 | } | 2986 | } |
| 2985 | | 2987 | |
| 2986 | return self.load(operand, Type.anyerror, errUnionErrorOffset(payload_ty, self.target)); | 2988 | return self.load(operand, Type.anyerror, @intCast(u32, errUnionErrOffset(payload_ty, self.target))); |
| 2987 | } | 2989 | } |
| 2988 | | 2990 | |
| 2989 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | 2991 | fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| ... | @@ -3003,13 +3005,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | ... | @@ -3003,13 +3005,13 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3003 | } | 3005 | } |
| 3004 | | 3006 | |
| 3005 | const err_union = try self.allocStack(err_ty); | 3007 | const err_union = try self.allocStack(err_ty); |
| 3006 | const payload_ptr = try self.buildPointerOffset(err_union, errUnionPayloadOffset(pl_ty, self.target), .new); | 3008 | const payload_ptr = try self.buildPointerOffset(err_union, @intCast(u32, errUnionPayloadOffset(pl_ty, self.target)), .new); |
| 3007 | try self.store(payload_ptr, operand, pl_ty, 0); | 3009 | try self.store(payload_ptr, operand, pl_ty, 0); |
| 3008 | | 3010 | |
| 3009 | // ensure we also write '0' to the error part, so any present stack value gets overwritten by it. | 3011 | // ensure we also write '0' to the error part, so any present stack value gets overwritten by it. |
| 3010 | try self.emitWValue(err_union); | 3012 | try self.emitWValue(err_union); |
| 3011 | try self.addImm32(0); | 3013 | try self.addImm32(0); |
| 3012 | const err_val_offset = errUnionErrorOffset(pl_ty, self.target); | 3014 | const err_val_offset = @intCast(u32, errUnionErrOffset(pl_ty, self.target)); |
| 3013 | try self.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 }); | 3015 | try self.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 }); |
| 3014 | | 3016 | |
| 3015 | return err_union; | 3017 | return err_union; |
| ... | @@ -3029,10 +3031,10 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | ... | @@ -3029,10 +3031,10 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3029 | | 3031 | |
| 3030 | const err_union = try self.allocStack(err_ty); | 3032 | const err_union = try self.allocStack(err_ty); |
| 3031 | // store error value | 3033 | // store error value |
| 3032 | try self.store(err_union, operand, Type.anyerror, errUnionErrorOffset(pl_ty, self.target)); | 3034 | try self.store(err_union, operand, Type.anyerror, @intCast(u32, errUnionErrOffset(pl_ty, self.target))); |
| 3033 | | 3035 | |
| 3034 | // write 'undefined' to the payload | 3036 | // write 'undefined' to the payload |
| 3035 | const payload_ptr = try self.buildPointerOffset(err_union, errUnionPayloadOffset(pl_ty, self.target), .new); | 3037 | const payload_ptr = try self.buildPointerOffset(err_union, @intCast(u32, errUnionPayloadOffset(pl_ty, self.target)), .new); |
| 3036 | const len = @intCast(u32, err_ty.errorUnionPayload().abiSize(self.target)); | 3038 | const len = @intCast(u32, err_ty.errorUnionPayload().abiSize(self.target)); |
| 3037 | try self.memset(payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaaaaaaaa }); | 3039 | try self.memset(payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaaaaaaaa }); |
| 3038 | | 3040 | |
| ... | @@ -3984,7 +3986,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!WValue | ... | @@ -3984,7 +3986,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!WValue |
| 3984 | operand, | 3986 | operand, |
| 3985 | .{ .imm32 = 0 }, | 3987 | .{ .imm32 = 0 }, |
| 3986 | Type.anyerror, | 3988 | Type.anyerror, |
| 3987 | errUnionErrorOffset(payload_ty, self.target), | 3989 | @intCast(u32, errUnionErrOffset(payload_ty, self.target)), |
| 3988 | ); | 3990 | ); |
| 3989 | | 3991 | |
| 3990 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; | 3992 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; |
| ... | @@ -3993,7 +3995,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!WValue | ... | @@ -3993,7 +3995,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!WValue |
| 3993 | return operand; | 3995 | return operand; |
| 3994 | } | 3996 | } |
| 3995 | | 3997 | |
| 3996 | return self.buildPointerOffset(operand, errUnionPayloadOffset(payload_ty, self.target), .new); | 3998 | return self.buildPointerOffset(operand, @intCast(u32, errUnionPayloadOffset(payload_ty, self.target)), .new); |
| 3997 | } | 3999 | } |
| 3998 | | 4000 | |
| 3999 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | 4001 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| ... | @@ -4621,17 +4623,3 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !WValue { | ... | @@ -4621,17 +4623,3 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !WValue { |
| 4621 | } }); | 4623 | } }); |
| 4622 | return WValue{ .none = {} }; | 4624 | return WValue{ .none = {} }; |
| 4623 | } | 4625 | } |
| 4624 | | | |
| 4625 | fn errUnionPayloadOffset(payload_ty: Type, target: std.Target) u32 { | | |
| 4626 | if (Type.anyerror.abiAlignment(target) > payload_ty.abiAlignment(target)) { | | |
| 4627 | return @intCast(u32, Type.anyerror.abiSize(target)); | | |
| 4628 | } | | |
| 4629 | return 0; | | |
| 4630 | } | | |
| 4631 | | | |
| 4632 | fn errUnionErrorOffset(payload_ty: Type, target: std.Target) u32 { | | |
| 4633 | if (Type.anyerror.abiAlignment(target) > payload_ty.abiAlignment(target)) { | | |
| 4634 | return 0; | | |
| 4635 | } | | |
| 4636 | return @intCast(u32, payload_ty.abiSize(target)); | | |
| 4637 | } | | |