| ... | ... | @@ -22,6 +22,8 @@ const Liveness = @import("../../Liveness.zig"); |
| 22 | 22 | const Mir = @import("Mir.zig"); |
| 23 | 23 | const Emit = @import("Emit.zig"); |
| 24 | 24 | const abi = @import("abi.zig"); |
| 25 | const errUnionPayloadOffset = codegen.errUnionPayloadOffset; |
| 26 | const errUnionErrOffset = codegen.errUnionErrOffset; |
| 25 | 27 | |
| 26 | 28 | /// Wasm Value, created when generating an instruction |
| 27 | 29 | const WValue = union(enum) { |
| ... | ... | @@ -2931,7 +2933,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!W |
| 2931 | 2933 | try self.emitWValue(operand); |
| 2932 | 2934 | if (pl_ty.hasRuntimeBitsIgnoreComptime()) { |
| 2933 | 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 | 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 | 2961 | |
| 2960 | 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 | 2965 | if (op_is_ptr or isByRef(payload_ty, self.target)) { |
| 2964 | 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 | 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 | 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 | 3005 | } |
| 3004 | 3006 | |
| 3005 | 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 | 3009 | try self.store(payload_ptr, operand, pl_ty, 0); |
| 3008 | 3010 | |
| 3009 | 3011 | // ensure we also write '0' to the error part, so any present stack value gets overwritten by it. |
| 3010 | 3012 | try self.emitWValue(err_union); |
| 3011 | 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 | 3015 | try self.addMemArg(.i32_store16, .{ .offset = err_union.offset() + err_val_offset, .alignment = 2 }); |
| 3014 | 3016 | |
| 3015 | 3017 | return err_union; |
| ... | ... | @@ -3029,10 +3031,10 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3029 | 3031 | |
| 3030 | 3032 | const err_union = try self.allocStack(err_ty); |
| 3031 | 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 | 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 | 3038 | const len = @intCast(u32, err_ty.errorUnionPayload().abiSize(self.target)); |
| 3037 | 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 | 3986 | operand, |
| 3985 | 3987 | .{ .imm32 = 0 }, |
| 3986 | 3988 | Type.anyerror, |
| 3987 | | errUnionErrorOffset(payload_ty, self.target), |
| 3989 | @intCast(u32, errUnionErrOffset(payload_ty, self.target)), |
| 3988 | 3990 | ); |
| 3989 | 3991 | |
| 3990 | 3992 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; |
| ... | ... | @@ -3993,7 +3995,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!WValue |
| 3993 | 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 | 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 | 4623 | } }); |
| 4622 | 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 | | } |