diff options
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/c.zig | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 988576a6f1..a36b58041c 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1759,8 +1759,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .wrap_errunion_err => try airWrapErrUnionErr(f, inst), .errunion_payload_ptr_set => try airErrUnionPayloadPtrSet(f, inst), - .wasm_memory_size => unreachable, - .wasm_memory_grow => unreachable, + .wasm_memory_size => try airWasmMemorySize(f, inst), + .wasm_memory_grow => try airWasmMemoryGrow(f, inst), // zig fmt: on }; switch (result_value) { @@ -3591,6 +3591,34 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue { return CValue.none; } +fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue { + const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; + + const writer = f.object.writer(); + const inst_ty = f.air.typeOfIndex(inst); + const local = try f.allocLocal(inst_ty, .Const); + + try writer.writeAll(" = "); + try writer.print("zig_wasm_memory_size({d});\n", .{ty_pl.payload}); + + return local; +} + +fn airWasmMemoryGrow(f: *Function, inst: Air.Inst.Index) !CValue { + const pl_op = f.air.instructions.items(.data)[inst].pl_op; + + const writer = f.object.writer(); + const inst_ty = f.air.typeOfIndex(inst); + const operand = try f.resolveInst(pl_op.operand); + const local = try f.allocLocal(inst_ty, .Const); + + try writer.writeAll(" = "); + try writer.print("zig_wasm_memory_grow({d}, ", .{pl_op.payload}); + try f.writeCValue(writer, operand); + try writer.writeAll(");\n"); + return local; +} + fn toMemoryOrder(order: std.builtin.AtomicOrder) [:0]const u8 { return switch (order) { .Unordered => "memory_order_relaxed", |
