MemoryInstruction

Enum MemoryInstruction 

Source
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

SourceΒ§

fn clone(&self) -> MemoryInstruction

Returns a duplicate of the value. Read more
1.0.0 Β· SourceΒ§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
SourceΒ§

impl Debug for MemoryInstruction

SourceΒ§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
SourceΒ§

impl From<MemoryInstruction> for Instruction

SourceΒ§

fn from(instruction: MemoryInstruction) -> Self

Converts to this type from the input type.
SourceΒ§

impl PartialEq for MemoryInstruction

SourceΒ§

fn eq(&self, other: &MemoryInstruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 Β· SourceΒ§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
SourceΒ§

impl Copy for MemoryInstruction

SourceΒ§

impl Eq for MemoryInstruction

SourceΒ§

impl StructuralPartialEq for MemoryInstruction

Auto Trait ImplementationsΒ§

Blanket ImplementationsΒ§

SourceΒ§

impl<T> Any for T
where T: 'static + ?Sized,

SourceΒ§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
SourceΒ§

impl<T> Borrow<T> for T
where T: ?Sized,

SourceΒ§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
SourceΒ§

impl<T> BorrowMut<T> for T
where T: ?Sized,

SourceΒ§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
SourceΒ§

impl<T> CloneToUninit for T
where T: Clone,

SourceΒ§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

πŸ”¬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
SourceΒ§

impl<T> From<T> for T

SourceΒ§

fn from(t: T) -> T

Returns the argument unchanged.

SourceΒ§

impl<T, U> Into<U> for T
where U: From<T>,

SourceΒ§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

SourceΒ§

impl<T> ToOwned for T
where T: Clone,

SourceΒ§

type Owned = T

The resulting type after obtaining ownership.
SourceΒ§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
SourceΒ§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
SourceΒ§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

SourceΒ§

type Error = Infallible

The type returned in the event of a conversion error.
SourceΒ§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
SourceΒ§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

SourceΒ§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
SourceΒ§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.