| ... | @@ -11,10 +11,8 @@ const log = std.log.scoped(.codegen); | ... | @@ -11,10 +11,8 @@ const log = std.log.scoped(.codegen); |
| 11 | | 11 | |
| 12 | const codegen = @import("../../codegen.zig"); | 12 | const codegen = @import("../../codegen.zig"); |
| 13 | const Zcu = @import("../../Zcu.zig"); | 13 | const Zcu = @import("../../Zcu.zig"); |
| 14 | /// Deprecated. | | |
| 15 | const Module = Zcu; | | |
| 16 | const InternPool = @import("../../InternPool.zig"); | 14 | const InternPool = @import("../../InternPool.zig"); |
| 17 | const Decl = Module.Decl; | 15 | const Decl = Zcu.Decl; |
| 18 | const Type = @import("../../type.zig").Type; | 16 | const Type = @import("../../type.zig").Type; |
| 19 | const Value = @import("../../Value.zig"); | 17 | const Value = @import("../../Value.zig"); |
| 20 | const Compilation = @import("../../Compilation.zig"); | 18 | const 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`. |
| 675 | arg_index: u32 = 0, | 673 | arg_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` |
| 677 | err_msg: *Module.ErrorMsg, | 675 | err_msg: *Zcu.ErrorMsg, |
| 678 | /// List of all locals' types generated throughout this declaration | 676 | /// 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. |
| 680 | locals: std.ArrayListUnmanaged(u8), | 678 | locals: std.ArrayListUnmanaged(u8), |
| ... | @@ -768,7 +766,7 @@ pub fn deinit(func: *CodeGen) void { | ... | @@ -768,7 +766,7 @@ pub fn deinit(func: *CodeGen) void { |
| 768 | fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError { | 766 | fn 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 | } |
| 774 | | 772 | |
| ... | @@ -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 | } |
| 993 | | 991 | |
| 994 | /// Using a given `Type`, returns the corresponding type | 992 | /// Using a given `Type`, returns the corresponding type |
| 995 | fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype { | 993 | fn 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 | } |
| 1033 | | 1031 | |
| 1034 | /// Using a given `Type`, returns the byte representation of its wasm value type | 1032 | /// Using a given `Type`, returns the byte representation of its wasm value type |
| 1035 | fn genValtype(ty: Type, mod: *Module) u8 { | 1033 | fn genValtype(ty: Type, mod: *Zcu) u8 { |
| 1036 | return wasm.valtype(typeToValtype(ty, mod)); | 1034 | return wasm.valtype(typeToValtype(ty, mod)); |
| 1037 | } | 1035 | } |
| 1038 | | 1036 | |
| 1039 | /// Using a given `Type`, returns the corresponding wasm value type | 1037 | /// Using a given `Type`, returns the corresponding wasm value type |
| 1040 | /// Differently from `genValtype` this also allows `void` to create a block | 1038 | /// Differently from `genValtype` this also allows `void` to create a block |
| 1041 | /// with no return type | 1039 | /// with no return type |
| 1042 | fn genBlockType(ty: Type, mod: *Module) u8 { | 1040 | fn 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( |
| 1204 | | 1202 | |
| 1205 | pub fn generate( | 1203 | pub 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 | } |
| 1407 | | 1405 | |
| 1408 | fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, mod: *Module) bool { | 1406 | fn 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 { |
| 1713 | | 1711 | |
| 1714 | /// For a given `Type`, will return true when the type will be passed | 1712 | /// For a given `Type`, will return true when the type will be passed |
| 1715 | /// by reference, rather than by value | 1713 | /// by reference, rather than by value |
| 1716 | fn isByRef(ty: Type, mod: *Module) bool { | 1714 | fn 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-simd | 1783 | /// 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 store | 1784 | /// 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. |
| 1788 | fn determineSimdStoreStrategy(ty: Type, mod: *Module) SimdStoreStrategy { | 1786 | fn 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 | } |
| 3449 | | 3447 | |
| 3450 | fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, mod: *Module) i32 { | 3448 | fn 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 | } |
| 3453 | | 3451 | |
| 3454 | fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 { | 3452 | fn 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; |