diff options
| author | Luuk de Gram <luuk@degram.dev> | 2021-12-29 22:28:18 +0100 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2022-01-01 12:59:43 +0100 |
| commit | b9a0401e2368894e135b1d1e870219c6b1543af2 (patch) | |
| tree | 108527ce39611ed0218ebb42b22aa68063825096 /src/arch/wasm/CodeGen.zig | |
| parent | f644c8b0478126484ce2780eb98336c2b4ff0177 (diff) | |
| download | zig-b9a0401e2368894e135b1d1e870219c6b1543af2.tar.gz zig-b9a0401e2368894e135b1d1e870219c6b1543af2.zip | |
wasm: Implement @ptrToInt and fix indirect function call
- Previously the table index and function type index were switched.
This commit swaps them.
- This also emits the correct indirect function calls count when importing the function table
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index d19810df54..3ce64d4e89 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1200,6 +1200,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { .optional_payload => self.airOptionalPayload(inst), .optional_payload_ptr => self.airOptionalPayload(inst), .optional_payload_ptr_set => self.airOptionalPayloadPtrSet(inst), + .ptrtoint => self.airPtrToInt(inst), .ret => self.airRet(inst), .ret_ptr => self.airRetPtr(inst), .ret_load => self.airRetLoad(inst), @@ -1729,6 +1730,8 @@ fn emitConstant(self: *Self, val: Value, ty: Type) InnerError!void { } else { try self.addLabel(.memory_address, decl.link.wasm.sym_index); } + } else if (val.castTag(.int_u64)) |int_ptr| { + try self.addImm32(@bitCast(i32, @intCast(u32, int_ptr.data))); } else return self.fail("Wasm TODO: emitConstant for other const pointer tag {s}", .{val.tag()}); }, .Void => {}, @@ -2601,3 +2604,9 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) InnerError!WValue { return slice_local; } + +fn airPtrToInt(self: *Self, inst: Air.Inst.Index) InnerError!WValue { + if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; + const un_op = self.air.instructions.items(.data)[inst].un_op; + return self.resolveInst(un_op); +} |
