pub enum MemoryInstruction {
Show 14 variants
Load(NumberType, MemoryArgument),
Store(NumberType, MemoryArgument),
Load8(IntegerType, SignExtension, MemoryArgument),
Load16(IntegerType, SignExtension, MemoryArgument),
Load32(SignExtension, MemoryArgument),
Store8(IntegerType, MemoryArgument),
Store16(IntegerType, MemoryArgument),
Store32(MemoryArgument),
Size,
Grow,
Fill,
Copy,
Init(DataIndex),
DataDrop(DataIndex),
}Expand description
Instructions in this group are concerned with linear memory. Memory is accessed with π ππΊπ½ and πππππΎ instructions for the different value types. They all take a memory immediate memarg that contains an address offset and the expected alignment (expressed as the exponent of a power of 2). Integer loads and stores can optionally specify a storage size that is smaller than the bit width of the respective value type. In the case of loads, a sign extension mode sx is then required to select appropriate behavior.
The static address offset is added to the dynamic address operand, yielding a 33 bit effective address that is the zero-based index at which the memory is accessed. All values are read and written in little endian byte order. A trap results if any of the accessed memory bytes lies outside the address range implied by the memoryβs current size.
See https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions
Β§Examples
use wasm_ast::{MemoryInstruction, Instruction, NumberType, MemoryArgument, IntegerType, SignExtension};
assert_eq!(
Instruction::Memory(MemoryInstruction::Load(NumberType::I32, MemoryArgument::default_offset(4))),
MemoryInstruction::Load(NumberType::I32, MemoryArgument::default_offset(4)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Load8(IntegerType::I32, SignExtension::Signed, MemoryArgument::default_offset(1))),
MemoryInstruction::Load8(IntegerType::I32, SignExtension::Signed, MemoryArgument::default_offset(1)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Load16(IntegerType::I64, SignExtension::Unsigned, MemoryArgument::default_offset(2))),
MemoryInstruction::Load16(IntegerType::I64, SignExtension::Unsigned, MemoryArgument::default_offset(2)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Load32(SignExtension::Signed, MemoryArgument::default_offset(4))),
MemoryInstruction::Load32(SignExtension::Signed, MemoryArgument::default_offset(4)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Store(NumberType::F64, MemoryArgument::default_offset(8))),
MemoryInstruction::Store(NumberType::F64, MemoryArgument::new(8, 0)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Store8(IntegerType::I32, MemoryArgument::default_offset(1))),
MemoryInstruction::Store8(IntegerType::I32, MemoryArgument::default_offset(1)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Store16(IntegerType::I64, MemoryArgument::default_offset(2))),
MemoryInstruction::Store16(IntegerType::I64, MemoryArgument::default_offset(2)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Store32(MemoryArgument::default_offset(4))),
MemoryInstruction::Store32(MemoryArgument::default_offset(4)).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Size),
MemoryInstruction::Size.into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Grow),
MemoryInstruction::Grow.into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Fill),
MemoryInstruction::Fill.into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Copy),
MemoryInstruction::Copy.into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::Init(1)),
MemoryInstruction::Init(1).into()
);
assert_eq!(
Instruction::Memory(MemoryInstruction::DataDrop(0)),
MemoryInstruction::DataDrop(0).into()
);VariantsΒ§
Load(NumberType, MemoryArgument)
xnn.load memarg Load a number type from memory.
Store(NumberType, MemoryArgument)
xnn.store memarg Store a number type from memory.
Load8(IntegerType, SignExtension, MemoryArgument)
inn.load8_sx memarg Integer load that specifies a storage size that is smaller than the bit width of the respective value type.
Load16(IntegerType, SignExtension, MemoryArgument)
inn.load16_sx memarg
Load32(SignExtension, MemoryArgument)
i64.load32_sx memarg
Store8(IntegerType, MemoryArgument)
inn.store8 memarg Integer store that specifies a storage size that is smaller than the bit width of the respective value type.
Store16(IntegerType, MemoryArgument)
inn.store16 memarg
Store32(MemoryArgument)
i64.store32 memarg
Size
The ππΎππππ.ππππΎ instruction returns the current size of a memory. Operates in units of page size.
Grow
The ππΎππππ.ππππ instruction grows memory by a given delta and returns the previous size, or β1 if enough memory cannot be allocated.
Fill
The ππΎππππ.πΏππ π instruction sets all values in a region to a given byte.
Copy
The ππΎππππ.πΌπππ instruction copies data from a source memory region to a possibly overlapping destination region.
Init(DataIndex)
The ππΎππππ.ππππ instruction copies data from a passive data segment into a memory.
DataDrop(DataIndex)
he π½πΊππΊ.π½πππ instruction prevents further use of a passive data segment. This instruction is intended to be used as an optimization hint. After a data segment is dropped its data can no longer be retrieved, so the memory used by this segment may be freed.
Trait ImplementationsΒ§
SourceΒ§impl Clone for MemoryInstruction
impl Clone for MemoryInstruction
SourceΒ§fn clone(&self) -> MemoryInstruction
fn clone(&self) -> MemoryInstruction
1.0.0 Β· SourceΒ§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more