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);
1111
1212const codegen = @import("../../codegen.zig");
1313const Zcu = @import("../../Zcu.zig");
14/// Deprecated.
15const Module = Zcu;
1614const InternPool = @import("../../InternPool.zig");
17const Decl = Module.Decl;
15const Decl = Zcu.Decl;
1816const Type = @import("../../type.zig").Type;
1917const Value = @import("../../Value.zig");
2018const Compilation = @import("../../Compilation.zig");
......@@ -674,7 +672,7 @@ local_index: u32 = 0,
674672/// Used to track which argument is being referenced in `airArg`.
675673arg_index: u32 = 0,
676674/// If codegen fails, an error messages will be allocated and saved in `err_msg`
677err_msg: *Module.ErrorMsg,
675err_msg: *Zcu.ErrorMsg,
678676/// List of all locals' types generated throughout this declaration
679677/// used to emit locals count at start of 'code' section.
680678locals: std.ArrayListUnmanaged(u8),
......@@ -768,7 +766,7 @@ pub fn deinit(func: *CodeGen) void {
768766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
769767 const mod = func.bin_file.base.comp.module.?;
770768 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);
772770 return error.CodegenFail;
773771}
774772
......@@ -992,7 +990,7 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
992990}
993991
994992/// Using a given `Type`, returns the corresponding type
995fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
993fn typeToValtype(ty: Type, mod: *Zcu) wasm.Valtype {
996994 const target = mod.getTarget();
997995 const ip = &mod.intern_pool;
998996 return switch (ty.zigTypeTag(mod)) {
......@@ -1032,14 +1030,14 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
10321030}
10331031
10341032/// 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 {
10361034 return wasm.valtype(typeToValtype(ty, mod));
10371035}
10381036
10391037/// Using a given `Type`, returns the corresponding wasm value type
10401038/// Differently from `genValtype` this also allows `void` to create a block
10411039/// with no return type
1042fn genBlockType(ty: Type, mod: *Module) u8 {
1040fn genBlockType(ty: Type, mod: *Zcu) u8 {
10431041 return switch (ty.ip_index) {
10441042 .void_type, .noreturn_type => wasm.block_empty,
10451043 else => genValtype(ty, mod),
......@@ -1149,7 +1147,7 @@ fn genFunctype(
11491147 cc: std.builtin.CallingConvention,
11501148 params: []const InternPool.Index,
11511149 return_type: Type,
1152 mod: *Module,
1150 mod: *Zcu,
11531151) !wasm.Type {
11541152 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);
11551153 defer temp_params.deinit();
......@@ -1204,7 +1202,7 @@ fn genFunctype(
12041202
12051203pub fn generate(
12061204 bin_file: *link.File,
1207 src_loc: Module.SrcLoc,
1205 src_loc: Zcu.SrcLoc,
12081206 func_index: InternPool.Index,
12091207 air: Air,
12101208 liveness: Liveness,
......@@ -1405,7 +1403,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
14051403 return result;
14061404}
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 {
14091407 switch (cc) {
14101408 .Unspecified, .Inline => return isByRef(return_type, mod),
14111409 .C => {
......@@ -1713,7 +1711,7 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {
17131711
17141712/// For a given `Type`, will return true when the type will be passed
17151713/// by reference, rather than by value
1716fn isByRef(ty: Type, mod: *Module) bool {
1714fn isByRef(ty: Type, mod: *Zcu) bool {
17171715 const ip = &mod.intern_pool;
17181716 const target = mod.getTarget();
17191717 switch (ty.zigTypeTag(mod)) {
......@@ -1785,7 +1783,7 @@ const SimdStoreStrategy = enum {
17851783/// This means when a given type is 128 bits and either the simd128 or relaxed-simd
17861784/// features are enabled, the function will return `.direct`. This would allow to store
17871785/// it using a instruction, rather than an unrolled version.
1788fn determineSimdStoreStrategy(ty: Type, mod: *Module) SimdStoreStrategy {
1786fn determineSimdStoreStrategy(ty: Type, mod: *Zcu) SimdStoreStrategy {
17891787 std.debug.assert(ty.zigTypeTag(mod) == .Vector);
17901788 if (ty.bitSize(mod) != 128) return .unrolled;
17911789 const hasFeature = std.Target.wasm.featureSetHas;
......@@ -3436,7 +3434,7 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
34363434 assert(ptr.base_addr == .int);
34373435 return @intCast(ptr.byte_offset);
34383436 },
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).?)))),
34403438 else => unreachable,
34413439 },
34423440 }
......@@ -3447,11 +3445,11 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
34473445 };
34483446}
34493447
3450fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32 {
3448fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Zcu) i32 {
34513449 return intStorageAsI32(ip.indexToKey(int).int.storage, mod);
34523450}
34533451
3454fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
3452fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Zcu) i32 {
34553453 return switch (storage) {
34563454 .i64 => |x| @as(i32, @intCast(x)),
34573455 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
......@@ -7340,7 +7338,7 @@ fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73407338 var lowest: ?u32 = null;
73417339 var highest: ?u32 = null;
73427340 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]).?);
73447342 if (lowest) |*l| {
73457343 if (err_int < l.*) {
73467344 l.* = err_int;
src/arch/wasm/Emit.zig+2-4
......@@ -6,8 +6,6 @@ const std = @import("std");
66const Mir = @import("Mir.zig");
77const link = @import("../../link.zig");
88const Zcu = @import("../../Zcu.zig");
9/// Deprecated.
10const Module = Zcu;
119const InternPool = @import("../../InternPool.zig");
1210const codegen = @import("../../codegen.zig");
1311const leb128 = std.leb;
......@@ -18,7 +16,7 @@ mir: Mir,
1816bin_file: *link.File.Wasm,
1917/// Possible error message. When set, the value is allocated and
2018/// must be freed manually.
21error_msg: ?*Module.ErrorMsg = null,
19error_msg: ?*Zcu.ErrorMsg = null,
2220/// The binary representation that will be emit by this module.
2321code: *std.ArrayList(u8),
2422/// List of allocated locals.
......@@ -259,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
259257 const comp = emit.bin_file.base.comp;
260258 const zcu = comp.module.?;
261259 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);
263261 return error.EmitFail;
264262}
265263
src/arch/wasm/abi.zig+2-4
......@@ -10,8 +10,6 @@ const assert = std.debug.assert;
1010
1111const Type = @import("../../type.zig").Type;
1212const Zcu = @import("../../Zcu.zig");
13/// Deprecated.
14const Module = Zcu;
1513
1614/// Defines how to pass a type as part of a function signature,
1715/// both for parameters as well as return values.
......@@ -24,7 +22,7 @@ const direct: [2]Class = .{ .direct, .none };
2422/// Classifies a given Zig type to determine how they must be passed
2523/// or returned as value within a wasm function.
2624/// 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 {
2826 const ip = &mod.intern_pool;
2927 const target = mod.getTarget();
3028 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;
......@@ -102,7 +100,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
102100/// Returns the scalar type a given type can represent.
103101/// Asserts given type can be represented as scalar, such as
104102/// a struct with a single scalar field.
105pub fn scalarType(ty: Type, mod: *Module) Type {
103pub fn scalarType(ty: Type, mod: *Zcu) Type {
106104 const ip = &mod.intern_pool;
107105 switch (ty.zigTypeTag(mod)) {
108106 .Struct => {