diff options
| author | Luuk de Gram <luuk@degram.dev> | 2022-03-05 20:17:29 +0100 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2022-03-06 19:38:50 +0100 |
| commit | 5a45fe2dba12e1440fabe0b4b594d69703640e17 (patch) | |
| tree | 39e0e284945be031e6583da771f32520148604e6 /src/arch/wasm/CodeGen.zig | |
| parent | 12e636c24e92dbe02508b89c1363c357ccef2192 (diff) | |
| download | zig-5a45fe2dba12e1440fabe0b4b594d69703640e17.tar.gz zig-5a45fe2dba12e1440fabe0b4b594d69703640e17.zip | |
wasm: Call `generateSymbol` for updateDecl
To unify the wasm backend with the other backends, we will now call `generateSymbol` to
lower a Decl into bytes. This means we also have to change some function signatures
to comply with the linker interface.
Since the general purpose generateSymbol is less featureful than wasm's, some tests are
temporarily disabled.
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index ca571370ad..4c6a9641eb 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1318,13 +1318,14 @@ pub const DeclGen = struct { if (decl.link.wasm.sym_index == 0) { try writer.writeIntLittle(u32, 0); } else { - try writer.writeIntLittle(u32, try self.bin_file.getDeclVAddr( - self.decl, // parent decl that owns the atom of the symbol - self.symbol_index, // source symbol index - decl, // target decl that contains the target symbol - @intCast(u32, self.code.items.len), // offset - @intCast(u32, offset), // addend - )); + try writer.writeIntLittle(u32, @intCast(u32, try self.bin_file.getDeclVAddr( + decl, + .{ + .parent_atom_index = self.symbol_index, + .offset = self.code.items.len, + .addend = @intCast(u32, offset), + }, + ))); } return Result{ .appended = {} }; } @@ -1809,8 +1810,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index) InnerError!WValue { if (func_val.castTag(.function)) |func| { break :blk func.data.owner_decl; - } else if (func_val.castTag(.extern_fn)) |ext_fn| { - break :blk ext_fn.data.owner_decl; + } else if (func_val.castTag(.extern_fn)) |extern_fn| { + const ext_decl = extern_fn.data.owner_decl; + var func_type = try genFunctype(self.gpa, ext_decl.ty, self.target); + defer func_type.deinit(self.gpa); + ext_decl.fn_link.wasm.type_index = try self.bin_file.putOrGetFuncType(func_type); + break :blk ext_decl; } else if (func_val.castTag(.decl_ref)) |decl_ref| { break :blk decl_ref.data; } |
