aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-02-10 21:06:16 +0100
committerLuuk de Gram <luuk@degram.dev>2022-02-10 21:40:06 +0100
commit0e2fcab334083d3cbc786e891be6c97e9fd81595 (patch)
tree7a9042737d071235a7cb17fc68365982f7a835f6 /src/link
parente139c41fd8955f873615b2c2434d162585c0e44c (diff)
downloadzig-0e2fcab334083d3cbc786e891be6c97e9fd81595.tar.gz
zig-0e2fcab334083d3cbc786e891be6c97e9fd81595.zip
wasm: Implement 'field_ptr' constants
This implements the `field_ptr` value for pointers. As the value only provides us with the index, we must calculate the offset from the container type using said index. (i.e. the offset from a struct field at index 2). Besides this, small miscellaneous fixes/updates were done to get remaining behavior tests passing: - We start the function table index at 1, so unresolved function pointers don't can be null-checked properly. - Implement genTypedValue for floats up to f64. - Fix zero-sized arguments by only creating `args` for non-zero-sized types. - lowerConstant now works for all decl_ref's. - lowerConstant properly lowers optional pointers, so `null` pointers are lowered to `0`.
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Wasm.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index d62f3a4201..81d77d5b66 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -428,7 +428,7 @@ pub fn addTableFunction(self: *Wasm, symbol_index: u32) !void {
fn mapFunctionTable(self: *Wasm) void {
var it = self.function_table.valueIterator();
- var index: u32 = 0;
+ var index: u32 = 1;
while (it.next()) |value_ptr| : (index += 1) {
value_ptr.* = index;
}
@@ -821,7 +821,7 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
try leb.writeULEB128(writer, wasm.reftype(.funcref));
try emitLimits(writer, .{
- .min = @intCast(u32, self.function_table.count()),
+ .min = @intCast(u32, self.function_table.count()) + 1,
.max = null,
});
@@ -931,7 +931,7 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
var flags: u32 = 0x2; // Yes we have a table
try leb.writeULEB128(writer, flags);
try leb.writeULEB128(writer, @as(u32, 0)); // index of that table. TODO: Store synthetic symbols
- try emitInit(writer, .{ .i32_const = 0 });
+ try emitInit(writer, .{ .i32_const = 1 }); // We start at index 1, so unresolved function pointers are invalid
try leb.writeULEB128(writer, @as(u8, 0));
try leb.writeULEB128(writer, @intCast(u32, self.function_table.count()));
var symbol_it = self.function_table.keyIterator();