wasm: Implement @wasmMemoryGrow builtin

Similarly to the other wasm builtin, this implements the grow variation where the memory
index is a comptime known value. The operand as well as the result are runtime values.
This also verifies during semantic analysis the target we're building for is wasm, or else
emits a compilation error. This means that other backends do not have to handle this AIR instruction,
other than the wasm and LLVM backends.
This commit is contained in:
Luuk de Gram
2022-03-03 19:10:58 +01:00
committed by Andrew Kelley
parent ec4c30ae48
commit 43cb19ea4d
12 changed files with 75 additions and 5 deletions

View File

@@ -1758,6 +1758,9 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.wrap_errunion_payload => try airWrapErrUnionPay(f, inst),
.wrap_errunion_err => try airWrapErrUnionErr(f, inst),
.errunion_payload_ptr_set => try airErrUnionPayloadPtrSet(f, inst),
.wasm_memory_size => unreachable,
.wasm_memory_grow => unreachable,
// zig fmt: on
};
switch (result_value) {

View File

@@ -3478,7 +3478,12 @@ pub const FuncGen = struct {
fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
_ = inst;
return self.todo("`@wasmMemorySize()`", .{});
return self.todo("implement builtin `@wasmMemorySize()`", .{});
}
fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
_ = inst;
return self.todo("implement builtin `@wasmMemoryGrow()`", .{});
}
fn airMin(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {