pub struct Module {Show 15 fields
pub imports: ModuleImports,
pub tables: ModuleTables,
pub types: ModuleTypes,
pub funcs: ModuleFunctions,
pub globals: ModuleGlobals,
pub locals: ModuleLocals,
pub exports: ModuleExports,
pub memories: ModuleMemories,
pub data: ModuleData,
pub elements: ModuleElements,
pub start: Option<FunctionId>,
pub producers: ModuleProducers,
pub customs: ModuleCustomSections,
pub debug: ModuleDebugData,
pub name: Option<String>,
/* private fields */
}
Expand description
A wasm module.
Fields§
§imports: ModuleImports
§tables: ModuleTables
§types: ModuleTypes
§funcs: ModuleFunctions
§globals: ModuleGlobals
§locals: ModuleLocals
§exports: ModuleExports
§memories: ModuleMemories
§data: ModuleData
Registration of passive data segments, if any
elements: ModuleElements
Registration of passive element segments, if any
start: Option<FunctionId>
The start
function, if any
producers: ModuleProducers
Representation of the eventual custom section, producers
customs: ModuleCustomSections
Custom sections found in this module.
debug: ModuleDebugData
Dwarf debug data.
name: Option<String>
The name of this module, used for debugging purposes in the name
custom section.
Implementations§
source§impl Module
impl Module
sourcepub fn write_graphviz_dot(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write_graphviz_dot(&self, path: impl AsRef<Path>) -> Result<()>
Generate a GraphViz Dot file for this module, showing the relationship between various structures in the module and its instructions.
Example
First, generate a .dot
file with this method:
let my_module: walrus::Module = get_module_from_somewhere();
my_module.write_graphviz_dot("my_module.dot")?;
Second, use the dot
command-line tool to render an SVG (or PNG,
etc…):
dot my_module.dot \ # Provide our generated `.dot`.
-T svg \ # Generate an SVG image.
-o my_module.svg # Write to this output file.
source§impl Module
impl Module
sourcepub fn get_memory_id(&self) -> Result<MemoryId>
pub fn get_memory_id(&self) -> Result<MemoryId>
Retrieve the ID for the first exported memory.
This method does not work in contexts with multi-memory enabled, and will error if more than one memory is present.
sourcepub fn replace_exported_func(
&mut self,
fid: FunctionId,
builder_fn: impl FnOnce((&mut InstrSeqBuilder<'_>, &Vec<LocalId>))
) -> Result<FunctionId>
pub fn replace_exported_func( &mut self, fid: FunctionId, builder_fn: impl FnOnce((&mut InstrSeqBuilder<'_>, &Vec<LocalId>)) ) -> Result<FunctionId>
Replace a single exported function with the result of the provided builder function.
The builder function is provided a mutable reference to an InstrSeqBuilder
which can be
used to build the function as necessary.
For example, if you wanted to replace an exported function with a no-op,
module.replace_exported_func(fid, |(body, arg_locals)| {
builder.func_body().unreachable();
});
The arguments passed to the original function will be passed to the new exported function that was built in your closure.
This function returns the function ID of the new function, after it has been inserted into the module as an export.
sourcepub fn replace_imported_func(
&mut self,
fid: FunctionId,
builder_fn: impl FnOnce((&mut InstrSeqBuilder<'_>, &Vec<LocalId>))
) -> Result<FunctionId>
pub fn replace_imported_func( &mut self, fid: FunctionId, builder_fn: impl FnOnce((&mut InstrSeqBuilder<'_>, &Vec<LocalId>)) ) -> Result<FunctionId>
Replace a single imported function with the result of the provided builder function.
The builder function is provided a mutable reference to an InstrSeqBuilder
which can be
used to build the function as necessary.
For example, if you wanted to replace an imported function with a no-op,
module.replace_imported_func(fid, |(body, arg_locals)| {
builder.func_body().unreachable();
});
The arguments passed to the original function will be passed to the new exported function that was built in your closure.
This function returns the function ID of the new function, and removes the existing import that has been replaced (the function will become local).
source§impl Module
impl Module
sourcepub fn add_import_func(
&mut self,
module: &str,
name: &str,
ty: TypeId
) -> (FunctionId, ImportId)
pub fn add_import_func( &mut self, module: &str, name: &str, ty: TypeId ) -> (FunctionId, ImportId)
Add an imported function to this module
sourcepub fn add_import_memory(
&mut self,
module: &str,
name: &str,
shared: bool,
initial: u32,
maximum: Option<u32>
) -> (MemoryId, ImportId)
pub fn add_import_memory( &mut self, module: &str, name: &str, shared: bool, initial: u32, maximum: Option<u32> ) -> (MemoryId, ImportId)
Add an imported memory to this module
source§impl Module
impl Module
sourcepub fn with_config(config: ModuleConfig) -> Self
pub fn with_config(config: ModuleConfig) -> Self
Create a default, empty module that uses the given configuration.
sourcepub fn from_file<P>(path: P) -> Result<Module>where
P: AsRef<Path>,
pub fn from_file<P>(path: P) -> Result<Module>where P: AsRef<Path>,
Construct a new module from the given path with the default configuration.
sourcepub fn from_file_with_config<P>(
path: P,
config: &ModuleConfig
) -> Result<Module>where
P: AsRef<Path>,
pub fn from_file_with_config<P>( path: P, config: &ModuleConfig ) -> Result<Module>where P: AsRef<Path>,
Construct a new module from the given path and configuration.
sourcepub fn from_buffer(wasm: &[u8]) -> Result<Module>
pub fn from_buffer(wasm: &[u8]) -> Result<Module>
Construct a new module from the in-memory wasm buffer with the default configuration.