aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig6
-rw-r--r--src/codegen/llvm.zig22
2 files changed, 22 insertions, 6 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index a36b58041c..ba7bb6fa3a 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -3592,14 +3592,16 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
}
fn airWasmMemorySize(f: *Function, inst: Air.Inst.Index) !CValue {
- const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
+ if (f.liveness.isUnused(inst)) return CValue.none;
+
+ const pl_op = f.air.instructions.items(.data)[inst].pl_op;
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});
+ try writer.print("zig_wasm_memory_size({d});\n", .{pl_op.payload});
return local;
}
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index bf754c975b..368a67f4b4 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -3478,13 +3478,27 @@ pub const FuncGen = struct {
}
fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
- _ = inst;
- return self.todo("implement builtin `@wasmMemorySize()`", .{});
+ if (self.liveness.isUnused(inst)) return null;
+
+ const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+ const index = pl_op.payload;
+ const llvm_u32 = self.context.intType(32);
+ const llvm_fn = self.getIntrinsic("llvm.wasm.memory.size.i32", &.{llvm_u32});
+ const args: [1]*const llvm.Value = .{llvm_u32.constInt(index, .False)};
+ return self.builder.buildCall(llvm_fn, &args, args.len, .Fast, .Auto, "");
}
fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
- _ = inst;
- return self.todo("implement builtin `@wasmMemoryGrow()`", .{});
+ const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+ const index = pl_op.payload;
+ const operand = try self.resolveInst(pl_op.operand);
+ const llvm_u32 = self.context.intType(32);
+ const llvm_fn = self.getIntrinsic("llvm.wasm.memory.grow.i32", &.{ llvm_u32, llvm_u32 });
+ const args: [2]*const llvm.Value = .{
+ llvm_u32.constInt(index, .False),
+ operand,
+ };
+ return self.builder.buildCall(llvm_fn, &args, args.len, .Fast, .Auto, "");
}
fn airMin(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {