authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-07-04 17:40:28+02:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-07-18 00:57:18+02:00
log6eb76f930defb86d09469f73196b374c90f7f8a5
tree8f57a4e96c1df196f5851edf11574d8668594af0
parent9356cb1475606a7afd2e722af60f87ce2b39f9f8

stage2-wasm: typeToValtype focus on .auto callconv

This is required for toLocal() correctly handling isByRef values, previous behavior was a hack.

1 files changed, 26 insertions(+), 26 deletions(-)

src/arch/wasm/CodeGen.zig+26-26
......@@ -990,44 +990,44 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
990990 return result;
991991}
992992
993/// Using a given `Type`, returns the corresponding type
993/// Using a given `Type`, returns the corresponding valtype for .auto callconv
994994fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype {
995995 const mod = pt.zcu;
996996 const target = mod.getTarget();
997997 const ip = &mod.intern_pool;
998998 return switch (ty.zigTypeTag(mod)) {
999999 .Float => switch (ty.floatBits(target)) {
1000 16 => wasm.Valtype.i32, // stored/loaded as u16
1001 32 => wasm.Valtype.f32,
1002 64 => wasm.Valtype.f64,
1003 80, 128 => wasm.Valtype.i64,
1000 16 => .i32, // stored/loaded as u16
1001 32 => .f32,
1002 64 => .f64,
1003 80, 128 => .i32,
10041004 else => unreachable,
10051005 },
1006 .Int, .Enum => blk: {
1007 const info = ty.intInfo(pt.zcu);
1008 if (info.bits <= 32) break :blk wasm.Valtype.i32;
1009 if (info.bits > 32 and info.bits <= 128) break :blk wasm.Valtype.i64;
1010 break :blk wasm.Valtype.i32; // represented as pointer to stack
1006 .Int, .Enum => switch (ty.intInfo(pt.zcu).bits) {
1007 0...32 => .i32,
1008 33...64 => .i64,
1009 else => .i32,
10111010 },
1012 .Struct => {
1011 .Struct => blk: {
10131012 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {
1014 return typeToValtype(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
1013 const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
1014 break :blk typeToValtype(backing_int_ty, pt);
10151015 } else {
1016 return wasm.Valtype.i32;
1016 break :blk .i32;
10171017 }
10181018 },
10191019 .Vector => switch (determineSimdStoreStrategy(ty, pt)) {
1020 .direct => wasm.Valtype.v128,
1021 .unrolled => wasm.Valtype.i32,
1020 .direct => .v128,
1021 .unrolled => .i32,
10221022 },
10231023 .Union => switch (ty.containerLayout(pt.zcu)) {
1024 .@"packed" => {
1024 .@"packed" => blk: {
10251025 const int_ty = pt.intType(.unsigned, @as(u16, @intCast(ty.bitSize(pt)))) catch @panic("out of memory");
1026 return typeToValtype(int_ty, pt);
1026 break :blk typeToValtype(int_ty, pt);
10271027 },
1028 else => wasm.Valtype.i32,
1028 else => .i32,
10291029 },
1030 else => wasm.Valtype.i32, // all represented as reference/immediate
1030 else => .i32, // all represented as reference/immediate
10311031 };
10321032}
10331033
......@@ -1180,20 +1180,20 @@ fn genFunctype(
11801180 switch (cc) {
11811181 .C => {
11821182 const param_classes = abi.classifyType(param_type, pt);
1183 for (param_classes) |class| {
1184 if (class == .none) continue;
1185 if (class == .direct) {
1183 if (param_classes[1] == .none) {
1184 if (param_classes[0] == .direct) {
11861185 const scalar_type = abi.scalarType(param_type, pt);
11871186 try temp_params.append(typeToValtype(scalar_type, pt));
11881187 } else {
11891188 try temp_params.append(typeToValtype(param_type, pt));
11901189 }
1190 } else {
1191 // i128/f128
1192 try temp_params.append(.i64);
1193 try temp_params.append(.i64);
11911194 }
11921195 },
1193 else => if (isByRef(param_type, pt))
1194 try temp_params.append(.i32)
1195 else
1196 try temp_params.append(typeToValtype(param_type, pt)),
1196 else => try temp_params.append(typeToValtype(param_type, pt)),
11971197 }
11981198 }
11991199