Merge pull request #26 from bainchild/trunk

Attempt to add memory copy/fill (allocator edition)
This commit is contained in:
Rerumu
2023-02-16 16:18:01 -05:00
committed by GitHub
7 changed files with 181 additions and 7 deletions
+30 -2
View File
@@ -4,8 +4,8 @@ use std::{
};
use wasm_ast::node::{
Block, Br, BrIf, BrTable, Call, CallIndirect, FuncData, If, LabelType, MemoryGrow, SetGlobal,
SetLocal, SetTemporary, Statement, StoreAt, Terminator,
Block, Br, BrIf, BrTable, Call, CallIndirect, FuncData, If, LabelType, MemoryGrow, MemoryCopy,
MemoryFill, SetGlobal, SetLocal, SetTemporary, Statement, StoreAt, Terminator,
};
use wasmparser::ValType;
@@ -282,6 +282,32 @@ impl DriverNoContext for MemoryGrow {
}
}
impl DriverNoContext for MemoryCopy {
fn write(&self, w: &mut dyn Write) -> Result<()> {
let dst = self.dst();
let src = self.src();
write!(w, "rt.allocator.copy(memory_at_0, {dst}, {src}, ")?;
self.size().write(w)?;
write!(w, ")")
}
}
impl DriverNoContext for MemoryFill {
fn write(&self, w: &mut dyn Write) -> Result<()> {
let mem = self.mem();
let value = self.value();
let n = self.n();
write!(w, "rt.allocator.fill(memory_at_0, {mem}, ")?;
value.write(w)?;
write!(w, ", ")?;
n.write(w)?;
write!(w, ")")
}
}
fn write_stat(stat: &dyn DriverNoContext, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
indentation!(mng, w)?;
stat.write(w)?;
@@ -301,6 +327,8 @@ impl Driver for Statement {
Self::SetGlobal(s) => write_stat(s, mng, w),
Self::StoreAt(s) => write_stat(s, mng, w),
Self::MemoryGrow(s) => write_stat(s, mng, w),
Self::MemoryCopy(s) => write_stat(s, mng, w),
Self::MemoryFill(s) => write_stat(s, mng, w)
}
}
}