diff options
| author | Techatrix <19954306+Techatrix@users.noreply.github.com> | 2023-11-25 04:30:48 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-25 04:09:53 -0500 |
| commit | 18608223ef5e588598d21dfe71678dbc62f320e4 (patch) | |
| tree | 407e0a98f6786f55c998fa42b402d55292db293e /src/link | |
| parent | e834e95d718fe3eacaec54034462c90fd10bfe76 (diff) | |
| download | zig-18608223ef5e588598d21dfe71678dbc62f320e4.tar.gz zig-18608223ef5e588598d21dfe71678dbc62f320e4.zip | |
convert `toType` and `toValue` to `Type.fromInterned` and `Value.fromInterned`
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/C.zig | 5 | ||||
| -rw-r--r-- | src/link/Coff.zig | 7 | ||||
| -rw-r--r-- | src/link/Dwarf.zig | 18 | ||||
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 10 | ||||
| -rw-r--r-- | src/link/MachO.zig | 8 | ||||
| -rw-r--r-- | src/link/Plan9.zig | 8 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 13 |
7 files changed, 38 insertions, 31 deletions
diff --git a/src/link/C.zig b/src/link/C.zig index f97f19f85b..3632029418 100644 --- a/src/link/C.zig +++ b/src/link/C.zig @@ -13,6 +13,7 @@ const codegen = @import("../codegen/c.zig"); const link = @import("../link.zig"); const trace = @import("../tracy.zig").trace; const Type = @import("../type.zig").Type; +const Value = @import("../value.zig").Value; const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); @@ -254,8 +255,8 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void { } const tv: @import("../TypedValue.zig") = .{ - .ty = module.intern_pool.typeOf(anon_decl).toType(), - .val = anon_decl.toValue(), + .ty = Type.fromInterned(module.intern_pool.typeOf(anon_decl)), + .val = Value.fromInterned(anon_decl), }; const c_value: codegen.CValue = .{ .constant = anon_decl }; const alignment: Alignment = self.aligned_anon_decls.get(anon_decl) orelse .none; diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 16736ab1af..fc60fc6b48 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1189,7 +1189,7 @@ pub fn updateDecl( var code_buffer = std.ArrayList(u8).init(self.base.allocator); defer code_buffer.deinit(); - const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val; + const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ .ty = decl.ty, .val = decl_val, @@ -1794,7 +1794,7 @@ pub fn lowerAnonDecl( ) !codegen.Result { const gpa = self.base.allocator; const mod = self.base.options.module.?; - const ty = mod.intern_pool.typeOf(decl_val).toType(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); const decl_alignment = switch (explicit_alignment) { .none => ty.abiAlignment(mod), else => explicit_alignment, @@ -1805,7 +1805,7 @@ pub fn lowerAnonDecl( return .ok; } - const val = decl_val.toValue(); + const val = Value.fromInterned(decl_val); const tv = TypedValue{ .ty = ty, .val = val }; var name_buf: [32]u8 = undefined; const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ @@ -2669,6 +2669,7 @@ const Relocation = @import("Coff/Relocation.zig"); const TableSection = @import("table_section.zig").TableSection; const StringTable = @import("StringTable.zig"); const Type = @import("../type.zig").Type; +const Value = @import("../value.zig").Value; const TypedValue = @import("../TypedValue.zig"); pub const base_tag: link.File.Tag = .coff; diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 8c889fa30d..f9fe41c029 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -305,7 +305,7 @@ pub const DeclState = struct { // DW.AT.type, DW.FORM.ref4 const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); - try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); + try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata const field_off = ty.structFieldOffset(field_index, mod); try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); @@ -323,7 +323,7 @@ pub const DeclState = struct { if (struct_type.isTuple(ip)) { for (struct_type.field_types.get(ip), struct_type.offsets.get(ip), 0..) |field_ty, field_off, field_index| { - if (!field_ty.toType().hasRuntimeBits(mod)) continue; + if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; // DW.AT.member try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member)); // DW.AT.name, DW.FORM.string @@ -331,7 +331,7 @@ pub const DeclState = struct { // DW.AT.type, DW.FORM.ref4 const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); - try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); + try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); } @@ -341,7 +341,7 @@ pub const DeclState = struct { struct_type.field_types.get(ip), struct_type.offsets.get(ip), ) |field_name_ip, field_ty, field_off| { - if (!field_ty.toType().hasRuntimeBits(mod)) continue; + if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; const field_name = ip.stringToSlice(field_name_ip); // DW.AT.member try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2); @@ -352,7 +352,7 @@ pub const DeclState = struct { // DW.AT.type, DW.FORM.ref4 const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); - try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); + try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); } @@ -389,7 +389,7 @@ pub const DeclState = struct { const value = enum_type.values.get(ip)[field_i]; // TODO do not assume a 64bit enum value - could be bigger. // See https://github.com/ziglang/zig/issues/645 - const field_int_val = try value.toValue().intFromEnum(ty, mod); + const field_int_val = try Value.fromInterned(value).intFromEnum(ty, mod); break :value @bitCast(field_int_val.toSignedInt(mod)); }; mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian); @@ -443,7 +443,7 @@ pub const DeclState = struct { } for (union_obj.field_types.get(ip), union_obj.field_names.get(ip)) |field_ty, field_name| { - if (!field_ty.toType().hasRuntimeBits(mod)) continue; + if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; // DW.AT.member try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member)); // DW.AT.name, DW.FORM.string @@ -452,7 +452,7 @@ pub const DeclState = struct { // DW.AT.type, DW.FORM.ref4 const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); - try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); + try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata try dbg_info_buffer.append(0); } @@ -469,7 +469,7 @@ pub const DeclState = struct { // DW.AT.type, DW.FORM.ref4 const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); - try self.addTypeRelocGlobal(atom_index, union_obj.enum_tag_ty.toType(), @intCast(index)); + try self.addTypeRelocGlobal(atom_index, Type.fromInterned(union_obj.enum_tag_ty), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset); diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 7f2a5efee8..ae546c5d62 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -660,7 +660,7 @@ pub fn lowerAnonDecl( ) !codegen.Result { const gpa = elf_file.base.allocator; const mod = elf_file.base.options.module.?; - const ty = mod.intern_pool.typeOf(decl_val).toType(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); const decl_alignment = switch (explicit_alignment) { .none => ty.abiAlignment(mod), else => explicit_alignment, @@ -671,7 +671,7 @@ pub fn lowerAnonDecl( return .ok; } - const val = decl_val.toValue(); + const val = Value.fromInterned(decl_val); const tv = TypedValue{ .ty = ty, .val = val }; var name_buf: [32]u8 = undefined; const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ @@ -835,7 +835,7 @@ fn getDeclShdrIndex( }); } if (variable.is_const) break :blk elf_file.zig_data_rel_ro_section_index.?; - if (variable.init.toValue().isUndefDeep(mod)) { + if (Value.fromInterned(variable.init).isUndefDeep(mod)) { const mode = elf_file.base.options.optimize_mode; if (mode == .Debug or mode == .ReleaseSafe) break :blk elf_file.zig_data_section_index.?; break :blk elf_file.zig_bss_section_index.?; @@ -1114,7 +1114,7 @@ pub fn updateDecl( defer if (decl_state) |*ds| ds.deinit(); // TODO implement .debug_info for global variables - const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val; + const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = if (decl_state) |*ds| try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{ .ty = decl.ty, @@ -1613,5 +1613,7 @@ const Module = @import("../../Module.zig"); const Object = @import("Object.zig"); const Symbol = @import("Symbol.zig"); const StringTable = @import("../StringTable.zig"); +const Type = @import("../../type.zig").Type; +const Value = @import("../../value.zig").Value; const TypedValue = @import("../../TypedValue.zig"); const ZigObject = @This(); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 67c9aaac05..9d30c374dc 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -2400,7 +2400,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo null; defer if (decl_state) |*ds| ds.deinit(); - const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val; + const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = if (decl_state) |*ds| try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ .ty = decl.ty, @@ -2569,7 +2569,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D const decl = module.declPtr(decl_index); const decl_metadata = self.decls.get(decl_index).?; - const decl_val = decl.val.getVariable(mod).?.init.toValue(); + const decl_val = Value.fromInterned(decl.val.getVariable(mod).?.init); const res = if (decl_state) |*ds| try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ .ty = decl.ty, @@ -2995,7 +2995,7 @@ pub fn lowerAnonDecl( ) !codegen.Result { const gpa = self.base.allocator; const mod = self.base.options.module.?; - const ty = mod.intern_pool.typeOf(decl_val).toType(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); const decl_alignment = switch (explicit_alignment) { .none => ty.abiAlignment(mod), else => explicit_alignment, @@ -3006,7 +3006,7 @@ pub fn lowerAnonDecl( return .ok; } - const val = decl_val.toValue(); + const val = Value.fromInterned(decl_val); const tv = TypedValue{ .ty = ty, .val = val }; var name_buf: [32]u8 = undefined; const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index 4221aa7dee..0d29cae6dc 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -13,6 +13,8 @@ const File = link.File; const build_options = @import("build_options"); const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); +const Type = @import("../type.zig").Type; +const Value = @import("../value.zig").Value; const TypedValue = @import("../TypedValue.zig"); const std = @import("std"); @@ -517,7 +519,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo var code_buffer = std.ArrayList(u8).init(self.base.allocator); defer code_buffer.deinit(); - const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val; + const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; // TODO we need the symbol index for symbol in the table of locals for the containing atom const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ .ty = decl.ty, @@ -1492,8 +1494,8 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S const gop = try self.anon_decls.getOrPut(gpa, decl_val); const mod = self.base.options.module.?; if (!gop.found_existing) { - const ty = mod.intern_pool.typeOf(decl_val).toType(); - const val = decl_val.toValue(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); + const val = Value.fromInterned(decl_val); const tv = TypedValue{ .ty = ty, .val = val }; const name = try std.fmt.allocPrint(gpa, "__anon_{d}", .{@intFromEnum(decl_val)}); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index da8753ac29..8b1039497c 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -23,6 +23,7 @@ const build_options = @import("build_options"); const wasi_libc = @import("../wasi_libc.zig"); const Cache = std.Build.Cache; const Type = @import("../type.zig").Type; +const Value = @import("../value.zig").Value; const TypedValue = @import("../TypedValue.zig"); const LlvmObject = @import("../codegen/llvm.zig").Object; const Air = @import("../Air.zig"); @@ -1452,7 +1453,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); return wasm.addOrUpdateImport(name, atom.sym_index, lib_name, null); } - const val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val; + const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; var code_writer = std.ArrayList(u8).init(wasm.base.allocator); defer code_writer.deinit(); @@ -1719,8 +1720,8 @@ pub fn lowerAnonDecl( const gop = try wasm.anon_decls.getOrPut(wasm.base.allocator, decl_val); if (!gop.found_existing) { const mod = wasm.base.options.module.?; - const ty = mod.intern_pool.typeOf(decl_val).toType(); - const tv: TypedValue = .{ .ty = ty, .val = decl_val.toValue() }; + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); + const tv: TypedValue = .{ .ty = ty, .val = Value.fromInterned(decl_val) }; var name_buf: [32]u8 = undefined; const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ @intFromEnum(decl_val), @@ -1751,7 +1752,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin const parent_atom = wasm.getAtomPtr(parent_atom_index); const is_wasm32 = wasm.base.options.target.cpu.arch == .wasm32; const mod = wasm.base.options.module.?; - const ty = mod.intern_pool.typeOf(decl_val).toType(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); if (ty.zigTypeTag(mod) == .Fn) { assert(reloc_info.addend == 0); // addend not allowed for function relocations // We found a function pointer, so add it to our table, @@ -3533,7 +3534,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod } else if (decl.getOwnedVariable(mod)) |variable| { if (variable.is_const) { try wasm.parseAtom(atom_index, .{ .data = .read_only }); - } else if (variable.init.toValue().isUndefDeep(mod)) { + } else if (Value.fromInterned(variable.init).isUndefDeep(mod)) { // for safe build modes, we store the atom in the data segment, // whereas for unsafe build modes we store it in bss. const is_initialized = wasm.base.options.optimize_mode == .Debug or @@ -3558,7 +3559,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod } // parse anonymous declarations for (wasm.anon_decls.keys(), wasm.anon_decls.values()) |decl_val, atom_index| { - const ty = mod.intern_pool.typeOf(decl_val).toType(); + const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); if (ty.zigTypeTag(mod) == .Fn) { try wasm.parseAtom(atom_index, .function); } else { |
