link: remove union types which are now internal to backends
This commit is contained in:
@@ -328,8 +328,6 @@ pub const ErrorInt = u32;
|
||||
pub const Export = struct {
|
||||
options: std.builtin.ExportOptions,
|
||||
src: LazySrcLoc,
|
||||
/// Represents the position of the export, if any, in the output file.
|
||||
link: link.File.Export,
|
||||
/// The Decl that performs the export. Note that this is *not* the Decl being exported.
|
||||
owner_decl: Decl.Index,
|
||||
/// The Decl containing the export statement. Inline function calls
|
||||
@@ -533,16 +531,8 @@ pub const Decl = struct {
|
||||
/// What kind of a declaration is this.
|
||||
kind: Kind,
|
||||
|
||||
/// Represents the position of the code in the output file.
|
||||
/// This is populated regardless of semantic analysis and code generation.
|
||||
link: link.File.LinkBlock,
|
||||
|
||||
/// Represents the function in the linked output file, if the `Decl` is a function.
|
||||
/// This is stored here and not in `Fn` because `Decl` survives across updates but
|
||||
/// `Fn` does not.
|
||||
/// TODO Look into making `Fn` a longer lived structure and moving this field there
|
||||
/// to save on memory usage.
|
||||
fn_link: link.File.LinkFn,
|
||||
/// TODO remove this once Wasm backend catches up
|
||||
fn_link: ?link.File.Wasm.FnData = null,
|
||||
|
||||
/// The shallow set of other decls whose typed_value could possibly change if this Decl's
|
||||
/// typed_value is modified.
|
||||
@@ -5258,27 +5248,9 @@ pub fn clearDecl(
|
||||
if (decl.ty.isFnOrHasRuntimeBits()) {
|
||||
mod.comp.bin_file.freeDecl(decl_index);
|
||||
|
||||
// TODO instead of a union, put this memory trailing Decl objects,
|
||||
// and allow it to be variably sized.
|
||||
decl.link = switch (mod.comp.bin_file.tag) {
|
||||
.coff => .{ .coff = {} },
|
||||
.elf => .{ .elf = {} },
|
||||
.macho => .{ .macho = {} },
|
||||
.plan9 => .{ .plan9 = {} },
|
||||
.c => .{ .c = {} },
|
||||
.wasm => .{ .wasm = {} },
|
||||
.spirv => .{ .spirv = {} },
|
||||
.nvptx => .{ .nvptx = {} },
|
||||
};
|
||||
decl.fn_link = switch (mod.comp.bin_file.tag) {
|
||||
.coff => .{ .coff = {} },
|
||||
.elf => .{ .elf = {} },
|
||||
.macho => .{ .macho = {} },
|
||||
.plan9 => .{ .plan9 = {} },
|
||||
.c => .{ .c = {} },
|
||||
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
|
||||
.spirv => .{ .spirv = {} },
|
||||
.nvptx => .{ .nvptx = {} },
|
||||
.wasm => link.File.Wasm.FnData.empty,
|
||||
else => null,
|
||||
};
|
||||
}
|
||||
if (decl.getInnerNamespace()) |namespace| {
|
||||
@@ -5680,25 +5652,9 @@ pub fn allocateNewDecl(
|
||||
.deletion_flag = false,
|
||||
.zir_decl_index = 0,
|
||||
.src_scope = src_scope,
|
||||
.link = switch (mod.comp.bin_file.tag) {
|
||||
.coff => .{ .coff = {} },
|
||||
.elf => .{ .elf = {} },
|
||||
.macho => .{ .macho = {} },
|
||||
.plan9 => .{ .plan9 = {} },
|
||||
.c => .{ .c = {} },
|
||||
.wasm => .{ .wasm = {} },
|
||||
.spirv => .{ .spirv = {} },
|
||||
.nvptx => .{ .nvptx = {} },
|
||||
},
|
||||
.fn_link = switch (mod.comp.bin_file.tag) {
|
||||
.coff => .{ .coff = {} },
|
||||
.elf => .{ .elf = {} },
|
||||
.macho => .{ .macho = {} },
|
||||
.plan9 => .{ .plan9 = {} },
|
||||
.c => .{ .c = {} },
|
||||
.wasm => .{ .wasm = link.File.Wasm.FnData.empty },
|
||||
.spirv => .{ .spirv = {} },
|
||||
.nvptx => .{ .nvptx = {} },
|
||||
.wasm => link.File.Wasm.FnData.empty,
|
||||
else => null,
|
||||
},
|
||||
.generation = 0,
|
||||
.is_pub = false,
|
||||
|
||||
10
src/Sema.zig
10
src/Sema.zig
@@ -5564,16 +5564,6 @@ pub fn analyzeExport(
|
||||
.visibility = borrowed_options.visibility,
|
||||
},
|
||||
.src = src,
|
||||
.link = switch (mod.comp.bin_file.tag) {
|
||||
.coff => .{ .coff = {} },
|
||||
.elf => .{ .elf = {} },
|
||||
.macho => .{ .macho = {} },
|
||||
.plan9 => .{ .plan9 = {} },
|
||||
.c => .{ .c = {} },
|
||||
.wasm => .{ .wasm = {} },
|
||||
.spirv => .{ .spirv = {} },
|
||||
.nvptx => .{ .nvptx = {} },
|
||||
},
|
||||
.owner_decl = sema.owner_decl_index,
|
||||
.src_decl = block.src_decl,
|
||||
.exported_decl = exported_decl_index,
|
||||
|
||||
@@ -1194,7 +1194,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
|
||||
const fn_info = func.decl.ty.fnInfo();
|
||||
var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types, fn_info.return_type, func.target);
|
||||
defer func_type.deinit(func.gpa);
|
||||
func.decl.fn_link.wasm.type_index = try func.bin_file.putOrGetFuncType(func_type);
|
||||
func.decl.fn_link.?.type_index = try func.bin_file.putOrGetFuncType(func_type);
|
||||
|
||||
var cc_result = try func.resolveCallingConventionValues(func.decl.ty);
|
||||
defer cc_result.deinit(func.gpa);
|
||||
@@ -2129,12 +2129,12 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
|
||||
defer func_type.deinit(func.gpa);
|
||||
const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_fn.data.owner_decl);
|
||||
const atom = func.bin_file.getAtomPtr(atom_index);
|
||||
ext_decl.fn_link.wasm.type_index = try func.bin_file.putOrGetFuncType(func_type);
|
||||
ext_decl.fn_link.?.type_index = try func.bin_file.putOrGetFuncType(func_type);
|
||||
try func.bin_file.addOrUpdateImport(
|
||||
mem.sliceTo(ext_decl.name, 0),
|
||||
atom.getSymbolIndex().?,
|
||||
ext_decl.getExternFn().?.lib_name,
|
||||
ext_decl.fn_link.wasm.type_index,
|
||||
ext_decl.fn_link.?.type_index,
|
||||
);
|
||||
break :blk extern_fn.data.owner_decl;
|
||||
} else if (func_val.castTag(.decl_ref)) |decl_ref| {
|
||||
|
||||
33
src/link.zig
33
src/link.zig
@@ -261,39 +261,6 @@ pub const File = struct {
|
||||
/// of this linking operation.
|
||||
lock: ?Cache.Lock = null,
|
||||
|
||||
pub const LinkBlock = union {
|
||||
elf: void,
|
||||
coff: void,
|
||||
macho: void,
|
||||
plan9: void,
|
||||
c: void,
|
||||
wasm: void,
|
||||
spirv: void,
|
||||
nvptx: void,
|
||||
};
|
||||
|
||||
pub const LinkFn = union {
|
||||
elf: void,
|
||||
coff: void,
|
||||
macho: void,
|
||||
plan9: void,
|
||||
c: void,
|
||||
wasm: Wasm.FnData,
|
||||
spirv: void,
|
||||
nvptx: void,
|
||||
};
|
||||
|
||||
pub const Export = union {
|
||||
elf: void,
|
||||
coff: void,
|
||||
macho: void,
|
||||
plan9: void,
|
||||
c: void,
|
||||
wasm: void,
|
||||
spirv: void,
|
||||
nvptx: void,
|
||||
};
|
||||
|
||||
/// Attempts incremental linking, if the file already exists. If
|
||||
/// incremental linking fails, falls back to truncating the file and
|
||||
/// rewriting it. A malicious file is detected as incremental link failure
|
||||
|
||||
@@ -2829,7 +2829,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
|
||||
if (decl.isExtern()) continue;
|
||||
const atom_index = entry.value_ptr.*;
|
||||
if (decl.ty.zigTypeTag() == .Fn) {
|
||||
try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.wasm });
|
||||
try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.? });
|
||||
} else if (decl.getVariable()) |variable| {
|
||||
if (!variable.is_mutable) {
|
||||
try wasm.parseAtom(atom_index, .{ .data = .read_only });
|
||||
|
||||
Reference in New Issue
Block a user