aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-02-01 18:55:35 +0100
committerLuuk de Gram <luuk@degram.dev>2023-02-01 19:10:56 +0100
commit46f54b23ae604c3f99f51ca719d9085530f6b59c (patch)
tree66547a2f4b33e876afb0b29ea6799795959699fb /src/arch/wasm/CodeGen.zig
parent1aa0f8aa2f382fb56639ea6833a62c4b8b031247 (diff)
downloadzig-46f54b23ae604c3f99f51ca719d9085530f6b59c.tar.gz
zig-46f54b23ae604c3f99f51ca719d9085530f6b59c.zip
link: make Wasm atoms fully owned by the linker
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index 8212d281e5..8559a728e5 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -1269,10 +1269,10 @@ fn genFunc(func: *CodeGen) InnerError!void {
var emit: Emit = .{
.mir = mir,
- .bin_file = &func.bin_file.base,
+ .bin_file = func.bin_file,
.code = func.code,
.locals = func.locals.items,
- .decl = func.decl,
+ .decl_index = func.decl_index,
.dbg_output = func.debug_output,
.prev_di_line = 0,
.prev_di_column = 0,
@@ -2115,21 +2115,20 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
const fn_info = fn_ty.fnInfo();
const first_param_sret = firstParamSRet(fn_info.cc, fn_info.return_type, func.target);
- const callee: ?*Decl = blk: {
+ const callee: ?Decl.Index = blk: {
const func_val = func.air.value(pl_op.operand) orelse break :blk null;
const module = func.bin_file.base.options.module.?;
if (func_val.castTag(.function)) |function| {
- const decl = module.declPtr(function.data.owner_decl);
- try decl.link.wasm.ensureInitialized(func.bin_file);
- break :blk decl;
+ _ = try func.bin_file.getOrCreateAtomForDecl(function.data.owner_decl);
+ break :blk function.data.owner_decl;
} else if (func_val.castTag(.extern_fn)) |extern_fn| {
const ext_decl = module.declPtr(extern_fn.data.owner_decl);
const ext_info = ext_decl.ty.fnInfo();
var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types, ext_info.return_type, func.target);
defer func_type.deinit(func.gpa);
- const atom = &ext_decl.link.wasm;
- try atom.ensureInitialized(func.bin_file);
+ 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);
try func.bin_file.addOrUpdateImport(
mem.sliceTo(ext_decl.name, 0),
@@ -2137,11 +2136,10 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
ext_decl.getExternFn().?.lib_name,
ext_decl.fn_link.wasm.type_index,
);
- break :blk ext_decl;
+ break :blk extern_fn.data.owner_decl;
} else if (func_val.castTag(.decl_ref)) |decl_ref| {
- const decl = module.declPtr(decl_ref.data);
- try decl.link.wasm.ensureInitialized(func.bin_file);
- break :blk decl;
+ _ = try func.bin_file.getOrCreateAtomForDecl(decl_ref.data);
+ break :blk decl_ref.data;
}
return func.fail("Expected a function, but instead found type '{}'", .{func_val.tag()});
};
@@ -2162,7 +2160,8 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
}
if (callee) |direct| {
- try func.addLabel(.call, direct.link.wasm.sym_index);
+ const atom_index = func.bin_file.decls.get(direct).?;
+ try func.addLabel(.call, func.bin_file.getAtom(atom_index).sym_index);
} else {
// in this case we call a function pointer
// so load its value onto the stack
@@ -2758,9 +2757,10 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Ind
}
module.markDeclAlive(decl);
- try decl.link.wasm.ensureInitialized(func.bin_file);
+ const atom_index = try func.bin_file.getOrCreateAtomForDecl(decl_index);
+ const atom = func.bin_file.getAtom(atom_index);
- const target_sym_index = decl.link.wasm.sym_index;
+ const target_sym_index = atom.sym_index;
if (decl.ty.zigTypeTag() == .Fn) {
try func.bin_file.addTableFunction(target_sym_index);
return WValue{ .function_index = target_sym_index };