Add memory.copy and memory.fill support
This commit is contained in:
parent
1878db1c1d
commit
a932920dc3
|
@ -514,6 +514,15 @@ impl<'a> WasmFuncBackend<'a> {
|
|||
Operator::MemoryGrow { mem } => {
|
||||
Some(wasm_encoder::Instruction::MemoryGrow(mem.index() as u32))
|
||||
}
|
||||
Operator::MemoryCopy { dst_mem, src_mem } => {
|
||||
Some(wasm_encoder::Instruction::MemoryCopy {
|
||||
src_mem: src_mem.index() as u32,
|
||||
dst_mem: dst_mem.index() as u32,
|
||||
})
|
||||
}
|
||||
Operator::MemoryFill { mem } => {
|
||||
Some(wasm_encoder::Instruction::MemoryFill(mem.index() as u32))
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(inst) = inst {
|
||||
|
|
|
@ -221,6 +221,8 @@ pub fn op_inputs(
|
|||
Operator::TableSize { .. } => Ok(Cow::Borrowed(&[])),
|
||||
Operator::MemorySize { .. } => Ok(Cow::Borrowed(&[])),
|
||||
Operator::MemoryGrow { .. } => Ok(Cow::Borrowed(&[Type::I32])),
|
||||
Operator::MemoryCopy { .. } => Ok(Cow::Borrowed(&[Type::I32, Type::I32, Type::I32])),
|
||||
Operator::MemoryFill { .. } => Ok(Cow::Borrowed(&[Type::I32, Type::I32, Type::I32])),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,6 +427,8 @@ pub fn op_outputs(
|
|||
Operator::TableSize { .. } => Ok(Cow::Borrowed(&[Type::I32])),
|
||||
Operator::MemorySize { .. } => Ok(Cow::Borrowed(&[Type::I32])),
|
||||
Operator::MemoryGrow { .. } => Ok(Cow::Borrowed(&[Type::I32])),
|
||||
Operator::MemoryCopy { .. } => Ok(Cow::Borrowed(&[])),
|
||||
Operator::MemoryFill { .. } => Ok(Cow::Borrowed(&[])),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,6 +639,8 @@ impl Operator {
|
|||
Operator::TableSize { .. } => &[ReadTable],
|
||||
Operator::MemorySize { .. } => &[ReadMem],
|
||||
Operator::MemoryGrow { .. } => &[WriteMem, Trap],
|
||||
Operator::MemoryCopy { .. } => &[Trap, ReadMem, WriteMem],
|
||||
Operator::MemoryFill { .. } => &[Trap, WriteMem],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -853,6 +859,10 @@ impl std::fmt::Display for Operator {
|
|||
Operator::TableSize { table_index, .. } => write!(f, "table_size<{}>", table_index)?,
|
||||
Operator::MemorySize { mem } => write!(f, "memory_size<{}>", mem)?,
|
||||
Operator::MemoryGrow { mem } => write!(f, "memory_grow<{}>", mem)?,
|
||||
Operator::MemoryCopy { dst_mem, src_mem } => {
|
||||
write!(f, "memory_copy<{}, {}>", dst_mem, src_mem)?
|
||||
}
|
||||
Operator::MemoryFill { mem } => write!(f, "memory_fill<{}>", mem)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
14
src/ops.rs
14
src/ops.rs
|
@ -295,6 +295,13 @@ pub enum Operator {
|
|||
MemoryGrow {
|
||||
mem: Memory,
|
||||
},
|
||||
MemoryCopy {
|
||||
dst_mem: Memory,
|
||||
src_mem: Memory,
|
||||
},
|
||||
MemoryFill {
|
||||
mem: Memory,
|
||||
},
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -568,6 +575,13 @@ impl<'a, 'b> std::convert::TryFrom<&'b wasmparser::Operator<'a>> for Operator {
|
|||
&wasmparser::Operator::MemoryGrow { mem, .. } => Ok(Operator::MemoryGrow {
|
||||
mem: Memory::from(mem),
|
||||
}),
|
||||
&wasmparser::Operator::MemoryCopy { dst_mem, src_mem } => Ok(Operator::MemoryCopy {
|
||||
dst_mem: Memory::from(dst_mem),
|
||||
src_mem: Memory::from(src_mem),
|
||||
}),
|
||||
&wasmparser::Operator::MemoryFill { mem } => {
|
||||
Ok(Operator::MemoryFill { mem: Memory::from(mem) })
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue