Attempt to add memory copy/fill (2)
This commit is contained in:
+25
-2
@@ -5,8 +5,8 @@ use crate::{
|
||||
node::{
|
||||
BinOp, BinOpType, Block, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, CmpOpType,
|
||||
Expression, FuncData, GetGlobal, GetLocal, If, LabelType, LoadAt, LoadType, MemoryGrow,
|
||||
MemorySize, Select, SetGlobal, SetLocal, Statement, StoreAt, StoreType, Terminator, UnOp,
|
||||
UnOpType, Value,
|
||||
MemoryCopy, MemoryFill, MemorySize, Select, SetGlobal, SetLocal, Statement, StoreAt,
|
||||
StoreType, Terminator, UnOp, UnOpType, Value,
|
||||
},
|
||||
stack::{ReadType, Stack},
|
||||
};
|
||||
@@ -609,6 +609,29 @@ impl<'a> Factory<'a> {
|
||||
self.target.leak_memory_write(memory);
|
||||
self.target.code.push(data);
|
||||
}
|
||||
Operator::MemoryCopy { src, dst } => {
|
||||
let size = self.target.stack.pop().into();
|
||||
|
||||
let data = Statement::MemoryCopy(MemoryCopy {
|
||||
dst,
|
||||
src,
|
||||
size,
|
||||
});
|
||||
|
||||
self.target.code.push(data);
|
||||
}
|
||||
Operator::MemoryFill { mem } => {
|
||||
let n = self.target.stack.pop().into();
|
||||
let value = self.target.stack.pop().into();
|
||||
|
||||
let data = Statement::MemoryFill(MemoryFill {
|
||||
mem,
|
||||
n,
|
||||
value,
|
||||
});
|
||||
|
||||
self.target.code.push(data);
|
||||
}
|
||||
Operator::I32Const { value } => self.target.push_constant(value),
|
||||
Operator::I64Const { value } => self.target.push_constant(value),
|
||||
Operator::F32Const { value } => self.target.push_constant(value.bits()),
|
||||
|
||||
@@ -1108,6 +1108,48 @@ impl MemoryGrow {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MemoryCopy {
|
||||
pub(crate) dst: u32,
|
||||
pub(crate) src: u32,
|
||||
pub(crate) size: Box<Expression>,
|
||||
}
|
||||
|
||||
impl MemoryCopy {
|
||||
#[must_use]
|
||||
pub fn dst(&self) -> u32 {
|
||||
self.dst
|
||||
}
|
||||
#[must_use]
|
||||
pub fn src(&self) -> u32 {
|
||||
self.src
|
||||
}
|
||||
#[must_use]
|
||||
pub fn size(&self) -> &Expression {
|
||||
&self.size
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MemoryFill {
|
||||
pub(crate) mem: u32,
|
||||
pub(crate) value: Box<Expression>,
|
||||
pub(crate) n: Box<Expression>,
|
||||
}
|
||||
|
||||
impl MemoryFill {
|
||||
#[must_use]
|
||||
pub fn mem(&self) -> u32 {
|
||||
self.mem
|
||||
}
|
||||
#[must_use]
|
||||
pub fn value(&self) -> &Expression {
|
||||
&self.value
|
||||
}
|
||||
#[must_use]
|
||||
pub fn n(&self) -> &Expression {
|
||||
&self.n
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Statement {
|
||||
Block(Block),
|
||||
BrIf(BrIf),
|
||||
@@ -1119,6 +1161,8 @@ pub enum Statement {
|
||||
SetGlobal(SetGlobal),
|
||||
StoreAt(StoreAt),
|
||||
MemoryGrow(MemoryGrow),
|
||||
MemoryCopy(MemoryCopy),
|
||||
MemoryFill(MemoryFill)
|
||||
}
|
||||
|
||||
pub struct FuncData {
|
||||
|
||||
+24
-1
@@ -1,6 +1,6 @@
|
||||
use crate::node::{
|
||||
BinOp, Block, Br, BrIf, BrTable, Call, CallIndirect, CmpOp, Expression, FuncData, GetGlobal,
|
||||
GetLocal, GetTemporary, If, LoadAt, MemoryGrow, MemorySize, Select, SetGlobal, SetLocal,
|
||||
GetLocal, GetTemporary, If, LoadAt, MemoryGrow, MemorySize, MemoryCopy, MemoryFill, Select, SetGlobal, SetLocal,
|
||||
SetTemporary, Statement, StoreAt, Terminator, UnOp, Value,
|
||||
};
|
||||
|
||||
@@ -55,6 +55,10 @@ pub trait Visitor {
|
||||
|
||||
fn visit_memory_grow(&mut self, _: &MemoryGrow) {}
|
||||
|
||||
fn visit_memory_copy(&mut self, _: &MemoryCopy) {}
|
||||
|
||||
fn visit_memory_fill(&mut self, _: &MemoryFill) {}
|
||||
|
||||
fn visit_statement(&mut self, _: &Statement) {}
|
||||
}
|
||||
|
||||
@@ -104,6 +108,23 @@ impl<T: Visitor> Driver<T> for MemorySize {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Visitor> Driver<T> for MemoryCopy {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
self.size().accept(visitor);
|
||||
|
||||
visitor.visit_memory_copy(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Visitor> Driver<T> for MemoryFill {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
self.value().accept(visitor);
|
||||
self.n().accept(visitor);
|
||||
|
||||
visitor.visit_memory_fill(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Visitor> Driver<T> for Value {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_value(self);
|
||||
@@ -145,6 +166,8 @@ impl<T: Visitor> Driver<T> for Expression {
|
||||
Self::GetGlobal(v) => v.accept(visitor),
|
||||
Self::LoadAt(v) => v.accept(visitor),
|
||||
Self::MemorySize(v) => v.accept(visitor),
|
||||
Self::MemoryCopy(v) => v.accept(visitor),
|
||||
Self::MemoryFill(v) => v.accept(visitor),
|
||||
Self::Value(v) => v.accept(visitor),
|
||||
Self::UnOp(v) => v.accept(visitor),
|
||||
Self::BinOp(v) => v.accept(visitor),
|
||||
|
||||
Reference in New Issue
Block a user