Struct golem_wasm_ast::core::Module

source ·
pub struct Module<Ast: AstCustomization + 'static> { /* private fields */ }
Expand description

The top-level AST node representing a core WASM module

Some parts of the AST are customizable by the Ast type parameter. See AstCustomization for more details.

Implementations§

source§

impl<Ast> Module<Ast>
where Ast: AstCustomization + 'static, Ast::Expr: TryFromExprSource, Ast::Data: From<Data<Ast::Expr>>, Ast::Custom: From<Custom>,

source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, String>

Parses a module from a binary WASM byte array

source§

impl<Ast> Module<Ast>
where Ast: AstCustomization + 'static, Ast::Expr: RetainsInstructions, Ast::Data: Into<Data<Ast::Expr>>, Ast::Custom: Into<Custom>,

source

pub fn into_bytes(self) -> Result<Vec<u8>, String>

Serializes the module into a binary WASM byte array

source§

impl<Ast: AstCustomization> Module<Ast>

source

pub fn empty() -> Self

Creates an empty module

source

pub fn types(&self) -> Vec<Mrc<FuncType>>

Gets all the function types in the module

source

pub fn func_type_refs(&self) -> Vec<Mrc<FuncTypeRef>>

Gets all the function type references in the module

A more useful function is [funcs] that combines this and [codes] together.

source

pub fn codes(&self) -> Vec<Mrc<FuncCode<Ast::Expr>>>

Gets all the function codes in the module.

A more useful function is [funcs] that combines this and [codes] together.

source

pub fn funcs(&self) -> Vec<Func<Ast::Expr>>

Gets all the functions defined in the module

source

pub fn tables(&self) -> Vec<Mrc<Table>>

Gets all the tables defined in the module

source

pub fn mems(&self) -> Vec<Mrc<Mem>>

Gets all the memories defined in the module

source

pub fn globals(&self) -> Vec<Mrc<Global>>

Gets all the globals defined in the module

source

pub fn elems(&self) -> Vec<Mrc<Elem<Ast::Expr>>>

Gets all the elems defined in the module

source

pub fn datas(&self) -> Vec<Mrc<Ast::Data>>

Gets all the data sections defined in the module

source

pub fn start(&self) -> Option<Mrc<Start>>

Gets the start section of the module

source

pub fn imports(&self) -> Vec<Mrc<Import>>

Gets all the imports of the module

source

pub fn exports(&self) -> Vec<Mrc<Export>>

Gets all the exports of the module

source

pub fn customs(&self) -> Vec<Mrc<Ast::Custom>>

Gets all the custom sections of the module

source

pub fn add_data(&mut self, data: Ast::Data)

Adds a new data section

source

pub fn add_elem(&mut self, elem: Elem<Ast::Expr>)

Adds a new elem

source

pub fn add_export(&mut self, export: Export)

Adds a new export

source

pub fn add_function( &mut self, func_type: FuncType, locals: Vec<ValType>, body: Ast::Expr, ) -> FuncIdx

Adds a new function

source

pub fn add_global(&mut self, global: Global)

Adds a new global

source

pub fn add_memory(&mut self, mem: Mem)

Adds a new memory

source

pub fn add_table(&mut self, table: Table)

Adds a new table

source

pub fn add_type(&mut self, func_type: FuncType)

Adds a new function type

source

pub fn get_code( &mut self, func_idx: FuncIdx, ) -> Option<Mrc<FuncCode<Ast::Expr>>>

Gets a function body by its index

source

pub fn get_data(&mut self, data_idx: DataIdx) -> Option<Mrc<Ast::Data>>

Gets a data section by its index

source

pub fn get_elem(&mut self, elem_idx: ElemIdx) -> Option<Mrc<Elem<Ast::Expr>>>

Gets an elem by its index

source

pub fn get_export(&mut self, export_idx: ExportIdx) -> Option<Mrc<Export>>

Gets an export by its index

source

pub fn get_function( &mut self, func_idx: FuncIdx, ) -> Option<ImportOrFunc<Ast::Expr>>

Gets a function by its index

In a core WASM module the function index space holds both defined functions and imported functions.

source

pub fn get_global(&mut self, global_idx: GlobalIdx) -> Option<Mrc<Global>>

Gets a global by its index

source

pub fn get_memory(&mut self, mem_idx: MemIdx) -> Option<Mrc<Mem>>

Gets a memory by its index

source

pub fn get_table(&mut self, table_idx: TableIdx) -> Option<Mrc<Table>>

Gets a table by its index

source

pub fn type_idx_of(&self, func_type: &FuncType) -> Option<TypeIdx>

Checks whether a given function type is already defined in the module, and returs its type index if so.

source

pub fn into_sections(self) -> Vec<Mrc<CoreSection<Ast>>>

Converts the module into a sequence of sections

source

pub fn into_grouped(self) -> Vec<(CoreSectionType, Vec<Mrc<CoreSection<Ast>>>)>

Converts the module into a grouped sequence of sections, exactly as it should be written to a binary WASM file

source§

impl<Ast> Module<Ast>

source

pub fn get_metadata(&self) -> Option<Metadata>

Gets all the metadata supported by the wasm-metadata crate defined in this module’s custom sections

Trait Implementations§

source§

impl<Ast: AstCustomization> Clone for Module<Ast>

source§

fn clone(&self) -> Self

Returns a copy 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<Ast: AstCustomization> Debug for Module<Ast>

source§

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

Formats the value using the given formatter. Read more
source§

impl<Ast: AstCustomization> PartialEq for Module<Ast>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Ast: AstCustomization> Section<ComponentIndexSpace, ComponentSectionType> for Module<Ast>

source§

impl<Ast> TryFrom<(Parser, &[u8])> for Module<Ast>
where Ast: AstCustomization, Ast::Expr: TryFromExprSource, Ast::Data: From<Data<Ast::Expr>>, Ast::Custom: From<Custom>,

§

type Error = String

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

fn try_from(value: (Parser, &[u8])) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<Ast> TryFrom<Module<Ast>> for Module
where Ast: AstCustomization, Ast::Expr: RetainsInstructions, Ast::Data: Into<Data<Ast::Expr>>, Ast::Custom: Into<Custom>,

§

type Error = String

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

fn try_from(value: Module<Ast>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<Ast> !Freeze for Module<Ast>

§

impl<Ast> !RefUnwindSafe for Module<Ast>

§

impl<Ast> !Send for Module<Ast>

§

impl<Ast> !Sync for Module<Ast>

§

impl<Ast> Unpin for Module<Ast>

§

impl<Ast> !UnwindSafe for Module<Ast>

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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

§

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

§

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.