pub struct Module {Show 16 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 tags: ModuleTags,
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: ModuleMemoriesTags for exception handling
data: ModuleDataRegistration of passive data segments, if any
elements: ModuleElementsRegistration of passive element segments, if any
start: Option<FunctionId>The start function, if any
producers: ModuleProducersRepresentation of the eventual custom section, producers
customs: ModuleCustomSectionsCustom sections found in this module.
debug: ModuleDebugDataDwarf 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,
memory64: bool,
initial: u64,
maximum: Option<u64>,
page_size_log2: Option<u32>,
) -> (MemoryId, ImportId)
pub fn add_import_memory( &mut self, module: &str, name: &str, shared: bool, memory64: bool, initial: u64, maximum: Option<u64>, page_size_log2: Option<u32>, ) -> (MemoryId, ImportId)
Add an imported memory to this module
Sourcepub fn add_import_table(
&mut self,
module: &str,
name: &str,
table64: bool,
initial: u64,
maximum: Option<u64>,
ty: RefType,
) -> (TableId, ImportId)
pub fn add_import_table( &mut self, module: &str, name: &str, table64: bool, initial: u64, maximum: Option<u64>, ty: RefType, ) -> (TableId, ImportId)
Add an imported table 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>
pub fn from_file<P>(path: P) -> Result<Module>
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>
pub fn from_file_with_config<P>( path: P, config: &ModuleConfig, ) -> Result<Module>
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.
Sourcepub fn from_buffer_with_config(
wasm: &[u8],
config: &ModuleConfig,
) -> Result<Module>
pub fn from_buffer_with_config( wasm: &[u8], config: &ModuleConfig, ) -> Result<Module>
Construct a new module from the in-memory wasm buffer and configuration.
Sourcepub fn emit_wasm_file<P>(&mut self, path: P) -> Result<()>
pub fn emit_wasm_file<P>(&mut self, path: P) -> Result<()>
Emit this module into a .wasm file at the given path.