diff options
| author | Luuk de Gram <Luukdegram@users.noreply.github.com> | 2021-01-26 19:47:15 +0100 |
|---|---|---|
| committer | Luuk de Gram <Luukdegram@users.noreply.github.com> | 2021-01-26 19:47:15 +0100 |
| commit | cc46c1b9024beefdd82ce8abd07e8849a72db20c (patch) | |
| tree | 5771573eccca912cd46fa1fb090cf57b71913989 /src/link | |
| parent | a0d81caec99fe0d1cd803b0ba461b6e02829b476 (diff) | |
| download | zig-cc46c1b9024beefdd82ce8abd07e8849a72db20c.tar.gz zig-cc46c1b9024beefdd82ce8abd07e8849a72db20c.zip | |
Add tests, fix locals that are created in blocks like loops, and handle all breaks correctly
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Wasm.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 1001e616e2..c39e995966 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -122,6 +122,13 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void { else => |e| return err, }; + // as locals are patched afterwards, the offsets of funcidx's are off, + // here we update them to correct them + for (decl.fn_link.wasm.?.idx_refs.items) |*func| { + // For each local, add 6 bytes (count + type) + func.offset += @intCast(u32, context.locals.items.len * 6); + } + fn_data.functype = context.func_type_data.toUnmanaged(); fn_data.code = context.code.toUnmanaged(); } @@ -238,7 +245,7 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void { try writer.writeAll(fn_data.code.items[current..idx_ref.offset]); current = idx_ref.offset; // Use a fixed width here to make calculating the code size - // in codegen.wasm.genCode() simpler. + // in codegen.wasm.gen() simpler. var buf: [5]u8 = undefined; leb.writeUnsignedFixed(5, &buf, self.getFuncidx(idx_ref.decl).?); try writer.writeAll(&buf); |
