aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-04-15 16:17:25 +0200
committerLuuk de Gram <luuk@degram.dev>2023-04-22 21:16:23 +0200
commitc4b295bb6e9fcb1d02122cb70c95019c81ae543e (patch)
treed83d44b17acddd5be0affc7cc368e479ae4f9acd /src/arch/wasm/CodeGen.zig
parent21aa55d34e432b677f71cbb377aa89c8cdbd1483 (diff)
downloadzig-c4b295bb6e9fcb1d02122cb70c95019c81ae543e.tar.gz
zig-c4b295bb6e9fcb1d02122cb70c95019c81ae543e.zip
wasm: implement `cmp_lt_errors_len` instruction
Creates a global undefined symbol when this instruction is called. The linker will then resolve it as a lazy symbol, ensuring it is only generated when the symbol was created. In `flush` it will then generate the function as only then, all errors are known and we can generate the function body. This logic allows us to re-use the same functionality of linker-synthetic-functions.
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index b94d3993f9..0d73e35185 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -3338,9 +3338,13 @@ fn airCmpVector(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const un_op = func.air.instructions.items(.data)[inst].un_op;
const operand = try func.resolveInst(un_op);
+ const sym_index = try func.bin_file.getGlobalSymbol("__zig_lt_errors_len", null);
- _ = operand;
- return func.fail("TODO implement airCmpLtErrorsLen for wasm", .{});
+ try func.emitWValue(operand);
+ try func.addLabel(.call, sym_index);
+ const result = try func.allocLocal(Type.bool);
+ try func.addLabel(.local_set, result.local.value);
+ return func.finishAir(inst, result, &.{un_op});
}
fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {