authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-06-28 00:13:11+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2024-07-02 15:02:59+02:00
log5a9495002fb8de2b70462c40dd27938c2fef6271
tree305026fdd3e60b5f736a889914afa5c9a2d19a0a
parent4b9d327f123df935adcde9dadcb8561f7a84ef95

stage2-wasm: Zcu renaming


3 files changed, 19 insertions(+), 25 deletions(-)

src/arch/wasm/CodeGen.zig+15-17
...@@ -11,10 +11,8 @@ const log = std.log.scoped(.codegen);...@@ -11,10 +11,8 @@ const log = std.log.scoped(.codegen);
1111
12const codegen = @import("../../codegen.zig");12const codegen = @import("../../codegen.zig");
13const Zcu = @import("../../Zcu.zig");13const Zcu = @import("../../Zcu.zig");
14/// Deprecated.
15const Module = Zcu;
16const InternPool = @import("../../InternPool.zig");14const InternPool = @import("../../InternPool.zig");
17const Decl = Module.Decl;15const Decl = Zcu.Decl;
18const Type = @import("../../type.zig").Type;16const Type = @import("../../type.zig").Type;
19const Value = @import("../../Value.zig");17const Value = @import("../../Value.zig");
20const Compilation = @import("../../Compilation.zig");18const Compilation = @import("../../Compilation.zig");
...@@ -674,7 +672,7 @@ local_index: u32 = 0,...@@ -674,7 +672,7 @@ local_index: u32 = 0,
674/// Used to track which argument is being referenced in `airArg`.672/// Used to track which argument is being referenced in `airArg`.
675arg_index: u32 = 0,673arg_index: u32 = 0,
676/// If codegen fails, an error messages will be allocated and saved in `err_msg`674/// If codegen fails, an error messages will be allocated and saved in `err_msg`
677err_msg: *Module.ErrorMsg,675err_msg: *Zcu.ErrorMsg,
678/// List of all locals' types generated throughout this declaration676/// List of all locals' types generated throughout this declaration
679/// used to emit locals count at start of 'code' section.677/// used to emit locals count at start of 'code' section.
680locals: std.ArrayListUnmanaged(u8),678locals: std.ArrayListUnmanaged(u8),
...@@ -768,7 +766,7 @@ pub fn deinit(func: *CodeGen) void {...@@ -768,7 +766,7 @@ pub fn deinit(func: *CodeGen) void {
768fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
769 const mod = func.bin_file.base.comp.module.?;767 const mod = func.bin_file.base.comp.module.?;
770 const src_loc = func.decl.navSrcLoc(mod).upgrade(mod);768 const src_loc = func.decl.navSrcLoc(mod).upgrade(mod);
771 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);769 func.err_msg = try Zcu.ErrorMsg.create(func.gpa, src_loc, fmt, args);
772 return error.CodegenFail;770 return error.CodegenFail;
773}771}
774772
...@@ -992,7 +990,7 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32...@@ -992,7 +990,7 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
992}990}
993991
994/// Using a given `Type`, returns the corresponding type992/// Using a given `Type`, returns the corresponding type
995fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {993fn typeToValtype(ty: Type, mod: *Zcu) wasm.Valtype {
996 const target = mod.getTarget();994 const target = mod.getTarget();
997 const ip = &mod.intern_pool;995 const ip = &mod.intern_pool;
998 return switch (ty.zigTypeTag(mod)) {996 return switch (ty.zigTypeTag(mod)) {
...@@ -1032,14 +1030,14 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {...@@ -1032,14 +1030,14 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
1032}1030}
10331031
1034/// Using a given `Type`, returns the byte representation of its wasm value type1032/// Using a given `Type`, returns the byte representation of its wasm value type
1035fn genValtype(ty: Type, mod: *Module) u8 {1033fn genValtype(ty: Type, mod: *Zcu) u8 {
1036 return wasm.valtype(typeToValtype(ty, mod));1034 return wasm.valtype(typeToValtype(ty, mod));
1037}1035}
10381036
1039/// Using a given `Type`, returns the corresponding wasm value type1037/// Using a given `Type`, returns the corresponding wasm value type
1040/// Differently from `genValtype` this also allows `void` to create a block1038/// Differently from `genValtype` this also allows `void` to create a block
1041/// with no return type1039/// with no return type
1042fn genBlockType(ty: Type, mod: *Module) u8 {1040fn genBlockType(ty: Type, mod: *Zcu) u8 {
1043 return switch (ty.ip_index) {1041 return switch (ty.ip_index) {
1044 .void_type, .noreturn_type => wasm.block_empty,1042 .void_type, .noreturn_type => wasm.block_empty,
1045 else => genValtype(ty, mod),1043 else => genValtype(ty, mod),
...@@ -1149,7 +1147,7 @@ fn genFunctype(...@@ -1149,7 +1147,7 @@ fn genFunctype(
1149 cc: std.builtin.CallingConvention,1147 cc: std.builtin.CallingConvention,
1150 params: []const InternPool.Index,1148 params: []const InternPool.Index,
1151 return_type: Type,1149 return_type: Type,
1152 mod: *Module,1150 mod: *Zcu,
1153) !wasm.Type {1151) !wasm.Type {
1154 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);1152 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);
1155 defer temp_params.deinit();1153 defer temp_params.deinit();
...@@ -1204,7 +1202,7 @@ fn genFunctype(...@@ -1204,7 +1202,7 @@ fn genFunctype(
12041202
1205pub fn generate(1203pub fn generate(
1206 bin_file: *link.File,1204 bin_file: *link.File,
1207 src_loc: Module.SrcLoc,1205 src_loc: Zcu.SrcLoc,
1208 func_index: InternPool.Index,1206 func_index: InternPool.Index,
1209 air: Air,1207 air: Air,
1210 liveness: Liveness,1208 liveness: Liveness,
...@@ -1405,7 +1403,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1405,7 +1403,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1405 return result;1403 return result;
1406}1404}
14071405
1408fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, mod: *Module) bool {1406fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, mod: *Zcu) bool {
1409 switch (cc) {1407 switch (cc) {
1410 .Unspecified, .Inline => return isByRef(return_type, mod),1408 .Unspecified, .Inline => return isByRef(return_type, mod),
1411 .C => {1409 .C => {
...@@ -1713,7 +1711,7 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {...@@ -1713,7 +1711,7 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {
17131711
1714/// For a given `Type`, will return true when the type will be passed1712/// For a given `Type`, will return true when the type will be passed
1715/// by reference, rather than by value1713/// by reference, rather than by value
1716fn isByRef(ty: Type, mod: *Module) bool {1714fn isByRef(ty: Type, mod: *Zcu) bool {
1717 const ip = &mod.intern_pool;1715 const ip = &mod.intern_pool;
1718 const target = mod.getTarget();1716 const target = mod.getTarget();
1719 switch (ty.zigTypeTag(mod)) {1717 switch (ty.zigTypeTag(mod)) {
...@@ -1785,7 +1783,7 @@ const SimdStoreStrategy = enum {...@@ -1785,7 +1783,7 @@ const SimdStoreStrategy = enum {
1785/// This means when a given type is 128 bits and either the simd128 or relaxed-simd1783/// This means when a given type is 128 bits and either the simd128 or relaxed-simd
1786/// features are enabled, the function will return `.direct`. This would allow to store1784/// features are enabled, the function will return `.direct`. This would allow to store
1787/// it using a instruction, rather than an unrolled version.1785/// it using a instruction, rather than an unrolled version.
1788fn determineSimdStoreStrategy(ty: Type, mod: *Module) SimdStoreStrategy {1786fn determineSimdStoreStrategy(ty: Type, mod: *Zcu) SimdStoreStrategy {
1789 std.debug.assert(ty.zigTypeTag(mod) == .Vector);1787 std.debug.assert(ty.zigTypeTag(mod) == .Vector);
1790 if (ty.bitSize(mod) != 128) return .unrolled;1788 if (ty.bitSize(mod) != 128) return .unrolled;
1791 const hasFeature = std.Target.wasm.featureSetHas;1789 const hasFeature = std.Target.wasm.featureSetHas;
...@@ -3436,7 +3434,7 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {...@@ -3436,7 +3434,7 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
3436 assert(ptr.base_addr == .int);3434 assert(ptr.base_addr == .int);
3437 return @intCast(ptr.byte_offset);3435 return @intCast(ptr.byte_offset);
3438 },3436 },
3439 .err => |err| @as(i32, @bitCast(@as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(err.name).?)))),3437 .err => |err| @as(i32, @bitCast(@as(Zcu.ErrorInt, @intCast(mod.global_error_set.getIndex(err.name).?)))),
3440 else => unreachable,3438 else => unreachable,
3441 },3439 },
3442 }3440 }
...@@ -3447,11 +3445,11 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {...@@ -3447,11 +3445,11 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
3447 };3445 };
3448}3446}
34493447
3450fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32 {3448fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Zcu) i32 {
3451 return intStorageAsI32(ip.indexToKey(int).int.storage, mod);3449 return intStorageAsI32(ip.indexToKey(int).int.storage, mod);
3452}3450}
34533451
3454fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {3452fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Zcu) i32 {
3455 return switch (storage) {3453 return switch (storage) {
3456 .i64 => |x| @as(i32, @intCast(x)),3454 .i64 => |x| @as(i32, @intCast(x)),
3457 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),3455 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
...@@ -7340,7 +7338,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7340,7 +7338,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7340 var lowest: ?u32 = null;7338 var lowest: ?u32 = null;
7341 var highest: ?u32 = null;7339 var highest: ?u32 = null;
7342 for (0..names.len) |name_index| {7340 for (0..names.len) |name_index| {
7343 const err_int: Module.ErrorInt = @intCast(mod.global_error_set.getIndex(names.get(ip)[name_index]).?);7341 const err_int: Zcu.ErrorInt = @intCast(mod.global_error_set.getIndex(names.get(ip)[name_index]).?);
7344 if (lowest) |*l| {7342 if (lowest) |*l| {
7345 if (err_int < l.*) {7343 if (err_int < l.*) {
7346 l.* = err_int;7344 l.* = err_int;
src/arch/wasm/Emit.zig+2-4
...@@ -6,8 +6,6 @@ const std = @import("std");...@@ -6,8 +6,6 @@ const std = @import("std");
6const Mir = @import("Mir.zig");6const Mir = @import("Mir.zig");
7const link = @import("../../link.zig");7const link = @import("../../link.zig");
8const Zcu = @import("../../Zcu.zig");8const Zcu = @import("../../Zcu.zig");
9/// Deprecated.
10const Module = Zcu;
11const InternPool = @import("../../InternPool.zig");9const InternPool = @import("../../InternPool.zig");
12const codegen = @import("../../codegen.zig");10const codegen = @import("../../codegen.zig");
13const leb128 = std.leb;11const leb128 = std.leb;
...@@ -18,7 +16,7 @@ mir: Mir,...@@ -18,7 +16,7 @@ mir: Mir,
18bin_file: *link.File.Wasm,16bin_file: *link.File.Wasm,
19/// Possible error message. When set, the value is allocated and17/// Possible error message. When set, the value is allocated and
20/// must be freed manually.18/// must be freed manually.
21error_msg: ?*Module.ErrorMsg = null,19error_msg: ?*Zcu.ErrorMsg = null,
22/// The binary representation that will be emit by this module.20/// The binary representation that will be emit by this module.
23code: *std.ArrayList(u8),21code: *std.ArrayList(u8),
24/// List of allocated locals.22/// List of allocated locals.
...@@ -259,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -259,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
259 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
260 const zcu = comp.module.?;258 const zcu = comp.module.?;
261 const gpa = comp.gpa;259 const gpa = comp.gpa;
262 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu).upgrade(zcu), format, args);260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu).upgrade(zcu), format, args);
263 return error.EmitFail;261 return error.EmitFail;
264}262}
265263
src/arch/wasm/abi.zig+2-4
...@@ -10,8 +10,6 @@ const assert = std.debug.assert;...@@ -10,8 +10,6 @@ const assert = std.debug.assert;
1010
11const Type = @import("../../type.zig").Type;11const Type = @import("../../type.zig").Type;
12const Zcu = @import("../../Zcu.zig");12const Zcu = @import("../../Zcu.zig");
13/// Deprecated.
14const Module = Zcu;
1513
16/// Defines how to pass a type as part of a function signature,14/// Defines how to pass a type as part of a function signature,
17/// both for parameters as well as return values.15/// both for parameters as well as return values.
...@@ -24,7 +22,7 @@ const direct: [2]Class = .{ .direct, .none };...@@ -24,7 +22,7 @@ const direct: [2]Class = .{ .direct, .none };
24/// Classifies a given Zig type to determine how they must be passed22/// Classifies a given Zig type to determine how they must be passed
25/// or returned as value within a wasm function.23/// or returned as value within a wasm function.
26/// When all elements result in `.none`, no value must be passed in or returned.24/// When all elements result in `.none`, no value must be passed in or returned.
27pub fn classifyType(ty: Type, mod: *Module) [2]Class {25pub fn classifyType(ty: Type, mod: *Zcu) [2]Class {
28 const ip = &mod.intern_pool;26 const ip = &mod.intern_pool;
29 const target = mod.getTarget();27 const target = mod.getTarget();
30 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;28 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;
...@@ -102,7 +100,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {...@@ -102,7 +100,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
102/// Returns the scalar type a given type can represent.100/// Returns the scalar type a given type can represent.
103/// Asserts given type can be represented as scalar, such as101/// Asserts given type can be represented as scalar, such as
104/// a struct with a single scalar field.102/// a struct with a single scalar field.
105pub fn scalarType(ty: Type, mod: *Module) Type {103pub fn scalarType(ty: Type, mod: *Zcu) Type {
106 const ip = &mod.intern_pool;104 const ip = &mod.intern_pool;
107 switch (ty.zigTypeTag(mod)) {105 switch (ty.zigTypeTag(mod)) {
108 .Struct => {106 .Struct => {