wit_bindgen_core::abi

Enum Instruction

Source
pub enum Instruction<'a> {
Show 79 variants GetArg { nth: usize, }, I32Const { val: i32, }, Bitcasts { casts: &'a [Bitcast], }, ConstZero { tys: &'a [WasmType], }, I32Load { offset: i32, }, I32Load8U { offset: i32, }, I32Load8S { offset: i32, }, I32Load16U { offset: i32, }, I32Load16S { offset: i32, }, I64Load { offset: i32, }, F32Load { offset: i32, }, F64Load { offset: i32, }, PointerLoad { offset: i32, }, LengthLoad { offset: i32, }, I32Store { offset: i32, }, I32Store8 { offset: i32, }, I32Store16 { offset: i32, }, I64Store { offset: i32, }, F32Store { offset: i32, }, F64Store { offset: i32, }, PointerStore { offset: i32, }, LengthStore { offset: i32, }, I32FromChar, I64FromU64, I64FromS64, I32FromU32, I32FromS32, I32FromU16, I32FromS16, I32FromU8, I32FromS8, CoreF32FromF32, CoreF64FromF64, S8FromI32, U8FromI32, S16FromI32, U16FromI32, S32FromI32, U32FromI32, S64FromI64, U64FromI64, CharFromI32, F32FromCoreF32, F64FromCoreF64, BoolFromI32, I32FromBool, ListCanonLower { element: &'a Type, realloc: Option<&'a str>, }, StringLower { realloc: Option<&'a str>, }, ListLower { element: &'a Type, realloc: Option<&'a str>, }, ListCanonLift { element: &'a Type, ty: TypeId, }, StringLift, ListLift { element: &'a Type, ty: TypeId, }, IterElem { element: &'a Type, }, IterBasePointer, RecordLower { record: &'a Record, name: &'a str, ty: TypeId, }, RecordLift { record: &'a Record, name: &'a str, ty: TypeId, }, HandleLower { handle: &'a Handle, name: &'a str, ty: TypeId, }, HandleLift { handle: &'a Handle, name: &'a str, ty: TypeId, }, TupleLower { tuple: &'a Tuple, ty: TypeId, }, TupleLift { tuple: &'a Tuple, ty: TypeId, }, FlagsLower { flags: &'a Flags, name: &'a str, ty: TypeId, }, FlagsLift { flags: &'a Flags, name: &'a str, ty: TypeId, }, VariantPayloadName, VariantLower { variant: &'a Variant, name: &'a str, ty: TypeId, results: &'a [WasmType], }, VariantLift { variant: &'a Variant, name: &'a str, ty: TypeId, }, EnumLower { enum_: &'a Enum, name: &'a str, ty: TypeId, }, EnumLift { enum_: &'a Enum, name: &'a str, ty: TypeId, }, OptionLower { payload: &'a Type, ty: TypeId, results: &'a [WasmType], }, OptionLift { payload: &'a Type, ty: TypeId, }, ResultLower { result: &'a Result_, ty: TypeId, results: &'a [WasmType], }, ResultLift { result: &'a Result_, ty: TypeId, }, CallWasm { name: &'a str, sig: &'a WasmSignature, }, CallInterface { func: &'a Function, }, Return { amt: usize, func: &'a Function, }, Malloc { realloc: &'static str, size: usize, align: usize, }, GuestDeallocate { size: usize, align: usize, }, GuestDeallocateString, GuestDeallocateList { element: &'a Type, }, GuestDeallocateVariant { blocks: usize, },
}

Variants§

§

GetArg

Acquires the specified parameter and places it on the stack. Depending on the context this may refer to wasm parameters or interface types parameters.

Fields

§nth: usize
§

I32Const

Pushes the constant val onto the stack.

Fields

§val: i32
§

Bitcasts

Casts the top N items on the stack using the Bitcast enum provided. Consumes the same number of operands that this produces.

Fields

§casts: &'a [Bitcast]
§

ConstZero

Pushes a number of constant zeros for each wasm type on the stack.

Fields

§tys: &'a [WasmType]
§

I32Load

Pops a pointer from the stack and loads a little-endian i32 from it, using the specified constant offset.

Fields

§offset: i32
§

I32Load8U

Pops a pointer from the stack and loads a little-endian i8 from it, using the specified constant offset. The value loaded is the zero-extended to 32-bits

Fields

§offset: i32
§

I32Load8S

Pops a pointer from the stack and loads a little-endian i8 from it, using the specified constant offset. The value loaded is the sign-extended to 32-bits

Fields

§offset: i32
§

I32Load16U

Pops a pointer from the stack and loads a little-endian i16 from it, using the specified constant offset. The value loaded is the zero-extended to 32-bits

Fields

§offset: i32
§

I32Load16S

Pops a pointer from the stack and loads a little-endian i16 from it, using the specified constant offset. The value loaded is the sign-extended to 32-bits

Fields

§offset: i32
§

I64Load

Pops a pointer from the stack and loads a little-endian i64 from it, using the specified constant offset.

Fields

§offset: i32
§

F32Load

Pops a pointer from the stack and loads a little-endian f32 from it, using the specified constant offset.

Fields

§offset: i32
§

F64Load

Pops a pointer from the stack and loads a little-endian f64 from it, using the specified constant offset.

Fields

§offset: i32
§

PointerLoad

Like I32Load or I64Load, but for loading pointer values.

Fields

§offset: i32
§

LengthLoad

Like I32Load or I64Load, but for loading array length values.

Fields

§offset: i32
§

I32Store

Pops a pointer from the stack and then an i32 value. Stores the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

I32Store8

Pops a pointer from the stack and then an i32 value. Stores the low 8 bits of the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

I32Store16

Pops a pointer from the stack and then an i32 value. Stores the low 16 bits of the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

I64Store

Pops a pointer from the stack and then an i64 value. Stores the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

F32Store

Pops a pointer from the stack and then an f32 value. Stores the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

F64Store

Pops a pointer from the stack and then an f64 value. Stores the value in little-endian at the pointer specified plus the constant offset.

Fields

§offset: i32
§

PointerStore

Like I32Store or I64Store, but for storing pointer values.

Fields

§offset: i32
§

LengthStore

Like I32Store or I64Store, but for storing array length values.

Fields

§offset: i32
§

I32FromChar

Converts an interface type char value to a 32-bit integer representing the unicode scalar value.

§

I64FromU64

Converts an interface type u64 value to a wasm i64.

§

I64FromS64

Converts an interface type s64 value to a wasm i64.

§

I32FromU32

Converts an interface type u32 value to a wasm i32.

§

I32FromS32

Converts an interface type s32 value to a wasm i32.

§

I32FromU16

Converts an interface type u16 value to a wasm i32.

§

I32FromS16

Converts an interface type s16 value to a wasm i32.

§

I32FromU8

Converts an interface type u8 value to a wasm i32.

§

I32FromS8

Converts an interface type s8 value to a wasm i32.

§

CoreF32FromF32

Conversion an interface type f32 value to a wasm f32.

This may be a noop for some implementations, but it’s here in case the native language representation of f32 is different than the wasm representation of f32.

§

CoreF64FromF64

Conversion an interface type f64 value to a wasm f64.

This may be a noop for some implementations, but it’s here in case the native language representation of f64 is different than the wasm representation of f64.

§

S8FromI32

Converts a native wasm i32 to an interface type s8.

This will truncate the upper bits of the i32.

§

U8FromI32

Converts a native wasm i32 to an interface type u8.

This will truncate the upper bits of the i32.

§

S16FromI32

Converts a native wasm i32 to an interface type s16.

This will truncate the upper bits of the i32.

§

U16FromI32

Converts a native wasm i32 to an interface type u16.

This will truncate the upper bits of the i32.

§

S32FromI32

Converts a native wasm i32 to an interface type s32.

§

U32FromI32

Converts a native wasm i32 to an interface type u32.

§

S64FromI64

Converts a native wasm i64 to an interface type s64.

§

U64FromI64

Converts a native wasm i64 to an interface type u64.

§

CharFromI32

Converts a native wasm i32 to an interface type char.

It’s safe to assume that the i32 is indeed a valid unicode code point.

§

F32FromCoreF32

Converts a native wasm f32 to an interface type f32.

§

F64FromCoreF64

Converts a native wasm f64 to an interface type f64.

§

BoolFromI32

Creates a bool from an i32 input, trapping if the i32 isn’t zero or one.

§

I32FromBool

Creates an i32 from a bool input, must return 0 or 1.

§

ListCanonLower

Lowers a list where the element’s layout in the native language is expected to match the canonical ABI definition of interface types.

Pops a list value from the stack and pushes the pointer/length onto the stack. If realloc is set to Some then this is expected to consume the list which means that the data needs to be copied. An allocation/copy is expected when:

  • A host is calling a wasm export with a list (it needs to copy the list in to the callee’s module, allocating space with realloc)
  • A wasm export is returning a list (it’s expected to use realloc to give ownership of the list to the caller.
  • A host is returning a list in a import definition, meaning that space needs to be allocated in the caller with realloc).

A copy does not happen (e.g. realloc is None) when:

  • A wasm module calls an import with the list. In this situation it’s expected the caller will know how to access this module’s memory (e.g. the host has raw access or wasm-to-wasm communication would copy the list).

If realloc is Some then the adapter is not responsible for cleaning up this list because the other end is receiving the allocation. If realloc is None then the adapter is responsible for cleaning up any temporary allocation it created, if any.

Fields

§element: &'a Type
§realloc: Option<&'a str>
§

StringLower

Same as ListCanonLower, but used for strings

Fields

§realloc: Option<&'a str>
§

ListLower

Lowers a list where the element’s layout in the native language is not expected to match the canonical ABI definition of interface types.

Pops a list value from the stack and pushes the pointer/length onto the stack. This operation also pops a block from the block stack which is used as the iteration body of writing each element of the list consumed.

The realloc field here behaves the same way as ListCanonLower. It’s only set to None when a wasm module calls a declared import. Otherwise lowering in other contexts requires allocating memory for the receiver to own.

Fields

§element: &'a Type
§realloc: Option<&'a str>
§

ListCanonLift

Lifts a list which has a canonical representation into an interface types value.

The term “canonical” representation here means that the representation of the interface types value in the native language exactly matches the canonical ABI definition of the type.

This will consume two i32 values from the stack, a pointer and a length, and then produces an interface value list.

Fields

§element: &'a Type
§

StringLift

Same as ListCanonLift, but used for strings

§

ListLift

Lifts a list which into an interface types value.

This will consume two i32 values from the stack, a pointer and a length, and then produces an interface value list.

This will also pop a block from the block stack which is how to read each individual element from the list.

Fields

§element: &'a Type
§

IterElem

Pushes an operand onto the stack representing the list item from each iteration of the list.

This is only used inside of blocks related to lowering lists.

Fields

§element: &'a Type
§

IterBasePointer

Pushes an operand onto the stack representing the base pointer of the next element in a list.

This is used for both lifting and lowering lists.

§

RecordLower

Pops a record value off the stack, decomposes the record to all of its fields, and then pushes the fields onto the stack.

Fields

§record: &'a Record
§name: &'a str
§

RecordLift

Pops all fields for a record off the stack and then composes them into a record.

Fields

§record: &'a Record
§name: &'a str
§

HandleLower

Create an i32 from a handle.

Fields

§handle: &'a Handle
§name: &'a str
§

HandleLift

Create a handle from an i32.

Fields

§handle: &'a Handle
§name: &'a str
§

TupleLower

Pops a tuple value off the stack, decomposes the tuple to all of its fields, and then pushes the fields onto the stack.

Fields

§tuple: &'a Tuple
§

TupleLift

Pops all fields for a tuple off the stack and then composes them into a tuple.

Fields

§tuple: &'a Tuple
§

FlagsLower

Converts a language-specific record-of-bools to a list of i32.

Fields

§flags: &'a Flags
§name: &'a str
§

FlagsLift

Converts a list of native wasm i32 to a language-specific record-of-bools.

Fields

§flags: &'a Flags
§name: &'a str
§

VariantPayloadName

This is a special instruction used for VariantLower instruction to determine the name of the payload, if present, to use within each block.

Each sub-block will have this be the first instruction, and if it lowers a payload it will expect something bound to this name.

§

VariantLower

Pops a variant off the stack as well as ty.cases.len() blocks from the code generator. Uses each of those blocks and the value from the stack to produce nresults of items.

Fields

§variant: &'a Variant
§name: &'a str
§results: &'a [WasmType]
§

VariantLift

Pops an i32 off the stack as well as ty.cases.len() blocks from the code generator. Uses each of those blocks and the value from the stack to produce a final variant.

Fields

§variant: &'a Variant
§name: &'a str
§

EnumLower

Pops an enum off the stack and pushes the i32 representation.

Fields

§enum_: &'a Enum
§name: &'a str
§

EnumLift

Pops an i32 off the stack and lifts it into the enum specified.

Fields

§enum_: &'a Enum
§name: &'a str
§

OptionLower

Specialization of VariantLower for specifically option<T> types, otherwise behaves the same as VariantLower (e.g. two blocks for the two cases.

Fields

§payload: &'a Type
§results: &'a [WasmType]
§

OptionLift

Specialization of VariantLift for specifically the option<T> type. Otherwise behaves the same as the VariantLift instruction with two blocks for the lift.

Fields

§payload: &'a Type
§

ResultLower

Specialization of VariantLower for specifically result<T, E> types, otherwise behaves the same as VariantLower (e.g. two blocks for the two cases.

Fields

§result: &'a Result_
§results: &'a [WasmType]
§

ResultLift

Specialization of VariantLift for specifically the result<T, E> type. Otherwise behaves the same as the VariantLift instruction with two blocks for the lift.

Fields

§result: &'a Result_
§

CallWasm

Represents a call to a raw WebAssembly API. The module/name are provided inline as well as the types if necessary.

Fields

§name: &'a str
§

CallInterface

Same as CallWasm, except the dual where an interface is being called rather than a raw wasm function.

Note that this will be used for async functions.

Fields

§func: &'a Function
§

Return

Returns amt values on the stack. This is always the last instruction.

Fields

§amt: usize
§func: &'a Function
§

Malloc

Calls the realloc function specified in a malloc-like fashion allocating size bytes with alignment align.

Pushes the returned pointer onto the stack.

Fields

§realloc: &'static str
§size: usize
§align: usize
§

GuestDeallocate

Used exclusively for guest-code generation this indicates that the standard memory deallocation function needs to be invoked with the specified parameters.

This will pop a pointer from the stack and push nothing.

Fields

§size: usize
§align: usize
§

GuestDeallocateString

Used exclusively for guest-code generation this indicates that a string is being deallocated. The ptr/length are on the stack and are poppped off and used to deallocate the string.

§

GuestDeallocateList

Used exclusively for guest-code generation this indicates that a list is being deallocated. The ptr/length are on the stack and are poppped off and used to deallocate the list.

This variant also pops a block off the block stack to be used as the body of the deallocation loop.

Fields

§element: &'a Type
§

GuestDeallocateVariant

Used exclusively for guest-code generation this indicates that a variant is being deallocated. The integer discriminant is popped off the stack as well as blocks number of blocks popped from the blocks stack. The variant is used to select, at runtime, which of the blocks is executed to deallocate the variant.

Fields

§blocks: usize

Implementations§

Source§

impl Instruction<'_>

Source

pub fn operands_len(&self) -> usize

How many operands does this instruction pop from the stack?

Source

pub fn results_len(&self) -> usize

How many results does this instruction push onto the stack?

Trait Implementations§

Source§

impl<'a> Debug for Instruction<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Instruction<'a>

§

impl<'a> RefUnwindSafe for Instruction<'a>

§

impl<'a> Send for Instruction<'a>

§

impl<'a> Sync for Instruction<'a>

§

impl<'a> Unpin for Instruction<'a>

§

impl<'a> UnwindSafe for Instruction<'a>

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> 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, 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.