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>,
impl<Ast> Module<Ast>where
Ast: AstCustomization + 'static,
Ast::Expr: TryFromExprSource,
Ast::Data: From<Data<Ast::Expr>>,
Ast::Custom: From<Custom>,
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, String>
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>,
impl<Ast> Module<Ast>where
Ast: AstCustomization + 'static,
Ast::Expr: RetainsInstructions,
Ast::Data: Into<Data<Ast::Expr>>,
Ast::Custom: Into<Custom>,
source§impl<Ast: AstCustomization> Module<Ast>
impl<Ast: AstCustomization> Module<Ast>
sourcepub fn func_type_refs(&self) -> Vec<Mrc<FuncTypeRef>>
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.
sourcepub fn codes(&self) -> Vec<Mrc<FuncCode<Ast::Expr>>>
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.
sourcepub fn add_export(&mut self, export: Export)
pub fn add_export(&mut self, export: Export)
Adds a new export
sourcepub fn add_function(
&mut self,
func_type: FuncType,
locals: Vec<ValType>,
body: Ast::Expr,
) -> FuncIdx
pub fn add_function( &mut self, func_type: FuncType, locals: Vec<ValType>, body: Ast::Expr, ) -> FuncIdx
Adds a new function
sourcepub fn add_global(&mut self, global: Global)
pub fn add_global(&mut self, global: Global)
Adds a new global
sourcepub fn add_memory(&mut self, mem: Mem)
pub fn add_memory(&mut self, mem: Mem)
Adds a new memory
sourcepub fn get_code(
&mut self,
func_idx: FuncIdx,
) -> Option<Mrc<FuncCode<Ast::Expr>>>
pub fn get_code( &mut self, func_idx: FuncIdx, ) -> Option<Mrc<FuncCode<Ast::Expr>>>
Gets a function body by its index
sourcepub fn get_data(&mut self, data_idx: DataIdx) -> Option<Mrc<Ast::Data>>
pub fn get_data(&mut self, data_idx: DataIdx) -> Option<Mrc<Ast::Data>>
Gets a data section by its index
sourcepub fn get_elem(&mut self, elem_idx: ElemIdx) -> Option<Mrc<Elem<Ast::Expr>>>
pub fn get_elem(&mut self, elem_idx: ElemIdx) -> Option<Mrc<Elem<Ast::Expr>>>
Gets an elem by its index
sourcepub fn get_export(&mut self, export_idx: ExportIdx) -> Option<Mrc<Export>>
pub fn get_export(&mut self, export_idx: ExportIdx) -> Option<Mrc<Export>>
Gets an export by its index
sourcepub fn get_function(
&mut self,
func_idx: FuncIdx,
) -> Option<ImportOrFunc<Ast::Expr>>
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.
sourcepub fn get_global(&mut self, global_idx: GlobalIdx) -> Option<Mrc<Global>>
pub fn get_global(&mut self, global_idx: GlobalIdx) -> Option<Mrc<Global>>
Gets a global by its index
sourcepub fn get_table(&mut self, table_idx: TableIdx) -> Option<Mrc<Table>>
pub fn get_table(&mut self, table_idx: TableIdx) -> Option<Mrc<Table>>
Gets a table by its index
sourcepub fn type_idx_of(&self, func_type: &FuncType) -> Option<TypeIdx>
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.
sourcepub fn into_sections(self) -> Vec<Mrc<CoreSection<Ast>>>
pub fn into_sections(self) -> Vec<Mrc<CoreSection<Ast>>>
Converts the module into a sequence of sections
sourcepub fn into_grouped(self) -> Vec<(CoreSectionType, Vec<Mrc<CoreSection<Ast>>>)>
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