| ... | ... | @@ -1233,7 +1233,7 @@ pub fn function( |
| 1233 | 1233 | const returns = fn_ty_index.ptr(wasm).returns.slice(wasm); |
| 1234 | 1234 | const any_returns = returns.len != 0; |
| 1235 | 1235 | |
| 1236 | | var cc_result = try resolveCallingConventionValues(pt, fn_ty, target); |
| 1236 | var cc_result = try resolveCallingConventionValues(zcu, fn_ty, target); |
| 1237 | 1237 | defer cc_result.deinit(gpa); |
| 1238 | 1238 | |
| 1239 | 1239 | var code_gen: CodeGen = .{ |
| ... | ... | @@ -1267,8 +1267,7 @@ pub fn function( |
| 1267 | 1267 | |
| 1268 | 1268 | fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function { |
| 1269 | 1269 | const wasm = cg.wasm; |
| 1270 | | const pt = cg.pt; |
| 1271 | | const zcu = pt.zcu; |
| 1270 | const zcu = cg.pt.zcu; |
| 1272 | 1271 | |
| 1273 | 1272 | const start_mir_off: u32 = @intCast(wasm.mir_instructions.len); |
| 1274 | 1273 | const start_mir_extra_off: u32 = @intCast(wasm.mir_extra.items.len); |
| ... | ... | @@ -1325,11 +1324,10 @@ const CallWValues = struct { |
| 1325 | 1324 | }; |
| 1326 | 1325 | |
| 1327 | 1326 | fn resolveCallingConventionValues( |
| 1328 | | pt: Zcu.PerThread, |
| 1327 | zcu: *const Zcu, |
| 1329 | 1328 | fn_ty: Type, |
| 1330 | 1329 | target: *const std.Target, |
| 1331 | 1330 | ) Allocator.Error!CallWValues { |
| 1332 | | const zcu = pt.zcu; |
| 1333 | 1331 | const gpa = zcu.gpa; |
| 1334 | 1332 | const ip = &zcu.intern_pool; |
| 1335 | 1333 | const fn_info = zcu.typeToFunc(fn_ty).?; |
| ... | ... | @@ -1407,8 +1405,7 @@ fn lowerArg(cg: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value: WV |
| 1407 | 1405 | return cg.lowerToStack(value); |
| 1408 | 1406 | } |
| 1409 | 1407 | |
| 1410 | | const pt = cg.pt; |
| 1411 | | const zcu = pt.zcu; |
| 1408 | const zcu = cg.pt.zcu; |
| 1412 | 1409 | const ty_classes = abi.classifyType(ty, zcu); |
| 1413 | 1410 | assert(ty_classes[0] != .none); |
| 1414 | 1411 | switch (ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -1494,7 +1491,8 @@ fn restoreStackPointer(cg: *CodeGen) !void { |
| 1494 | 1491 | /// |
| 1495 | 1492 | /// Asserts Type has codegenbits |
| 1496 | 1493 | fn allocStack(cg: *CodeGen, ty: Type) !WValue { |
| 1497 | | const zcu = cg.pt.zcu; |
| 1494 | const pt = cg.pt; |
| 1495 | const zcu = pt.zcu; |
| 1498 | 1496 | assert(ty.hasRuntimeBitsIgnoreComptime(zcu)); |
| 1499 | 1497 | if (cg.initial_stack_value == .none) { |
| 1500 | 1498 | try cg.initializeStack(); |
| ... | ... | @@ -1502,7 +1500,7 @@ fn allocStack(cg: *CodeGen, ty: Type) !WValue { |
| 1502 | 1500 | |
| 1503 | 1501 | const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse { |
| 1504 | 1502 | return cg.fail("Type {} with ABI size of {d} exceeds stack frame size", .{ |
| 1505 | | ty.fmt(cg.pt), ty.abiSize(zcu), |
| 1503 | ty.fmt(pt), ty.abiSize(zcu), |
| 1506 | 1504 | }); |
| 1507 | 1505 | }; |
| 1508 | 1506 | const abi_align = ty.abiAlignment(zcu); |
| ... | ... | @@ -2038,8 +2036,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2038 | 2036 | } |
| 2039 | 2037 | |
| 2040 | 2038 | fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 2041 | | const pt = cg.pt; |
| 2042 | | const zcu = pt.zcu; |
| 2039 | const zcu = cg.pt.zcu; |
| 2043 | 2040 | const ip = &zcu.intern_pool; |
| 2044 | 2041 | |
| 2045 | 2042 | for (body) |inst| { |
| ... | ... | @@ -2060,8 +2057,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 2060 | 2057 | } |
| 2061 | 2058 | |
| 2062 | 2059 | fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2063 | | const pt = cg.pt; |
| 2064 | | const zcu = pt.zcu; |
| 2060 | const zcu = cg.pt.zcu; |
| 2065 | 2061 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 2066 | 2062 | const operand = try cg.resolveInst(un_op); |
| 2067 | 2063 | const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?; |
| ... | ... | @@ -2104,8 +2100,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2104 | 2100 | } |
| 2105 | 2101 | |
| 2106 | 2102 | fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2107 | | const pt = cg.pt; |
| 2108 | | const zcu = pt.zcu; |
| 2103 | const zcu = cg.pt.zcu; |
| 2109 | 2104 | const child_type = cg.typeOfIndex(inst).childType(zcu); |
| 2110 | 2105 | |
| 2111 | 2106 | const result = result: { |
| ... | ... | @@ -2125,8 +2120,7 @@ fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2125 | 2120 | } |
| 2126 | 2121 | |
| 2127 | 2122 | fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2128 | | const pt = cg.pt; |
| 2129 | | const zcu = pt.zcu; |
| 2123 | const zcu = cg.pt.zcu; |
| 2130 | 2124 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 2131 | 2125 | const operand = try cg.resolveInst(un_op); |
| 2132 | 2126 | const ret_ty = cg.typeOf(un_op).childType(zcu); |
| ... | ... | @@ -2452,8 +2446,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2452 | 2446 | /// Loads an operand from the linear memory section. |
| 2453 | 2447 | /// NOTE: Leaves the value on the stack. |
| 2454 | 2448 | fn load(cg: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValue { |
| 2455 | | const pt = cg.pt; |
| 2456 | | const zcu = pt.zcu; |
| 2449 | const zcu = cg.pt.zcu; |
| 2457 | 2450 | // load local's value from memory by its stack position |
| 2458 | 2451 | try cg.emitWValue(operand); |
| 2459 | 2452 | |
| ... | ... | @@ -2526,8 +2519,7 @@ fn airArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2526 | 2519 | } |
| 2527 | 2520 | |
| 2528 | 2521 | fn airBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 2529 | | const pt = cg.pt; |
| 2530 | | const zcu = pt.zcu; |
| 2522 | const zcu = cg.pt.zcu; |
| 2531 | 2523 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 2532 | 2524 | const lhs = try cg.resolveInst(bin_op.lhs); |
| 2533 | 2525 | const rhs = try cg.resolveInst(bin_op.rhs); |
| ... | ... | @@ -2594,8 +2586,7 @@ fn binOp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WV |
| 2594 | 2586 | } |
| 2595 | 2587 | |
| 2596 | 2588 | fn binOpBigInt(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue { |
| 2597 | | const pt = cg.pt; |
| 2598 | | const zcu = pt.zcu; |
| 2589 | const zcu = cg.pt.zcu; |
| 2599 | 2590 | const int_info = ty.intInfo(zcu); |
| 2600 | 2591 | if (int_info.bits > 128) { |
| 2601 | 2592 | return cg.fail("TODO: Implement binary operation for big integers larger than 128 bits", .{}); |
| ... | ... | @@ -2877,8 +2868,7 @@ fn airUnaryFloatOp(cg: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError!v |
| 2877 | 2868 | } |
| 2878 | 2869 | |
| 2879 | 2870 | fn floatOp(cg: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) InnerError!WValue { |
| 2880 | | const pt = cg.pt; |
| 2881 | | const zcu = pt.zcu; |
| 2871 | const zcu = cg.pt.zcu; |
| 2882 | 2872 | if (ty.zigTypeTag(zcu) == .vector) { |
| 2883 | 2873 | return cg.fail("TODO: Implement floatOps for vectors", .{}); |
| 2884 | 2874 | } |
| ... | ... | @@ -2952,8 +2942,7 @@ fn floatNeg(cg: *CodeGen, ty: Type, arg: WValue) InnerError!WValue { |
| 2952 | 2942 | } |
| 2953 | 2943 | |
| 2954 | 2944 | fn airWrapBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 2955 | | const pt = cg.pt; |
| 2956 | | const zcu = pt.zcu; |
| 2945 | const zcu = cg.pt.zcu; |
| 2957 | 2946 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 2958 | 2947 | |
| 2959 | 2948 | const lhs = try cg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -3000,8 +2989,7 @@ fn wrapBinOp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerErro |
| 3000 | 2989 | /// Asserts `Type` is <= 128 bits. |
| 3001 | 2990 | /// NOTE: When the Type is <= 64 bits, leaves the value on top of the stack, if wrapping was needed. |
| 3002 | 2991 | fn wrapOperand(cg: *CodeGen, operand: WValue, ty: Type) InnerError!WValue { |
| 3003 | | const pt = cg.pt; |
| 3004 | | const zcu = pt.zcu; |
| 2992 | const zcu = cg.pt.zcu; |
| 3005 | 2993 | assert(ty.abiSize(zcu) <= 16); |
| 3006 | 2994 | const int_bits: u16 = @intCast(ty.bitSize(zcu)); // TODO use ty.intInfo(zcu).bits |
| 3007 | 2995 | const wasm_bits = toWasmBits(int_bits) orelse { |
| ... | ... | @@ -3275,8 +3263,7 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue { |
| 3275 | 3263 | } |
| 3276 | 3264 | |
| 3277 | 3265 | fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 3278 | | const pt = cg.pt; |
| 3279 | | const zcu = pt.zcu; |
| 3266 | const zcu = cg.pt.zcu; |
| 3280 | 3267 | const ip = &zcu.intern_pool; |
| 3281 | 3268 | switch (ty.zigTypeTag(zcu)) { |
| 3282 | 3269 | .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa }, |
| ... | ... | @@ -3317,16 +3304,15 @@ fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 3317 | 3304 | /// It's illegal to provide a value with a type that cannot be represented |
| 3318 | 3305 | /// as an integer value. |
| 3319 | 3306 | fn valueAsI32(cg: *const CodeGen, val: Value) i32 { |
| 3320 | | const pt = cg.pt; |
| 3321 | | const zcu = pt.zcu; |
| 3307 | const zcu = cg.pt.zcu; |
| 3322 | 3308 | const ip = &zcu.intern_pool; |
| 3323 | 3309 | |
| 3324 | 3310 | switch (val.toIntern()) { |
| 3325 | 3311 | .bool_true => return 1, |
| 3326 | 3312 | .bool_false => return 0, |
| 3327 | 3313 | else => return switch (ip.indexToKey(val.ip_index)) { |
| 3328 | | .enum_tag => |enum_tag| intIndexAsI32(ip, enum_tag.int, pt), |
| 3329 | | .int => |int| intStorageAsI32(int.storage, pt), |
| 3314 | .enum_tag => |enum_tag| intIndexAsI32(ip, enum_tag.int, zcu), |
| 3315 | .int => |int| intStorageAsI32(int.storage, zcu), |
| 3330 | 3316 | .ptr => |ptr| { |
| 3331 | 3317 | assert(ptr.base_addr == .int); |
| 3332 | 3318 | return @intCast(ptr.byte_offset); |
| ... | ... | @@ -3337,12 +3323,11 @@ fn valueAsI32(cg: *const CodeGen, val: Value) i32 { |
| 3337 | 3323 | } |
| 3338 | 3324 | } |
| 3339 | 3325 | |
| 3340 | | fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, pt: Zcu.PerThread) i32 { |
| 3341 | | return intStorageAsI32(ip.indexToKey(int).int.storage, pt); |
| 3326 | fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, zcu: *const Zcu) i32 { |
| 3327 | return intStorageAsI32(ip.indexToKey(int).int.storage, zcu); |
| 3342 | 3328 | } |
| 3343 | 3329 | |
| 3344 | | fn intStorageAsI32(storage: InternPool.Key.Int.Storage, pt: Zcu.PerThread) i32 { |
| 3345 | | const zcu = pt.zcu; |
| 3330 | fn intStorageAsI32(storage: InternPool.Key.Int.Storage, zcu: *const Zcu) i32 { |
| 3346 | 3331 | return switch (storage) { |
| 3347 | 3332 | .i64 => |x| @as(i32, @intCast(x)), |
| 3348 | 3333 | .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))), |
| ... | ... | @@ -3359,8 +3344,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3359 | 3344 | } |
| 3360 | 3345 | |
| 3361 | 3346 | fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void { |
| 3362 | | const pt = cg.pt; |
| 3363 | | const zcu = pt.zcu; |
| 3347 | const zcu = cg.pt.zcu; |
| 3364 | 3348 | const wasm_block_ty = genBlockType(block_ty, zcu, cg.target); |
| 3365 | 3349 | |
| 3366 | 3350 | // if wasm_block_ty is non-empty, we create a register to store the temporary value |
| ... | ... | @@ -3478,8 +3462,7 @@ fn airCmp(cg: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) Inne |
| 3478 | 3462 | /// NOTE: This leaves the result on top of the stack, rather than a new local. |
| 3479 | 3463 | fn cmp(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOperator) InnerError!WValue { |
| 3480 | 3464 | assert(!(lhs != .stack and rhs == .stack)); |
| 3481 | | const pt = cg.pt; |
| 3482 | | const zcu = pt.zcu; |
| 3465 | const zcu = cg.pt.zcu; |
| 3483 | 3466 | if (ty.zigTypeTag(zcu) == .optional and !ty.optionalReprIsPayload(zcu)) { |
| 3484 | 3467 | const payload_ty = ty.optionalChild(zcu); |
| 3485 | 3468 | if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| ... | ... | @@ -3699,8 +3682,7 @@ fn airUnreachable(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3699 | 3682 | } |
| 3700 | 3683 | |
| 3701 | 3684 | fn airBitcast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3702 | | const pt = cg.pt; |
| 3703 | | const zcu = pt.zcu; |
| 3685 | const zcu = cg.pt.zcu; |
| 3704 | 3686 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3705 | 3687 | const operand = try cg.resolveInst(ty_op.operand); |
| 3706 | 3688 | const wanted_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -3743,8 +3725,7 @@ fn airBitcast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3743 | 3725 | } |
| 3744 | 3726 | |
| 3745 | 3727 | fn bitcast(cg: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue { |
| 3746 | | const pt = cg.pt; |
| 3747 | | const zcu = pt.zcu; |
| 3728 | const zcu = cg.pt.zcu; |
| 3748 | 3729 | // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction |
| 3749 | 3730 | if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand; |
| 3750 | 3731 | if (wanted_ty.ip_index == .f16_type or given_ty.ip_index == .f16_type) return operand; |
| ... | ... | @@ -3762,8 +3743,7 @@ fn bitcast(cg: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inner |
| 3762 | 3743 | } |
| 3763 | 3744 | |
| 3764 | 3745 | fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3765 | | const pt = cg.pt; |
| 3766 | | const zcu = pt.zcu; |
| 3746 | const zcu = cg.pt.zcu; |
| 3767 | 3747 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 3768 | 3748 | const extra = cg.air.extraData(Air.StructField, ty_pl.payload); |
| 3769 | 3749 | |
| ... | ... | @@ -3775,8 +3755,7 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3775 | 3755 | } |
| 3776 | 3756 | |
| 3777 | 3757 | fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void { |
| 3778 | | const pt = cg.pt; |
| 3779 | | const zcu = pt.zcu; |
| 3758 | const zcu = cg.pt.zcu; |
| 3780 | 3759 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 3781 | 3760 | const struct_ptr = try cg.resolveInst(ty_op.operand); |
| 3782 | 3761 | const struct_ptr_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -4115,8 +4094,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4115 | 4094 | } |
| 4116 | 4095 | |
| 4117 | 4096 | fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode) InnerError!void { |
| 4118 | | const pt = cg.pt; |
| 4119 | | const zcu = pt.zcu; |
| 4097 | const zcu = cg.pt.zcu; |
| 4120 | 4098 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 4121 | 4099 | const operand = try cg.resolveInst(un_op); |
| 4122 | 4100 | const err_union_ty = cg.typeOf(un_op); |
| ... | ... | @@ -4148,8 +4126,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode) InnerEr |
| 4148 | 4126 | } |
| 4149 | 4127 | |
| 4150 | 4128 | fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 4151 | | const pt = cg.pt; |
| 4152 | | const zcu = pt.zcu; |
| 4129 | const zcu = cg.pt.zcu; |
| 4153 | 4130 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4154 | 4131 | |
| 4155 | 4132 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -4176,8 +4153,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) |
| 4176 | 4153 | } |
| 4177 | 4154 | |
| 4178 | 4155 | fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 4179 | | const pt = cg.pt; |
| 4180 | | const zcu = pt.zcu; |
| 4156 | const zcu = cg.pt.zcu; |
| 4181 | 4157 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4182 | 4158 | |
| 4183 | 4159 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -4230,8 +4206,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4230 | 4206 | } |
| 4231 | 4207 | |
| 4232 | 4208 | fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4233 | | const pt = cg.pt; |
| 4234 | | const zcu = pt.zcu; |
| 4209 | const zcu = cg.pt.zcu; |
| 4235 | 4210 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4236 | 4211 | |
| 4237 | 4212 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -4263,8 +4238,7 @@ fn airIntcast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4263 | 4238 | const ty = ty_op.ty.toType(); |
| 4264 | 4239 | const operand = try cg.resolveInst(ty_op.operand); |
| 4265 | 4240 | const operand_ty = cg.typeOf(ty_op.operand); |
| 4266 | | const pt = cg.pt; |
| 4267 | | const zcu = pt.zcu; |
| 4241 | const zcu = cg.pt.zcu; |
| 4268 | 4242 | if (ty.zigTypeTag(zcu) == .vector or operand_ty.zigTypeTag(zcu) == .vector) { |
| 4269 | 4243 | return cg.fail("todo Wasm intcast for vectors", .{}); |
| 4270 | 4244 | } |
| ... | ... | @@ -4287,8 +4261,7 @@ fn airIntcast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4287 | 4261 | /// Asserts type's bitsize <= 128 |
| 4288 | 4262 | /// NOTE: May leave the result on the top of the stack. |
| 4289 | 4263 | fn intcast(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue { |
| 4290 | | const pt = cg.pt; |
| 4291 | | const zcu = pt.zcu; |
| 4264 | const zcu = cg.pt.zcu; |
| 4292 | 4265 | const given_bitsize = @as(u16, @intCast(given.bitSize(zcu))); |
| 4293 | 4266 | const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(zcu))); |
| 4294 | 4267 | assert(given_bitsize <= 128); |
| ... | ... | @@ -4337,8 +4310,7 @@ fn intcast(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError! |
| 4337 | 4310 | } |
| 4338 | 4311 | |
| 4339 | 4312 | fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void { |
| 4340 | | const pt = cg.pt; |
| 4341 | | const zcu = pt.zcu; |
| 4313 | const zcu = cg.pt.zcu; |
| 4342 | 4314 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 4343 | 4315 | const operand = try cg.resolveInst(un_op); |
| 4344 | 4316 | |
| ... | ... | @@ -4379,8 +4351,7 @@ fn isNull(cg: *CodeGen, operand: WValue, optional_ty: Type, opcode: std.wasm.Opc |
| 4379 | 4351 | } |
| 4380 | 4352 | |
| 4381 | 4353 | fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4382 | | const pt = cg.pt; |
| 4383 | | const zcu = pt.zcu; |
| 4354 | const zcu = cg.pt.zcu; |
| 4384 | 4355 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4385 | 4356 | const opt_ty = cg.typeOf(ty_op.operand); |
| 4386 | 4357 | const payload_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -4402,8 +4373,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4402 | 4373 | } |
| 4403 | 4374 | |
| 4404 | 4375 | fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4405 | | const pt = cg.pt; |
| 4406 | | const zcu = pt.zcu; |
| 4376 | const zcu = cg.pt.zcu; |
| 4407 | 4377 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4408 | 4378 | const operand = try cg.resolveInst(ty_op.operand); |
| 4409 | 4379 | const opt_ty = cg.typeOf(ty_op.operand).childType(zcu); |
| ... | ... | @@ -4507,8 +4477,7 @@ fn airSliceLen(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4507 | 4477 | } |
| 4508 | 4478 | |
| 4509 | 4479 | fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4510 | | const pt = cg.pt; |
| 4511 | | const zcu = pt.zcu; |
| 4480 | const zcu = cg.pt.zcu; |
| 4512 | 4481 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4513 | 4482 | |
| 4514 | 4483 | const slice_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -4535,8 +4504,7 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4535 | 4504 | } |
| 4536 | 4505 | |
| 4537 | 4506 | fn airSliceElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4538 | | const pt = cg.pt; |
| 4539 | | const zcu = pt.zcu; |
| 4507 | const zcu = cg.pt.zcu; |
| 4540 | 4508 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4541 | 4509 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4542 | 4510 | |
| ... | ... | @@ -4579,8 +4547,7 @@ fn airTrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4579 | 4547 | const operand = try cg.resolveInst(ty_op.operand); |
| 4580 | 4548 | const wanted_ty: Type = ty_op.ty.toType(); |
| 4581 | 4549 | const op_ty = cg.typeOf(ty_op.operand); |
| 4582 | | const pt = cg.pt; |
| 4583 | | const zcu = pt.zcu; |
| 4550 | const zcu = cg.pt.zcu; |
| 4584 | 4551 | |
| 4585 | 4552 | if (wanted_ty.zigTypeTag(zcu) == .vector or op_ty.zigTypeTag(zcu) == .vector) { |
| 4586 | 4553 | return cg.fail("TODO: trunc for vectors", .{}); |
| ... | ... | @@ -4597,8 +4564,7 @@ fn airTrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4597 | 4564 | /// Truncates a given operand to a given type, discarding any overflown bits. |
| 4598 | 4565 | /// NOTE: Resulting value is left on the stack. |
| 4599 | 4566 | fn trunc(cg: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue { |
| 4600 | | const pt = cg.pt; |
| 4601 | | const zcu = pt.zcu; |
| 4567 | const zcu = cg.pt.zcu; |
| 4602 | 4568 | const given_bits = @as(u16, @intCast(given_ty.bitSize(zcu))); |
| 4603 | 4569 | if (toWasmBits(given_bits) == null) { |
| 4604 | 4570 | return cg.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits}); |
| ... | ... | @@ -4622,8 +4588,7 @@ fn airIntFromBool(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4622 | 4588 | } |
| 4623 | 4589 | |
| 4624 | 4590 | fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4625 | | const pt = cg.pt; |
| 4626 | | const zcu = pt.zcu; |
| 4591 | const zcu = cg.pt.zcu; |
| 4627 | 4592 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4628 | 4593 | |
| 4629 | 4594 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -4646,8 +4611,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4646 | 4611 | } |
| 4647 | 4612 | |
| 4648 | 4613 | fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4649 | | const pt = cg.pt; |
| 4650 | | const zcu = pt.zcu; |
| 4614 | const zcu = cg.pt.zcu; |
| 4651 | 4615 | const un_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 4652 | 4616 | const operand = try cg.resolveInst(un_op); |
| 4653 | 4617 | const ptr_ty = cg.typeOf(un_op); |
| ... | ... | @@ -4662,8 +4626,7 @@ fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4662 | 4626 | } |
| 4663 | 4627 | |
| 4664 | 4628 | fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4665 | | const pt = cg.pt; |
| 4666 | | const zcu = pt.zcu; |
| 4629 | const zcu = cg.pt.zcu; |
| 4667 | 4630 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4668 | 4631 | |
| 4669 | 4632 | const ptr_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -4694,8 +4657,7 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4694 | 4657 | } |
| 4695 | 4658 | |
| 4696 | 4659 | fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4697 | | const pt = cg.pt; |
| 4698 | | const zcu = pt.zcu; |
| 4660 | const zcu = cg.pt.zcu; |
| 4699 | 4661 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4700 | 4662 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4701 | 4663 | |
| ... | ... | @@ -4723,8 +4685,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4723 | 4685 | } |
| 4724 | 4686 | |
| 4725 | 4687 | fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 4726 | | const pt = cg.pt; |
| 4727 | | const zcu = pt.zcu; |
| 4688 | const zcu = cg.pt.zcu; |
| 4728 | 4689 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 4729 | 4690 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 4730 | 4691 | |
| ... | ... | @@ -4750,8 +4711,7 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 4750 | 4711 | } |
| 4751 | 4712 | |
| 4752 | 4713 | fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { |
| 4753 | | const pt = cg.pt; |
| 4754 | | const zcu = pt.zcu; |
| 4714 | const zcu = cg.pt.zcu; |
| 4755 | 4715 | if (safety) { |
| 4756 | 4716 | // TODO if the value is undef, write 0xaa bytes to dest |
| 4757 | 4717 | } else { |
| ... | ... | @@ -4784,8 +4744,8 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { |
| 4784 | 4744 | /// this to wasm's memset instruction. When the feature is not present, |
| 4785 | 4745 | /// we implement it manually. |
| 4786 | 4746 | fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void { |
| 4787 | | const pt = cg.pt; |
| 4788 | | const abi_size = @as(u32, @intCast(elem_ty.abiSize(pt.zcu))); |
| 4747 | const zcu = cg.pt.zcu; |
| 4748 | const abi_size = @as(u32, @intCast(elem_ty.abiSize(zcu))); |
| 4789 | 4749 | |
| 4790 | 4750 | // When bulk_memory is enabled, we lower it to wasm's memset instruction. |
| 4791 | 4751 | // If not, we lower it ourselves. |
| ... | ... | @@ -4869,8 +4829,7 @@ fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) |
| 4869 | 4829 | } |
| 4870 | 4830 | |
| 4871 | 4831 | fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4872 | | const pt = cg.pt; |
| 4873 | | const zcu = pt.zcu; |
| 4832 | const zcu = cg.pt.zcu; |
| 4874 | 4833 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 4875 | 4834 | |
| 4876 | 4835 | const array_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -4931,8 +4890,7 @@ fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4931 | 4890 | } |
| 4932 | 4891 | |
| 4933 | 4892 | fn airIntFromFloat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4934 | | const pt = cg.pt; |
| 4935 | | const zcu = pt.zcu; |
| 4893 | const zcu = cg.pt.zcu; |
| 4936 | 4894 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4937 | 4895 | |
| 4938 | 4896 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -4983,8 +4941,7 @@ fn airIntFromFloat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4983 | 4941 | } |
| 4984 | 4942 | |
| 4985 | 4943 | fn airFloatFromInt(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4986 | | const pt = cg.pt; |
| 4987 | | const zcu = pt.zcu; |
| 4944 | const zcu = cg.pt.zcu; |
| 4988 | 4945 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 4989 | 4946 | |
| 4990 | 4947 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -5036,8 +4993,7 @@ fn airFloatFromInt(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5036 | 4993 | } |
| 5037 | 4994 | |
| 5038 | 4995 | fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5039 | | const pt = cg.pt; |
| 5040 | | const zcu = pt.zcu; |
| 4996 | const zcu = cg.pt.zcu; |
| 5041 | 4997 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5042 | 4998 | const operand = try cg.resolveInst(ty_op.operand); |
| 5043 | 4999 | const ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -5405,8 +5361,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 5405 | 5361 | } |
| 5406 | 5362 | |
| 5407 | 5363 | fn cmpOptionals(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue { |
| 5408 | | const pt = cg.pt; |
| 5409 | | const zcu = pt.zcu; |
| 5364 | const zcu = cg.pt.zcu; |
| 5410 | 5365 | assert(operand_ty.hasRuntimeBitsIgnoreComptime(zcu)); |
| 5411 | 5366 | assert(op == .eq or op == .neq); |
| 5412 | 5367 | const payload_ty = operand_ty.optionalChild(zcu); |
| ... | ... | @@ -5442,8 +5397,7 @@ fn cmpOptionals(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: st |
| 5442 | 5397 | /// NOTE: Leaves the result of the comparison on top of the stack. |
| 5443 | 5398 | /// TODO: Lower this to compiler_rt call when bitsize > 128 |
| 5444 | 5399 | fn cmpBigInt(cg: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue { |
| 5445 | | const pt = cg.pt; |
| 5446 | | const zcu = pt.zcu; |
| 5400 | const zcu = cg.pt.zcu; |
| 5447 | 5401 | assert(operand_ty.abiSize(zcu) >= 16); |
| 5448 | 5402 | assert(!(lhs != .stack and rhs == .stack)); |
| 5449 | 5403 | if (operand_ty.bitSize(zcu) > 128) { |
| ... | ... | @@ -5637,8 +5591,7 @@ fn fptrunc(cg: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError! |
| 5637 | 5591 | } |
| 5638 | 5592 | |
| 5639 | 5593 | fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5640 | | const pt = cg.pt; |
| 5641 | | const zcu = pt.zcu; |
| 5594 | const zcu = cg.pt.zcu; |
| 5642 | 5595 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5643 | 5596 | |
| 5644 | 5597 | const err_set_ty = cg.typeOf(ty_op.operand).childType(zcu); |
| ... | ... | @@ -5664,8 +5617,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void |
| 5664 | 5617 | } |
| 5665 | 5618 | |
| 5666 | 5619 | fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5667 | | const pt = cg.pt; |
| 5668 | | const zcu = pt.zcu; |
| 5620 | const zcu = cg.pt.zcu; |
| 5669 | 5621 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 5670 | 5622 | const extra = cg.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 5671 | 5623 | |
| ... | ... | @@ -5686,8 +5638,7 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5686 | 5638 | } |
| 5687 | 5639 | |
| 5688 | 5640 | fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue { |
| 5689 | | const pt = cg.pt; |
| 5690 | | const zcu = pt.zcu; |
| 5641 | const zcu = cg.pt.zcu; |
| 5691 | 5642 | if (ptr_ty.isSlice(zcu)) { |
| 5692 | 5643 | return cg.slicePtr(ptr); |
| 5693 | 5644 | } else { |
| ... | ... | @@ -5696,8 +5647,7 @@ fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue { |
| 5696 | 5647 | } |
| 5697 | 5648 | |
| 5698 | 5649 | fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5699 | | const pt = cg.pt; |
| 5700 | | const zcu = pt.zcu; |
| 5650 | const zcu = cg.pt.zcu; |
| 5701 | 5651 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 5702 | 5652 | const dst = try cg.resolveInst(bin_op.lhs); |
| 5703 | 5653 | const dst_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -5788,8 +5738,7 @@ fn airPopcount(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5788 | 5738 | } |
| 5789 | 5739 | |
| 5790 | 5740 | fn airBitReverse(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5791 | | const pt = cg.pt; |
| 5792 | | const zcu = pt.zcu; |
| 5741 | const zcu = cg.pt.zcu; |
| 5793 | 5742 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5794 | 5743 | |
| 5795 | 5744 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6176,8 +6125,7 @@ fn airMaxMin( |
| 6176 | 6125 | op: enum { fmax, fmin }, |
| 6177 | 6126 | cmp_op: std.math.CompareOperator, |
| 6178 | 6127 | ) InnerError!void { |
| 6179 | | const pt = cg.pt; |
| 6180 | | const zcu = pt.zcu; |
| 6128 | const zcu = cg.pt.zcu; |
| 6181 | 6129 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6182 | 6130 | |
| 6183 | 6131 | const ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -6218,8 +6166,7 @@ fn airMaxMin( |
| 6218 | 6166 | } |
| 6219 | 6167 | |
| 6220 | 6168 | fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6221 | | const pt = cg.pt; |
| 6222 | | const zcu = pt.zcu; |
| 6169 | const zcu = cg.pt.zcu; |
| 6223 | 6170 | const pl_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6224 | 6171 | const bin_op = cg.air.extraData(Air.Bin, pl_op.payload).data; |
| 6225 | 6172 | |
| ... | ... | @@ -6253,8 +6200,7 @@ fn airMulAdd(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6253 | 6200 | } |
| 6254 | 6201 | |
| 6255 | 6202 | fn airClz(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6256 | | const pt = cg.pt; |
| 6257 | | const zcu = pt.zcu; |
| 6203 | const zcu = cg.pt.zcu; |
| 6258 | 6204 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6259 | 6205 | |
| 6260 | 6206 | const ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -6304,8 +6250,7 @@ fn airClz(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6304 | 6250 | } |
| 6305 | 6251 | |
| 6306 | 6252 | fn airCtz(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6307 | | const pt = cg.pt; |
| 6308 | | const zcu = pt.zcu; |
| 6253 | const zcu = cg.pt.zcu; |
| 6309 | 6254 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6310 | 6255 | |
| 6311 | 6256 | const ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -6406,8 +6351,7 @@ fn airTry(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6406 | 6351 | } |
| 6407 | 6352 | |
| 6408 | 6353 | fn airTryPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6409 | | const pt = cg.pt; |
| 6410 | | const zcu = pt.zcu; |
| 6354 | const zcu = cg.pt.zcu; |
| 6411 | 6355 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 6412 | 6356 | const extra = cg.air.extraData(Air.TryPtr, ty_pl.payload); |
| 6413 | 6357 | const err_union_ptr = try cg.resolveInst(extra.data.ptr); |
| ... | ... | @@ -6425,8 +6369,7 @@ fn lowerTry( |
| 6425 | 6369 | err_union_ty: Type, |
| 6426 | 6370 | operand_is_ptr: bool, |
| 6427 | 6371 | ) InnerError!WValue { |
| 6428 | | const pt = cg.pt; |
| 6429 | | const zcu = pt.zcu; |
| 6372 | const zcu = cg.pt.zcu; |
| 6430 | 6373 | if (operand_is_ptr) { |
| 6431 | 6374 | return cg.fail("TODO: lowerTry for pointers", .{}); |
| 6432 | 6375 | } |
| ... | ... | @@ -6475,8 +6418,7 @@ fn lowerTry( |
| 6475 | 6418 | } |
| 6476 | 6419 | |
| 6477 | 6420 | fn airByteSwap(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6478 | | const pt = cg.pt; |
| 6479 | | const zcu = pt.zcu; |
| 6421 | const zcu = cg.pt.zcu; |
| 6480 | 6422 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 6481 | 6423 | |
| 6482 | 6424 | const ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -6558,8 +6500,7 @@ fn airDivTrunc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6558 | 6500 | fn airDivFloor(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6559 | 6501 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6560 | 6502 | |
| 6561 | | const pt = cg.pt; |
| 6562 | | const zcu = pt.zcu; |
| 6503 | const zcu = cg.pt.zcu; |
| 6563 | 6504 | const ty = cg.typeOfIndex(inst); |
| 6564 | 6505 | const lhs = try cg.resolveInst(bin_op.lhs); |
| 6565 | 6506 | const rhs = try cg.resolveInst(bin_op.rhs); |
| ... | ... | @@ -6819,8 +6760,7 @@ fn airSatBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { |
| 6819 | 6760 | assert(op == .add or op == .sub); |
| 6820 | 6761 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 6821 | 6762 | |
| 6822 | | const pt = cg.pt; |
| 6823 | | const zcu = pt.zcu; |
| 6763 | const zcu = cg.pt.zcu; |
| 6824 | 6764 | const ty = cg.typeOfIndex(inst); |
| 6825 | 6765 | const lhs = try cg.resolveInst(bin_op.lhs); |
| 6826 | 6766 | const rhs = try cg.resolveInst(bin_op.rhs); |
| ... | ... | @@ -7041,8 +6981,7 @@ fn callIntrinsic( |
| 7041 | 6981 | args: []const WValue, |
| 7042 | 6982 | ) InnerError!WValue { |
| 7043 | 6983 | assert(param_types.len == args.len); |
| 7044 | | const pt = cg.pt; |
| 7045 | | const zcu = pt.zcu; |
| 6984 | const zcu = cg.pt.zcu; |
| 7046 | 6985 | |
| 7047 | 6986 | // Always pass over C-ABI |
| 7048 | 6987 | |
| ... | ... | @@ -7090,8 +7029,7 @@ fn airTagName(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7090 | 7029 | } |
| 7091 | 7030 | |
| 7092 | 7031 | fn airErrorSetHasValue(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7093 | | const pt = cg.pt; |
| 7094 | | const zcu = pt.zcu; |
| 7032 | const zcu = cg.pt.zcu; |
| 7095 | 7033 | const ip = &zcu.intern_pool; |
| 7096 | 7034 | const ty_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 7097 | 7035 | |
| ... | ... | @@ -7177,8 +7115,7 @@ inline fn useAtomicFeature(cg: *const CodeGen) bool { |
| 7177 | 7115 | } |
| 7178 | 7116 | |
| 7179 | 7117 | fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7180 | | const pt = cg.pt; |
| 7181 | | const zcu = pt.zcu; |
| 7118 | const zcu = cg.pt.zcu; |
| 7182 | 7119 | const ty_pl = cg.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 7183 | 7120 | const extra = cg.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 7184 | 7121 | |
| ... | ... | @@ -7251,13 +7188,13 @@ fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7251 | 7188 | } |
| 7252 | 7189 | |
| 7253 | 7190 | fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7254 | | const pt = cg.pt; |
| 7191 | const zcu = cg.pt.zcu; |
| 7255 | 7192 | const atomic_load = cg.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 7256 | 7193 | const ptr = try cg.resolveInst(atomic_load.ptr); |
| 7257 | 7194 | const ty = cg.typeOfIndex(inst); |
| 7258 | 7195 | |
| 7259 | 7196 | if (cg.useAtomicFeature()) { |
| 7260 | | const tag: std.wasm.AtomicsOpcode = switch (ty.abiSize(pt.zcu)) { |
| 7197 | const tag: std.wasm.AtomicsOpcode = switch (ty.abiSize(zcu)) { |
| 7261 | 7198 | 1 => .i32_atomic_load8_u, |
| 7262 | 7199 | 2 => .i32_atomic_load16_u, |
| 7263 | 7200 | 4 => .i32_atomic_load, |
| ... | ... | @@ -7267,7 +7204,7 @@ fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7267 | 7204 | try cg.emitWValue(ptr); |
| 7268 | 7205 | try cg.addAtomicMemArg(tag, .{ |
| 7269 | 7206 | .offset = ptr.offset(), |
| 7270 | | .alignment = @intCast(ty.abiAlignment(pt.zcu).toByteUnits().?), |
| 7207 | .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?), |
| 7271 | 7208 | }); |
| 7272 | 7209 | } else { |
| 7273 | 7210 | _ = try cg.load(ptr, ty, 0); |
| ... | ... | @@ -7277,8 +7214,7 @@ fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7277 | 7214 | } |
| 7278 | 7215 | |
| 7279 | 7216 | fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7280 | | const pt = cg.pt; |
| 7281 | | const zcu = pt.zcu; |
| 7217 | const zcu = cg.pt.zcu; |
| 7282 | 7218 | const pl_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 7283 | 7219 | const extra = cg.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 7284 | 7220 | |
| ... | ... | @@ -7452,8 +7388,7 @@ fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7452 | 7388 | } |
| 7453 | 7389 | |
| 7454 | 7390 | fn airAtomicStore(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7455 | | const pt = cg.pt; |
| 7456 | | const zcu = pt.zcu; |
| 7391 | const zcu = cg.pt.zcu; |
| 7457 | 7392 | const bin_op = cg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 7458 | 7393 | |
| 7459 | 7394 | const ptr = try cg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -7491,14 +7426,12 @@ fn airFrameAddress(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7491 | 7426 | } |
| 7492 | 7427 | |
| 7493 | 7428 | fn typeOf(cg: *CodeGen, inst: Air.Inst.Ref) Type { |
| 7494 | | const pt = cg.pt; |
| 7495 | | const zcu = pt.zcu; |
| 7429 | const zcu = cg.pt.zcu; |
| 7496 | 7430 | return cg.air.typeOf(inst, &zcu.intern_pool); |
| 7497 | 7431 | } |
| 7498 | 7432 | |
| 7499 | 7433 | fn typeOfIndex(cg: *CodeGen, inst: Air.Inst.Index) Type { |
| 7500 | | const pt = cg.pt; |
| 7501 | | const zcu = pt.zcu; |
| 7434 | const zcu = cg.pt.zcu; |
| 7502 | 7435 | return cg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 7503 | 7436 | } |
| 7504 | 7437 | |