| ... | ... | @@ -157,7 +157,7 @@ simd_immediates: std.ArrayList([16]u8) = .empty, |
| 157 | 157 | /// The Target we're emitting (used to call intInfo) |
| 158 | 158 | target: *const std.Target, |
| 159 | 159 | ptr_size: enum { wasm32, wasm64 }, |
| 160 | | pt: Zcu.PerThread, |
| 160 | zcu: *Zcu, |
| 161 | 161 | /// List of MIR Instructions |
| 162 | 162 | mir_instructions: std.MultiArrayList(Mir.Inst), |
| 163 | 163 | /// Contains extra data for MIR |
| ... | ... | @@ -380,7 +380,7 @@ pub fn deinit(cg: *CodeGen) void { |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | pub fn fail(cg: *CodeGen, comptime fmt: []const u8, args: anytype) Error { |
| 383 | | const zcu = cg.pt.zcu; |
| 383 | const zcu = cg.zcu; |
| 384 | 384 | const func = zcu.funcInfo(cg.func_index); |
| 385 | 385 | return zcu.codegenFail(func.owner_nav, fmt, args); |
| 386 | 386 | } |
| ... | ... | @@ -395,8 +395,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue { |
| 395 | 395 | const gop = try cg.values.getOrPut(cg.gpa, ref); |
| 396 | 396 | assert(!gop.found_existing); |
| 397 | 397 | |
| 398 | | const pt = cg.pt; |
| 399 | | const zcu = pt.zcu; |
| 398 | const zcu = cg.zcu; |
| 400 | 399 | const val: Value = .fromInterned(ref.toInterned().?); |
| 401 | 400 | const ty = cg.typeOf(ref); |
| 402 | 401 | if (!ty.hasRuntimeBits(zcu) and !ty.isInt(zcu) and !ty.isError(zcu)) { |
| ... | ... | @@ -420,7 +419,7 @@ fn resolveInst(cg: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue { |
| 420 | 419 | } |
| 421 | 420 | |
| 422 | 421 | fn resolveValue(cg: *CodeGen, val: Value) InnerError!WValue { |
| 423 | | const zcu = cg.pt.zcu; |
| 422 | const zcu = cg.zcu; |
| 424 | 423 | const ty = val.typeOf(zcu); |
| 425 | 424 | |
| 426 | 425 | return if (isByRef(ty, zcu, cg.target)) |
| ... | ... | @@ -761,7 +760,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void { |
| 761 | 760 | .float32 => |val| try cg.addFloat32(val), |
| 762 | 761 | .float64 => |val| try cg.addFloat64(val), |
| 763 | 762 | .nav_ref => |nav_ref| { |
| 764 | | const zcu = cg.pt.zcu; |
| 763 | const zcu = cg.zcu; |
| 765 | 764 | const ip = &zcu.intern_pool; |
| 766 | 765 | if (ip.zigTypeTag(ip.getNav(nav_ref.nav_index).resolved.?.type) == .@"fn") { |
| 767 | 766 | assert(nav_ref.offset == 0); |
| ... | ... | @@ -782,7 +781,7 @@ fn emitWValue(cg: *CodeGen, value: WValue) InnerError!void { |
| 782 | 781 | } |
| 783 | 782 | }, |
| 784 | 783 | .uav_ref => |uav| { |
| 785 | | const zcu = cg.pt.zcu; |
| 784 | const zcu = cg.zcu; |
| 786 | 785 | const ip = &zcu.intern_pool; |
| 787 | 786 | assert(!ip.isFunctionType(ip.typeOf(uav.ip_index))); |
| 788 | 787 | const gop = try cg.mir_uavs.getOrPut(cg.gpa, uav.ip_index); |
| ... | ... | @@ -853,7 +852,7 @@ fn releaseLocal(cg: *CodeGen, index: u32) void { |
| 853 | 852 | /// Creates one locals for a given `Type`. |
| 854 | 853 | /// Returns a corresponding `Wvalue` with `local` as active tag |
| 855 | 854 | fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 856 | | const zcu = cg.pt.zcu; |
| 855 | const zcu = cg.zcu; |
| 857 | 856 | const valtype = typeToValtype(ty, zcu, cg.target); |
| 858 | 857 | const free_list = cg.local_pool.freeList(valtype); |
| 859 | 858 | if (free_list.unwrap()) |index| { |
| ... | ... | @@ -870,7 +869,7 @@ fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 870 | 869 | /// Ensures a new local will be created. This is useful when it's useful |
| 871 | 870 | /// to use a zero-initialized local. |
| 872 | 871 | fn ensureAllocLocal(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 873 | | const zcu = cg.pt.zcu; |
| 872 | const zcu = cg.zcu; |
| 874 | 873 | try cg.mir_locals.ensureUnusedCapacity(cg.gpa, 1); |
| 875 | 874 | try cg.local_pool.locals.ensureUnusedCapacity(cg.gpa, 1); |
| 876 | 875 | assert(cg.mir_locals.items.len == cg.local_pool.locals.items.len); |
| ... | ... | @@ -905,7 +904,7 @@ pub fn generate( |
| 905 | 904 | |
| 906 | 905 | var code_gen: CodeGen = .{ |
| 907 | 906 | .gpa = gpa, |
| 908 | | .pt = pt, |
| 907 | .zcu = zcu, |
| 909 | 908 | .air = air.*, |
| 910 | 909 | .liveness = liveness.*.?, |
| 911 | 910 | .owner_nav = cg.owner_nav, |
| ... | ... | @@ -940,7 +939,7 @@ pub fn generate( |
| 940 | 939 | } |
| 941 | 940 | |
| 942 | 941 | fn generateInner(cg: *CodeGen, any_returns: bool) InnerError!Mir { |
| 943 | | const zcu = cg.pt.zcu; |
| 942 | const zcu = cg.zcu; |
| 944 | 943 | cg.wasm_param_count = @intCast(cg.args.len + @intFromBool(cg.return_value != .none) + @intFromBool(cg.varargs != .none)); |
| 945 | 944 | cg.initial_stack_value = try cg.ensureAllocLocal(Type.usize); |
| 946 | 945 | cg.bottom_stack_value = try cg.ensureAllocLocal(Type.usize); |
| ... | ... | @@ -1099,7 +1098,7 @@ fn lowerArg(cg: *CodeGen, cc: std.lang.CallingConvention, ty: Type, value: WValu |
| 1099 | 1098 | return cg.emitWValue(value); |
| 1100 | 1099 | } |
| 1101 | 1100 | |
| 1102 | | const zcu = cg.pt.zcu; |
| 1101 | const zcu = cg.zcu; |
| 1103 | 1102 | |
| 1104 | 1103 | switch (abi.classifyType(ty, zcu, cg.target)) { |
| 1105 | 1104 | .direct => |scalar_ty| { |
| ... | ... | @@ -1148,8 +1147,7 @@ fn restoreStackPointer(cg: *CodeGen) !void { |
| 1148 | 1147 | /// |
| 1149 | 1148 | /// Asserts Type has codegenbits |
| 1150 | 1149 | fn allocStack(cg: *CodeGen, ty: Type) !WValue { |
| 1151 | | const pt = cg.pt; |
| 1152 | | const zcu = pt.zcu; |
| 1150 | const zcu = cg.zcu; |
| 1153 | 1151 | assert(ty.hasRuntimeBits(zcu)); |
| 1154 | 1152 | |
| 1155 | 1153 | const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse { |
| ... | ... | @@ -1187,8 +1185,7 @@ fn allocStackBytes(cg: *CodeGen, size: u32, alignment: Alignment) !WValue { |
| 1187 | 1185 | /// This is different from allocStack where this will use the pointer's alignment |
| 1188 | 1186 | /// if it is set, to ensure the stack alignment will be set correctly. |
| 1189 | 1187 | fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue { |
| 1190 | | const pt = cg.pt; |
| 1191 | | const zcu = pt.zcu; |
| 1188 | const zcu = cg.zcu; |
| 1192 | 1189 | const ptr_ty = cg.typeOfIndex(inst); |
| 1193 | 1190 | const pointee_ty = ptr_ty.childType(zcu); |
| 1194 | 1191 | |
| ... | ... | @@ -1356,7 +1353,7 @@ pub fn determineSimdStoreStrategy(ty: Type, zcu: *const Zcu, target: *const std. |
| 1356 | 1353 | } |
| 1357 | 1354 | |
| 1358 | 1355 | fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1359 | | const zcu = cg.pt.zcu; |
| 1356 | const zcu = cg.zcu; |
| 1360 | 1357 | const air_tags = cg.air.instructions.items(.tag); |
| 1361 | 1358 | return switch (air_tags[@backingInt(inst)]) { |
| 1362 | 1359 | // No soft float legalizations are enabled. |
| ... | ... | @@ -1492,7 +1489,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1492 | 1489 | const rhs = try cg.resolveInst(bin_op.rhs); |
| 1493 | 1490 | const ty = cg.typeOfIndex(inst); |
| 1494 | 1491 | |
| 1495 | | if (ty.zigTypeTag(cg.pt.zcu) == .vector) { |
| 1492 | if (ty.zigTypeTag(cg.zcu) == .vector) { |
| 1496 | 1493 | return cg.fail("TODO: implement AIR op: mul_add for vectors", .{}); |
| 1497 | 1494 | } |
| 1498 | 1495 | |
| ... | ... | @@ -1510,7 +1507,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1510 | 1507 | const rhs = try cg.resolveInst(bin_op.rhs); |
| 1511 | 1508 | const ty = cg.typeOfIndex(inst); |
| 1512 | 1509 | |
| 1513 | | if (ty.zigTypeTag(cg.pt.zcu) == .vector) { |
| 1510 | if (ty.zigTypeTag(cg.zcu) == .vector) { |
| 1514 | 1511 | return cg.fail("TODO: implement AIR op: {s} for vectors", .{@tagName(tag)}); |
| 1515 | 1512 | } |
| 1516 | 1513 | |
| ... | ... | @@ -1555,7 +1552,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1555 | 1552 | defer res_tmp.free(cg); |
| 1556 | 1553 | |
| 1557 | 1554 | const result = try cg.allocStack(cg.typeOfIndex(inst)); |
| 1558 | | const offset: u32 = @intCast(ty.abiSize(cg.pt.zcu)); |
| 1555 | const offset: u32 = @intCast(ty.abiSize(cg.zcu)); |
| 1559 | 1556 | |
| 1560 | 1557 | try cg.store(result, res_tmp, ty, .{}); |
| 1561 | 1558 | try cg.store(result, ov_tmp, .u1, .{ .offset = offset }); |
| ... | ... | @@ -1675,7 +1672,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1675 | 1672 | const src_ty = cg.typeOf(ty_op.operand); |
| 1676 | 1673 | const dest_ty = cg.typeOfIndex(inst); |
| 1677 | 1674 | |
| 1678 | | if (dest_ty.zigTypeTag(cg.pt.zcu) == .vector) { |
| 1675 | if (dest_ty.zigTypeTag(cg.zcu) == .vector) { |
| 1679 | 1676 | return cg.fail("TODO: implement AIR op: {s} for vectors", .{@tagName(tag)}); |
| 1680 | 1677 | } |
| 1681 | 1678 | |
| ... | ... | @@ -1959,7 +1956,7 @@ fn genInst(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1959 | 1956 | } |
| 1960 | 1957 | |
| 1961 | 1958 | fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 1962 | | const zcu = cg.pt.zcu; |
| 1959 | const zcu = cg.zcu; |
| 1963 | 1960 | const ip = &zcu.intern_pool; |
| 1964 | 1961 | |
| 1965 | 1962 | for (body) |inst| { |
| ... | ... | @@ -1979,7 +1976,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 1979 | 1976 | } |
| 1980 | 1977 | |
| 1981 | 1978 | fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 1982 | | const zcu = cg.pt.zcu; |
| 1979 | const zcu = cg.zcu; |
| 1983 | 1980 | const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op; |
| 1984 | 1981 | const operand = try cg.resolveInst(un_op); |
| 1985 | 1982 | const fn_info = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?; |
| ... | ... | @@ -2019,7 +2016,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2019 | 2016 | } |
| 2020 | 2017 | |
| 2021 | 2018 | fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2022 | | const zcu = cg.pt.zcu; |
| 2019 | const zcu = cg.zcu; |
| 2023 | 2020 | const child_type = cg.typeOfIndex(inst).childType(zcu); |
| 2024 | 2021 | |
| 2025 | 2022 | const result = result: { |
| ... | ... | @@ -2039,7 +2036,7 @@ fn airRetPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2039 | 2036 | } |
| 2040 | 2037 | |
| 2041 | 2038 | fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2042 | | const zcu = cg.pt.zcu; |
| 2039 | const zcu = cg.zcu; |
| 2043 | 2040 | const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op; |
| 2044 | 2041 | const operand = try cg.resolveInst(un_op); |
| 2045 | 2042 | const ret_ty = cg.typeOf(un_op).childType(zcu); |
| ... | ... | @@ -2076,8 +2073,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier) |
| 2076 | 2073 | const args = call.args; |
| 2077 | 2074 | const ty = cg.typeOf(call.callee); |
| 2078 | 2075 | |
| 2079 | | const pt = cg.pt; |
| 2080 | | const zcu = pt.zcu; |
| 2076 | const zcu = cg.zcu; |
| 2081 | 2077 | const ip = &zcu.intern_pool; |
| 2082 | 2078 | const fn_ty = switch (ty.zigTypeTag(zcu)) { |
| 2083 | 2079 | .@"fn" => ty, |
| ... | ... | @@ -2250,7 +2246,7 @@ fn airVaCopy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2250 | 2246 | } |
| 2251 | 2247 | |
| 2252 | 2248 | fn airVaArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2253 | | const zcu = cg.pt.zcu; |
| 2249 | const zcu = cg.zcu; |
| 2254 | 2250 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 2255 | 2251 | const operand = try cg.resolveInst(ty_op.operand); |
| 2256 | 2252 | |
| ... | ... | @@ -2322,8 +2318,7 @@ fn airAlloc(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2322 | 2318 | } |
| 2323 | 2319 | |
| 2324 | 2320 | fn airStore(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { |
| 2325 | | const pt = cg.pt; |
| 2326 | | const zcu = pt.zcu; |
| 2321 | const zcu = cg.zcu; |
| 2327 | 2322 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 2328 | 2323 | |
| 2329 | 2324 | const lhs = try cg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -2366,8 +2361,7 @@ const MemArg = struct { |
| 2366 | 2361 | |
| 2367 | 2362 | fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) InnerError!void { |
| 2368 | 2363 | assert(!(lhs != .stack and rhs == .stack)); |
| 2369 | | const pt = cg.pt; |
| 2370 | | const zcu = pt.zcu; |
| 2364 | const zcu = cg.zcu; |
| 2371 | 2365 | const abi_size = ty.abiSize(zcu); |
| 2372 | 2366 | |
| 2373 | 2367 | if (!ty.hasRuntimeBits(zcu)) return; |
| ... | ... | @@ -2432,8 +2426,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) Inner |
| 2432 | 2426 | } |
| 2433 | 2427 | |
| 2434 | 2428 | fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2435 | | const pt = cg.pt; |
| 2436 | | const zcu = pt.zcu; |
| 2429 | const zcu = cg.zcu; |
| 2437 | 2430 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 2438 | 2431 | const operand = try cg.resolveInst(ty_op.operand); |
| 2439 | 2432 | const elem_ty = ty_op.ty; |
| ... | ... | @@ -2459,7 +2452,7 @@ fn airLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2459 | 2452 | /// Loads an operand from the linear memory section. |
| 2460 | 2453 | /// NOTE: Leaves the value on the stack, if isByRef == false. |
| 2461 | 2454 | fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WValue { |
| 2462 | | const zcu = cg.pt.zcu; |
| 2455 | const zcu = cg.zcu; |
| 2463 | 2456 | |
| 2464 | 2457 | const natural_alignment = ty.abiAlignment(zcu); |
| 2465 | 2458 | // wasm memory instruction alignment is <= access width |
| ... | ... | @@ -2537,8 +2530,7 @@ fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WVal |
| 2537 | 2530 | } |
| 2538 | 2531 | |
| 2539 | 2532 | fn airArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 2540 | | const pt = cg.pt; |
| 2541 | | const zcu = pt.zcu; |
| 2533 | const zcu = cg.zcu; |
| 2542 | 2534 | const arg_index = cg.arg_index; |
| 2543 | 2535 | const arg = cg.args[arg_index]; |
| 2544 | 2536 | const cc = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?.cc; |
| ... | ... | @@ -2590,7 +2582,7 @@ const IntType = struct { |
| 2590 | 2582 | // Adapted from x86_64 backend |
| 2591 | 2583 | // Differ from Type.intInfo as it treats pointers/booleans/packed/enums/errors as integer |
| 2592 | 2584 | fn fromType(cg: *CodeGen, ty: Type) IntType { |
| 2593 | | const zcu = cg.pt.zcu; |
| 2585 | const zcu = cg.zcu; |
| 2594 | 2586 | const ip = &zcu.intern_pool; |
| 2595 | 2587 | var ty_index = ty.ip_index; |
| 2596 | 2588 | while (true) switch (ip.indexToKey(ty_index)) { |
| ... | ... | @@ -5041,8 +5033,7 @@ fn floatFromInt(cg: *CodeGen, dest_ty: FloatType, src_ty: IntType, operand: WVal |
| 5041 | 5033 | } |
| 5042 | 5034 | |
| 5043 | 5035 | fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerError!WValue { |
| 5044 | | const pt = cg.pt; |
| 5045 | | const zcu = pt.zcu; |
| 5036 | const zcu = cg.zcu; |
| 5046 | 5037 | const ip = &zcu.intern_pool; |
| 5047 | 5038 | const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; |
| 5048 | 5039 | const offset: u64 = prev_offset + ptr.byte_offset; |
| ... | ... | @@ -5056,7 +5047,10 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro |
| 5056 | 5047 | .{ .uav_ref = .{ .ip_index = uav.val, .offset = @intCast(offset), .orig_ptr_ty = uav.orig_ty } } |
| 5057 | 5048 | else |
| 5058 | 5049 | .{ .imm32 = @intCast(Type.fromInterned(uav.orig_ty).ptrAlignment(zcu).forward(@as(u32, 0xaaaaaaaa))) }, |
| 5059 | | .int => return cg.lowerConstant(try pt.intValue(.usize, offset)), |
| 5050 | .int => return switch (cg.ptr_size) { |
| 5051 | .wasm32 => .{ .imm32 = @intCast(offset) }, |
| 5052 | .wasm64 => .{ .imm64 = offset }, |
| 5053 | }, |
| 5060 | 5054 | .eu_payload => |eu_ptr| try cg.lowerPtr( |
| 5061 | 5055 | eu_ptr, |
| 5062 | 5056 | offset + codegen.errUnionPayloadOffset( |
| ... | ... | @@ -5095,8 +5089,7 @@ fn lowerPtr(cg: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerErro |
| 5095 | 5089 | |
| 5096 | 5090 | /// Asserts that `isByRef` returns `false` for `val.typeOf(zcu)`. |
| 5097 | 5091 | fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue { |
| 5098 | | const pt = cg.pt; |
| 5099 | | const zcu = pt.zcu; |
| 5092 | const zcu = cg.zcu; |
| 5100 | 5093 | const ty = val.typeOf(zcu); |
| 5101 | 5094 | assert(!isByRef(ty, zcu, cg.target)); |
| 5102 | 5095 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -5154,22 +5147,16 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue { |
| 5154 | 5147 | } |
| 5155 | 5148 | }, |
| 5156 | 5149 | .err => |err| { |
| 5157 | | const int = try pt.getErrorValue(err.name); |
| 5150 | const int = ip.getErrorValueIfExists(err.name).?; |
| 5158 | 5151 | return .{ .imm32 = int }; |
| 5159 | 5152 | }, |
| 5160 | 5153 | .error_union => |error_union| { |
| 5161 | | const err_int_ty = try pt.errorIntType(); |
| 5162 | | const err_val: Value = switch (error_union.val) { |
| 5163 | | .err_name => |err_name| .fromInterned(try pt.intern(.{ .err = .{ |
| 5164 | | .ty = ty.errorUnionSet(zcu).toIntern(), |
| 5165 | | .name = err_name, |
| 5166 | | } })), |
| 5167 | | .payload => try pt.intValue(err_int_ty, 0), |
| 5168 | | }; |
| 5169 | 5154 | const payload_type = ty.errorUnionPayload(zcu); |
| 5170 | 5155 | if (!payload_type.hasRuntimeBits(zcu)) { |
| 5171 | | // We use the error type directly as the type. |
| 5172 | | return cg.lowerConstant(err_val); |
| 5156 | return .{ .imm32 = switch (error_union.val) { |
| 5157 | .err_name => |err_name| ip.getErrorValueIfExists(err_name).?, |
| 5158 | .payload => 0, |
| 5159 | } }; |
| 5173 | 5160 | } |
| 5174 | 5161 | |
| 5175 | 5162 | return cg.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{}); |
| ... | ... | @@ -5233,7 +5220,7 @@ fn storeSimdImmd(cg: *CodeGen, value: [16]u8) !WValue { |
| 5233 | 5220 | } |
| 5234 | 5221 | |
| 5235 | 5222 | fn emitUndefined(cg: *CodeGen, ty: Type) InnerError!WValue { |
| 5236 | | const zcu = cg.pt.zcu; |
| 5223 | const zcu = cg.zcu; |
| 5237 | 5224 | switch (ty.zigTypeTag(zcu)) { |
| 5238 | 5225 | .vector => return cg.storeSimdImmd(@splat(0xaa)), |
| 5239 | 5226 | .bool, .error_set => return .{ .imm32 = 0xaaaaaaaa }, |
| ... | ... | @@ -5276,7 +5263,7 @@ fn airBlock(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5276 | 5263 | } |
| 5277 | 5264 | |
| 5278 | 5265 | fn lowerBlock(cg: *CodeGen, inst: Air.Inst.Index, block_ty: Type, body: []const Air.Inst.Index) InnerError!void { |
| 5279 | | const zcu = cg.pt.zcu; |
| 5266 | const zcu = cg.zcu; |
| 5280 | 5267 | |
| 5281 | 5268 | if (block_ty.isNoReturn(zcu)) { |
| 5282 | 5269 | assert(cg.liveness.getBlock(inst).deaths.len == 0); |
| ... | ... | @@ -5385,7 +5372,7 @@ fn airCmp(cg: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) Inne |
| 5385 | 5372 | const lhs = try cg.resolveInst(bin_op.lhs); |
| 5386 | 5373 | const rhs = try cg.resolveInst(bin_op.rhs); |
| 5387 | 5374 | const operand_ty = cg.typeOf(bin_op.lhs); |
| 5388 | | const zcu = cg.pt.zcu; |
| 5375 | const zcu = cg.zcu; |
| 5389 | 5376 | |
| 5390 | 5377 | const type_tag = operand_ty.zigTypeTag(zcu); |
| 5391 | 5378 | |
| ... | ... | @@ -5617,10 +5604,10 @@ fn airCmpLteErrorsLen(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5617 | 5604 | const operand = try cg.resolveInst(un_op); |
| 5618 | 5605 | |
| 5619 | 5606 | try cg.emitWValue(operand); |
| 5620 | | const pt = cg.pt; |
| 5621 | | const err_int_ty = try pt.errorIntType(); |
| 5607 | const zcu = cg.zcu; |
| 5608 | const err_int_ty: IntType = .{ .is_signed = false, .bits = zcu.errorSetBits() }; |
| 5622 | 5609 | try cg.addTag(.errors_len); |
| 5623 | | const result = try cg.intCmp(.fromType(cg, err_int_ty), .lt, .stack, .stack); |
| 5610 | const result = try cg.intCmp(err_int_ty, .lt, .stack, .stack); |
| 5624 | 5611 | |
| 5625 | 5612 | return cg.finishAir(inst, result, &.{un_op}); |
| 5626 | 5613 | } |
| ... | ... | @@ -5676,7 +5663,7 @@ fn airUnreachable(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5676 | 5663 | } |
| 5677 | 5664 | |
| 5678 | 5665 | fn airNopCast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5679 | | const zcu = cg.pt.zcu; |
| 5666 | const zcu = cg.zcu; |
| 5680 | 5667 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 5681 | 5668 | |
| 5682 | 5669 | const operand_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5690,7 +5677,7 @@ fn airNopCast(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5690 | 5677 | } |
| 5691 | 5678 | |
| 5692 | 5679 | fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5693 | | const zcu = cg.pt.zcu; |
| 5680 | const zcu = cg.zcu; |
| 5694 | 5681 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 5695 | 5682 | |
| 5696 | 5683 | const operand_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5709,7 +5696,7 @@ fn airIntFromPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5709 | 5696 | } |
| 5710 | 5697 | |
| 5711 | 5698 | fn airUnionFromEnum(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5712 | | const zcu = cg.pt.zcu; |
| 5699 | const zcu = cg.zcu; |
| 5713 | 5700 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 5714 | 5701 | |
| 5715 | 5702 | const union_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -5741,7 +5728,7 @@ const BitcastClass = union(enum) { |
| 5741 | 5728 | }; |
| 5742 | 5729 | |
| 5743 | 5730 | fn bitcastClass(cg: *CodeGen, ty: Type) BitcastClass { |
| 5744 | | const zcu = cg.pt.zcu; |
| 5731 | const zcu = cg.zcu; |
| 5745 | 5732 | return switch (ty.zigTypeTag(zcu)) { |
| 5746 | 5733 | .bool, |
| 5747 | 5734 | .int, |
| ... | ... | @@ -5759,7 +5746,7 @@ fn bitcastClass(cg: *CodeGen, ty: Type) BitcastClass { |
| 5759 | 5746 | fn bitcast(cg: *CodeGen, dest_ty: Type, src_ty: Type, operand: WValue) InnerError!WValue { |
| 5760 | 5747 | if (dest_ty.eql(src_ty)) return operand; |
| 5761 | 5748 | |
| 5762 | | const zcu = cg.pt.zcu; |
| 5749 | const zcu = cg.zcu; |
| 5763 | 5750 | const src_class = cg.bitcastClass(src_ty); |
| 5764 | 5751 | const dest_class = cg.bitcastClass(dest_ty); |
| 5765 | 5752 | const src_by_ref = isByRef(src_ty, zcu, cg.target); |
| ... | ... | @@ -5835,7 +5822,7 @@ fn bitcast(cg: *CodeGen, dest_ty: Type, src_ty: Type, operand: WValue) InnerErro |
| 5835 | 5822 | } |
| 5836 | 5823 | |
| 5837 | 5824 | fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5838 | | const zcu = cg.pt.zcu; |
| 5825 | const zcu = cg.zcu; |
| 5839 | 5826 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 5840 | 5827 | const extra = cg.air.extraData(Air.StructField, ty_pl.payload); |
| 5841 | 5828 | |
| ... | ... | @@ -5847,7 +5834,7 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5847 | 5834 | } |
| 5848 | 5835 | |
| 5849 | 5836 | fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void { |
| 5850 | | const zcu = cg.pt.zcu; |
| 5837 | const zcu = cg.zcu; |
| 5851 | 5838 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 5852 | 5839 | const struct_ptr = try cg.resolveInst(ty_op.operand); |
| 5853 | 5840 | const struct_ptr_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -5865,8 +5852,7 @@ fn structFieldPtr( |
| 5865 | 5852 | struct_ty: Type, |
| 5866 | 5853 | index: u32, |
| 5867 | 5854 | ) InnerError!WValue { |
| 5868 | | const pt = cg.pt; |
| 5869 | | const zcu = pt.zcu; |
| 5855 | const zcu = cg.zcu; |
| 5870 | 5856 | const result_ty = cg.typeOfIndex(inst); |
| 5871 | 5857 | const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu); |
| 5872 | 5858 | |
| ... | ... | @@ -5888,8 +5874,7 @@ fn structFieldPtr( |
| 5888 | 5874 | } |
| 5889 | 5875 | |
| 5890 | 5876 | fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5891 | | const pt = cg.pt; |
| 5892 | | const zcu = pt.zcu; |
| 5877 | const zcu = cg.zcu; |
| 5893 | 5878 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 5894 | 5879 | const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data; |
| 5895 | 5880 | |
| ... | ... | @@ -5917,8 +5902,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5917 | 5902 | |
| 5918 | 5903 | // Both `.switch_br` and `.loop_switch_br` are noreturn. |
| 5919 | 5904 | fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index, is_dispatch_loop: bool) InnerError!void { |
| 5920 | | const pt = cg.pt; |
| 5921 | | const zcu = pt.zcu; |
| 5905 | const zcu = cg.zcu; |
| 5922 | 5906 | |
| 5923 | 5907 | const switch_br = cg.air.unwrapSwitch(inst); |
| 5924 | 5908 | const target_ty = cg.typeOf(switch_br.operand); |
| ... | ... | @@ -6146,7 +6130,7 @@ fn airSwitchDispatch(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6146 | 6130 | } |
| 6147 | 6131 | |
| 6148 | 6132 | fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void { |
| 6149 | | const zcu = cg.pt.zcu; |
| 6133 | const zcu = cg.zcu; |
| 6150 | 6134 | const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op; |
| 6151 | 6135 | const operand = try cg.resolveInst(un_op); |
| 6152 | 6136 | const err_union_ty = switch (op_kind) { |
| ... | ... | @@ -6185,7 +6169,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind |
| 6185 | 6169 | /// E!T -> T op_is_ptr == false |
| 6186 | 6170 | /// *(E!T) -> *T op_is_prt == true |
| 6187 | 6171 | fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 6188 | | const zcu = cg.pt.zcu; |
| 6172 | const zcu = cg.zcu; |
| 6189 | 6173 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6190 | 6174 | |
| 6191 | 6175 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6217,7 +6201,7 @@ fn airUnwrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) |
| 6217 | 6201 | /// *(E!T) -> E op_is_ptr == true |
| 6218 | 6202 | /// NOTE: op_is_ptr will not change return type |
| 6219 | 6203 | fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void { |
| 6220 | | const zcu = cg.pt.zcu; |
| 6204 | const zcu = cg.zcu; |
| 6221 | 6205 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6222 | 6206 | |
| 6223 | 6207 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6242,7 +6226,7 @@ fn airUnwrapErrUnionError(cg: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) I |
| 6242 | 6226 | } |
| 6243 | 6227 | |
| 6244 | 6228 | fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6245 | | const zcu = cg.pt.zcu; |
| 6229 | const zcu = cg.zcu; |
| 6246 | 6230 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6247 | 6231 | |
| 6248 | 6232 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6271,7 +6255,7 @@ fn airWrapErrUnionPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6271 | 6255 | } |
| 6272 | 6256 | |
| 6273 | 6257 | fn airWrapErrUnionErr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6274 | | const zcu = cg.pt.zcu; |
| 6258 | const zcu = cg.zcu; |
| 6275 | 6259 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6276 | 6260 | |
| 6277 | 6261 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6311,8 +6295,7 @@ fn airIsNull(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kin |
| 6311 | 6295 | /// For a given type and operand, checks if it's considered `null`. |
| 6312 | 6296 | /// NOTE: Leaves the result on the stack |
| 6313 | 6297 | fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, op_kind: OpKind) InnerError!WValue { |
| 6314 | | const pt = cg.pt; |
| 6315 | | const zcu = pt.zcu; |
| 6298 | const zcu = cg.zcu; |
| 6316 | 6299 | const optional_ty = switch (op_kind) { |
| 6317 | 6300 | .value => op_ty, |
| 6318 | 6301 | .ptr => op_ty.childType(zcu), |
| ... | ... | @@ -6357,7 +6340,7 @@ fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, o |
| 6357 | 6340 | } |
| 6358 | 6341 | |
| 6359 | 6342 | fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6360 | | const zcu = cg.pt.zcu; |
| 6343 | const zcu = cg.zcu; |
| 6361 | 6344 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6362 | 6345 | const opt_ty = cg.typeOf(ty_op.operand); |
| 6363 | 6346 | const payload_ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -6379,7 +6362,7 @@ fn airOptionalPayload(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6379 | 6362 | } |
| 6380 | 6363 | |
| 6381 | 6364 | fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6382 | | const zcu = cg.pt.zcu; |
| 6365 | const zcu = cg.zcu; |
| 6383 | 6366 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6384 | 6367 | const operand = try cg.resolveInst(ty_op.operand); |
| 6385 | 6368 | const opt_ty = cg.typeOf(ty_op.operand).childType(zcu); |
| ... | ... | @@ -6396,8 +6379,7 @@ fn airOptionalPayloadPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6396 | 6379 | } |
| 6397 | 6380 | |
| 6398 | 6381 | fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6399 | | const pt = cg.pt; |
| 6400 | | const zcu = pt.zcu; |
| 6382 | const zcu = cg.zcu; |
| 6401 | 6383 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6402 | 6384 | const operand = try cg.resolveInst(ty_op.operand); |
| 6403 | 6385 | const opt_ty = cg.typeOf(ty_op.operand).childType(zcu); |
| ... | ... | @@ -6421,8 +6403,7 @@ fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void |
| 6421 | 6403 | fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6422 | 6404 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6423 | 6405 | const payload_ty = cg.typeOf(ty_op.operand); |
| 6424 | | const pt = cg.pt; |
| 6425 | | const zcu = pt.zcu; |
| 6406 | const zcu = cg.zcu; |
| 6426 | 6407 | |
| 6427 | 6408 | const result = result: { |
| 6428 | 6409 | if (!payload_ty.hasRuntimeBits(zcu)) { |
| ... | ... | @@ -6478,7 +6459,7 @@ fn airSliceLen(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6478 | 6459 | } |
| 6479 | 6460 | |
| 6480 | 6461 | fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6481 | | const zcu = cg.pt.zcu; |
| 6462 | const zcu = cg.zcu; |
| 6482 | 6463 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 6483 | 6464 | |
| 6484 | 6465 | const slice_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -6499,7 +6480,7 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6499 | 6480 | } |
| 6500 | 6481 | |
| 6501 | 6482 | fn airSliceElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6502 | | const zcu = cg.pt.zcu; |
| 6483 | const zcu = cg.zcu; |
| 6503 | 6484 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 6504 | 6485 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6505 | 6486 | |
| ... | ... | @@ -6534,7 +6515,7 @@ fn sliceLen(cg: *CodeGen, operand: WValue) InnerError!WValue { |
| 6534 | 6515 | } |
| 6535 | 6516 | |
| 6536 | 6517 | fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6537 | | const zcu = cg.pt.zcu; |
| 6518 | const zcu = cg.zcu; |
| 6538 | 6519 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6539 | 6520 | |
| 6540 | 6521 | const operand = try cg.resolveInst(ty_op.operand); |
| ... | ... | @@ -6554,7 +6535,7 @@ fn airArrayToSlice(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6554 | 6535 | } |
| 6555 | 6536 | |
| 6556 | 6537 | fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6557 | | const zcu = cg.pt.zcu; |
| 6538 | const zcu = cg.zcu; |
| 6558 | 6539 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 6559 | 6540 | |
| 6560 | 6541 | const ptr_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -6579,7 +6560,7 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6579 | 6560 | } |
| 6580 | 6561 | |
| 6581 | 6562 | fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6582 | | const zcu = cg.pt.zcu; |
| 6563 | const zcu = cg.zcu; |
| 6583 | 6564 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 6584 | 6565 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6585 | 6566 | |
| ... | ... | @@ -6604,7 +6585,7 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6604 | 6585 | } |
| 6605 | 6586 | |
| 6606 | 6587 | fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: PointerOffsetOp) InnerError!void { |
| 6607 | | const zcu = cg.pt.zcu; |
| 6588 | const zcu = cg.zcu; |
| 6608 | 6589 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 6609 | 6590 | const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; |
| 6610 | 6591 | |
| ... | ... | @@ -6623,7 +6604,7 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: PointerOffsetOp) InnerErr |
| 6623 | 6604 | } |
| 6624 | 6605 | |
| 6625 | 6606 | fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { |
| 6626 | | const zcu = cg.pt.zcu; |
| 6607 | const zcu = cg.zcu; |
| 6627 | 6608 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 6628 | 6609 | |
| 6629 | 6610 | const ptr = try cg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -6657,7 +6638,7 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { |
| 6657 | 6638 | /// this to wasm's memset instruction. When the feature is not present, |
| 6658 | 6639 | /// we implement it manually. |
| 6659 | 6640 | fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void { |
| 6660 | | const zcu = cg.pt.zcu; |
| 6641 | const zcu = cg.zcu; |
| 6661 | 6642 | const abi_size = @as(u32, @intCast(elem_ty.abiSize(zcu))); |
| 6662 | 6643 | const len_known_neq_0 = switch (len) { |
| 6663 | 6644 | .imm32 => |imm| if (imm != 0) true else return, |
| ... | ... | @@ -6774,7 +6755,7 @@ fn memset(cg: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) |
| 6774 | 6755 | } |
| 6775 | 6756 | |
| 6776 | 6757 | fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6777 | | const zcu = cg.pt.zcu; |
| 6758 | const zcu = cg.zcu; |
| 6778 | 6759 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 6779 | 6760 | |
| 6780 | 6761 | const array_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -6828,7 +6809,7 @@ fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6828 | 6809 | } |
| 6829 | 6810 | |
| 6830 | 6811 | fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6831 | | const zcu = cg.pt.zcu; |
| 6812 | const zcu = cg.zcu; |
| 6832 | 6813 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 6833 | 6814 | const operand = try cg.resolveInst(ty_op.operand); |
| 6834 | 6815 | const ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -6899,8 +6880,7 @@ fn airSelect(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6899 | 6880 | } |
| 6900 | 6881 | |
| 6901 | 6882 | fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6902 | | const pt = cg.pt; |
| 6903 | | const zcu = pt.zcu; |
| 6883 | const zcu = cg.zcu; |
| 6904 | 6884 | |
| 6905 | 6885 | const unwrapped = cg.air.unwrapShuffleOne(zcu, inst); |
| 6906 | 6886 | const result_ty = unwrapped.result_ty; |
| ... | ... | @@ -6931,8 +6911,7 @@ fn airShuffleOne(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6931 | 6911 | } |
| 6932 | 6912 | |
| 6933 | 6913 | fn airShuffleTwo(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 6934 | | const pt = cg.pt; |
| 6935 | | const zcu = pt.zcu; |
| 6914 | const zcu = cg.zcu; |
| 6936 | 6915 | |
| 6937 | 6916 | const unwrapped = cg.air.unwrapShuffleTwo(zcu, inst); |
| 6938 | 6917 | const result_ty = unwrapped.result_ty; |
| ... | ... | @@ -7008,8 +6987,7 @@ fn airReduce(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7008 | 6987 | } |
| 7009 | 6988 | |
| 7010 | 6989 | fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7011 | | const pt = cg.pt; |
| 7012 | | const zcu = pt.zcu; |
| 6990 | const zcu = cg.zcu; |
| 7013 | 6991 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 7014 | 6992 | const result_ty = cg.typeOfIndex(inst); |
| 7015 | 6993 | const len = @as(usize, @intCast(result_ty.arrayLen(zcu))); |
| ... | ... | @@ -7067,9 +7045,10 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7067 | 7045 | else => { |
| 7068 | 7046 | const result = try cg.allocStack(result_ty); |
| 7069 | 7047 | for (elements, 0..) |elem, elem_index| { |
| 7070 | | if (try result_ty.structFieldValueComptime(pt, elem_index) != null) continue; |
| 7048 | if (result_ty.structFieldIsComptime(elem_index, zcu)) continue; |
| 7071 | 7049 | |
| 7072 | 7050 | const elem_ty = result_ty.fieldType(elem_index, zcu); |
| 7051 | if (!elem_ty.hasRuntimeBits(zcu)) continue; |
| 7073 | 7052 | const field_offset = result_ty.structFieldOffset(elem_index, zcu); |
| 7074 | 7053 | |
| 7075 | 7054 | const value = try cg.resolveInst(elem); |
| ... | ... | @@ -7089,8 +7068,7 @@ fn airAggregateInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7089 | 7068 | } |
| 7090 | 7069 | |
| 7091 | 7070 | fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7092 | | const pt = cg.pt; |
| 7093 | | const zcu = pt.zcu; |
| 7071 | const zcu = cg.zcu; |
| 7094 | 7072 | const ip = &zcu.intern_pool; |
| 7095 | 7073 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 7096 | 7074 | const extra = cg.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| ... | ... | @@ -7102,11 +7080,27 @@ fn airUnionInit(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7102 | 7080 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]); |
| 7103 | 7081 | const field_name = ip.loadEnumType(union_obj.enum_tag_type).field_names.get(ip)[extra.field_index]; |
| 7104 | 7082 | |
| 7105 | | const tag_int = blk: { |
| 7083 | const tag_int: WValue = blk: { |
| 7106 | 7084 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); |
| 7107 | 7085 | const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?; |
| 7108 | | const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index); |
| 7109 | | break :blk try cg.lowerConstant(tag_val); |
| 7086 | const enum_type = ip.loadEnumType(tag_ty.toIntern()); |
| 7087 | const int_ty = Type.fromInterned(enum_type.int_tag_type); |
| 7088 | const int_bits = int_ty.intInfo(zcu).bits; |
| 7089 | if (int_bits > 64) { |
| 7090 | return cg.fail("TODO: union tags > 64 bits", .{}); |
| 7091 | } |
| 7092 | |
| 7093 | if (enum_type.field_values.len == 0) { |
| 7094 | // Auto-numbered fields. |
| 7095 | break :blk switch (int_bits) { |
| 7096 | 0...32 => .{ .imm32 = enum_field_index }, |
| 7097 | 33...64 => .{ .imm64 = enum_field_index }, |
| 7098 | else => unreachable, |
| 7099 | }; |
| 7100 | } |
| 7101 | |
| 7102 | const int_value = enum_type.field_values.get(ip)[enum_field_index]; |
| 7103 | break :blk try cg.lowerConstant(.fromInterned(int_value)); |
| 7110 | 7104 | }; |
| 7111 | 7105 | if (layout.payload_size == 0) { |
| 7112 | 7106 | if (layout.tag_size == 0) { |
| ... | ... | @@ -7167,8 +7161,7 @@ fn airWasmMemoryGrow(cg: *CodeGen, inst: Air.Inst.Index) !void { |
| 7167 | 7161 | } |
| 7168 | 7162 | |
| 7169 | 7163 | fn airSetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7170 | | const pt = cg.pt; |
| 7171 | | const zcu = pt.zcu; |
| 7164 | const zcu = cg.zcu; |
| 7172 | 7165 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 7173 | 7166 | const un_ty = cg.typeOf(bin_op.lhs).childType(zcu); |
| 7174 | 7167 | const tag_ty = cg.typeOf(bin_op.rhs); |
| ... | ... | @@ -7192,7 +7185,7 @@ fn airSetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7192 | 7185 | } |
| 7193 | 7186 | |
| 7194 | 7187 | fn airGetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7195 | | const zcu = cg.pt.zcu; |
| 7188 | const zcu = cg.zcu; |
| 7196 | 7189 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 7197 | 7190 | |
| 7198 | 7191 | const un_ty = cg.typeOf(ty_op.operand); |
| ... | ... | @@ -7212,7 +7205,7 @@ fn airGetUnionTag(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7212 | 7205 | } |
| 7213 | 7206 | |
| 7214 | 7207 | fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7215 | | const zcu = cg.pt.zcu; |
| 7208 | const zcu = cg.zcu; |
| 7216 | 7209 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 7217 | 7210 | |
| 7218 | 7211 | const err_set_ty = cg.typeOf(ty_op.operand).childType(zcu); |
| ... | ... | @@ -7236,8 +7229,7 @@ fn airErrUnionPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void |
| 7236 | 7229 | } |
| 7237 | 7230 | |
| 7238 | 7231 | fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7239 | | const pt = cg.pt; |
| 7240 | | const zcu = pt.zcu; |
| 7232 | const zcu = cg.zcu; |
| 7241 | 7233 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 7242 | 7234 | const extra = cg.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 7243 | 7235 | |
| ... | ... | @@ -7276,7 +7268,7 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7276 | 7268 | } |
| 7277 | 7269 | |
| 7278 | 7270 | fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue { |
| 7279 | | const zcu = cg.pt.zcu; |
| 7271 | const zcu = cg.zcu; |
| 7280 | 7272 | if (ptr_ty.isSlice(zcu)) { |
| 7281 | 7273 | return cg.slicePtr(ptr); |
| 7282 | 7274 | } else { |
| ... | ... | @@ -7285,7 +7277,7 @@ fn sliceOrArrayPtr(cg: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue { |
| 7285 | 7277 | } |
| 7286 | 7278 | |
| 7287 | 7279 | fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7288 | | const zcu = cg.pt.zcu; |
| 7280 | const zcu = cg.zcu; |
| 7289 | 7281 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 7290 | 7282 | const dst = try cg.resolveInst(bin_op.lhs); |
| 7291 | 7283 | const dst_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -7319,7 +7311,7 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7319 | 7311 | } |
| 7320 | 7312 | |
| 7321 | 7313 | fn airMemmove(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7322 | | const zcu = cg.pt.zcu; |
| 7314 | const zcu = cg.zcu; |
| 7323 | 7315 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 7324 | 7316 | const dst = try cg.resolveInst(bin_op.lhs); |
| 7325 | 7317 | const dst_ty = cg.typeOf(bin_op.lhs); |
| ... | ... | @@ -7370,9 +7362,9 @@ fn airErrorName(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7370 | 7362 | // |
| 7371 | 7363 | // As the names are global and the slice elements are constant, we do not have |
| 7372 | 7364 | // to make a copy of the ptr+value but can point towards them directly. |
| 7373 | | const pt = cg.pt; |
| 7365 | const zcu = cg.zcu; |
| 7374 | 7366 | const name_ty = Type.slice_const_u8_sentinel_0; |
| 7375 | | const abi_size = name_ty.abiSize(pt.zcu); |
| 7367 | const abi_size = name_ty.abiSize(zcu); |
| 7376 | 7368 | |
| 7377 | 7369 | // Lowers to a i32.const or i64.const with the error table memory address. |
| 7378 | 7370 | cg.error_name_table_ref_count += 1; |
| ... | ... | @@ -7433,7 +7425,7 @@ fn airTry(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7433 | 7425 | } |
| 7434 | 7426 | |
| 7435 | 7427 | fn airTryPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7436 | | const zcu = cg.pt.zcu; |
| 7428 | const zcu = cg.zcu; |
| 7437 | 7429 | const unwrapped_try = cg.air.unwrapTryPtr(inst); |
| 7438 | 7430 | const err_union_ptr = try cg.resolveInst(unwrapped_try.error_union_ptr); |
| 7439 | 7431 | const body = unwrapped_try.else_body; |
| ... | ... | @@ -7456,7 +7448,7 @@ fn lowerTry( |
| 7456 | 7448 | err_union_ty: Type, |
| 7457 | 7449 | operand_is_ptr: bool, |
| 7458 | 7450 | ) InnerError!WValue { |
| 7459 | | const zcu = cg.pt.zcu; |
| 7451 | const zcu = cg.zcu; |
| 7460 | 7452 | const branch_liveness = cg.liveness.getCondBr(inst); |
| 7461 | 7453 | |
| 7462 | 7454 | const pl_ty = err_union_ty.errorUnionPayload(zcu); |
| ... | ... | @@ -7516,7 +7508,7 @@ fn callIntrinsic( |
| 7516 | 7508 | args: []const WValue, |
| 7517 | 7509 | ) InnerError!WValue { |
| 7518 | 7510 | assert(param_types.len == args.len); |
| 7519 | | const zcu = cg.pt.zcu; |
| 7511 | const zcu = cg.zcu; |
| 7520 | 7512 | |
| 7521 | 7513 | // Always pass over C-ABI |
| 7522 | 7514 | |
| ... | ... | @@ -7574,7 +7566,7 @@ fn airIsNamedEnumValue(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7574 | 7566 | } |
| 7575 | 7567 | |
| 7576 | 7568 | fn airErrorSetHasValue(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7577 | | const zcu = cg.pt.zcu; |
| 7569 | const zcu = cg.zcu; |
| 7578 | 7570 | const ip = &zcu.intern_pool; |
| 7579 | 7571 | const ty_op = cg.air.instructions.items(.data)[@backingInt(inst)].ty_op; |
| 7580 | 7572 | |
| ... | ... | @@ -7661,7 +7653,7 @@ inline fn useAtomicFeature(cg: *const CodeGen) bool { |
| 7661 | 7653 | } |
| 7662 | 7654 | |
| 7663 | 7655 | fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7664 | | const zcu = cg.pt.zcu; |
| 7656 | const zcu = cg.zcu; |
| 7665 | 7657 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 7666 | 7658 | const extra = cg.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 7667 | 7659 | |
| ... | ... | @@ -7739,7 +7731,7 @@ fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7739 | 7731 | } |
| 7740 | 7732 | |
| 7741 | 7733 | fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7742 | | const zcu = cg.pt.zcu; |
| 7734 | const zcu = cg.zcu; |
| 7743 | 7735 | const atomic_load = cg.air.instructions.items(.data)[@backingInt(inst)].atomic_load; |
| 7744 | 7736 | const ptr = try cg.resolveInst(atomic_load.ptr); |
| 7745 | 7737 | const ty = cg.typeOfIndex(inst); |
| ... | ... | @@ -7765,7 +7757,7 @@ fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7765 | 7757 | } |
| 7766 | 7758 | |
| 7767 | 7759 | fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7768 | | const zcu = cg.pt.zcu; |
| 7760 | const zcu = cg.zcu; |
| 7769 | 7761 | const pl_op = cg.air.instructions.items(.data)[@backingInt(inst)].pl_op; |
| 7770 | 7762 | const extra = cg.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 7771 | 7763 | |
| ... | ... | @@ -7972,7 +7964,7 @@ fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7972 | 7964 | } |
| 7973 | 7965 | |
| 7974 | 7966 | fn airAtomicStore(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7975 | | const zcu = cg.pt.zcu; |
| 7967 | const zcu = cg.zcu; |
| 7976 | 7968 | const bin_op = cg.air.instructions.items(.data)[@backingInt(inst)].bin_op; |
| 7977 | 7969 | |
| 7978 | 7970 | const ptr = try cg.resolveInst(bin_op.lhs); |
| ... | ... | @@ -8008,7 +8000,7 @@ fn airFrameAddress(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 8008 | 8000 | |
| 8009 | 8001 | fn airRuntimeNavPtr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 8010 | 8002 | const ty_nav = cg.air.instructions.items(.data)[@backingInt(inst)].ty_nav; |
| 8011 | | const mod = cg.pt.zcu.navFileScope(cg.owner_nav).mod.?; |
| 8003 | const mod = cg.zcu.navFileScope(cg.owner_nav).mod.?; |
| 8012 | 8004 | if (mod.single_threaded) { |
| 8013 | 8005 | const result: WValue = .{ .nav_ref = .{ |
| 8014 | 8006 | .nav_index = ty_nav.nav, |
| ... | ... | @@ -8024,7 +8016,7 @@ fn airAsm(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 8024 | 8016 | const outputs = unwrapped_asm.outputs; |
| 8025 | 8017 | const inputs = unwrapped_asm.inputs; |
| 8026 | 8018 | |
| 8027 | | const zcu = cg.pt.zcu; |
| 8019 | const zcu = cg.zcu; |
| 8028 | 8020 | const output_ty = cg.typeOfIndex(inst); |
| 8029 | 8021 | |
| 8030 | 8022 | const result: WValue = if (output_ty.hasRuntimeBits(zcu)) |
| ... | ... | @@ -8091,11 +8083,11 @@ fn airAsm(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 8091 | 8083 | } |
| 8092 | 8084 | |
| 8093 | 8085 | fn typeOf(cg: *CodeGen, inst: Air.Inst.Ref) Type { |
| 8094 | | const zcu = cg.pt.zcu; |
| 8086 | const zcu = cg.zcu; |
| 8095 | 8087 | return cg.air.typeOf(inst, &zcu.intern_pool); |
| 8096 | 8088 | } |
| 8097 | 8089 | |
| 8098 | 8090 | fn typeOfIndex(cg: *CodeGen, inst: Air.Inst.Index) Type { |
| 8099 | | const zcu = cg.pt.zcu; |
| 8091 | const zcu = cg.zcu; |
| 8100 | 8092 | return cg.air.typeOfIndex(inst, &zcu.intern_pool); |
| 8101 | 8093 | } |