Struct parity_wasm::builder::ModuleBuilder
source · pub struct ModuleBuilder<F = Identity> { /* private fields */ }
Expand description
Module builder
Implementations
sourceimpl ModuleBuilder
impl ModuleBuilder
sourceimpl<F> ModuleBuilder<F>where
F: Invoke<Module>,
impl<F> ModuleBuilder<F>where
F: Invoke<Module>,
sourcepub fn with_callback(callback: F) -> Self
pub fn with_callback(callback: F) -> Self
New module builder with bound callback
sourcepub fn with_module(self, module: Module) -> Self
pub fn with_module(self, module: Module) -> Self
Builder from raw module
sourcepub fn with_sections<I>(self, sections: I) -> Selfwhere
I: IntoIterator<Item = Section>,
pub fn with_sections<I>(self, sections: I) -> Selfwhere
I: IntoIterator<Item = Section>,
Fill module with sections from iterator
sourcepub fn with_section(self, section: Section) -> Self
pub fn with_section(self, section: Section) -> Self
Add additional section
sourcepub fn with_signatures(self, bindings: Vec<Signature>) -> Self
pub fn with_signatures(self, bindings: Vec<Signature>) -> Self
Binds to the type section, creates additional types when required
sourcepub fn push_function(&mut self, func: FunctionDefinition) -> CodeLocation
pub fn push_function(&mut self, func: FunctionDefinition) -> CodeLocation
Push stand-alone function definition, creating sections, signature and code blocks
in corresponding sections.
FunctionDefinition
can be build using builder::function
builder
sourcepub fn push_memory(&mut self, memory: MemoryDefinition) -> u32
pub fn push_memory(&mut self, memory: MemoryDefinition) -> u32
Push linear memory region
sourcepub fn push_table(&mut self, table: TableDefinition) -> u32
pub fn push_table(&mut self, table: TableDefinition) -> u32
Push table
sourcepub fn push_signature(&mut self, signature: Signature) -> u32
pub fn push_signature(&mut self, signature: Signature) -> u32
Push one function signature, returning it’s calling index. Can create corresponding type in type section.
sourcepub fn push_signatures(&mut self, signatures: Vec<Signature>) -> Vec<u32>
pub fn push_signatures(&mut self, signatures: Vec<Signature>) -> Vec<u32>
Push signatures in the module, returning corresponding indices of pushed signatures
sourcepub fn push_import(&mut self, import: ImportEntry) -> u32
pub fn push_import(&mut self, import: ImportEntry) -> u32
Push import entry to module. Note that this does not update calling indices in function bodies.
sourcepub fn push_export(&mut self, export: ExportEntry) -> u32
pub fn push_export(&mut self, export: ExportEntry) -> u32
Push export entry to module.
sourcepub fn function(self) -> FunctionBuilder<Self>
pub fn function(self) -> FunctionBuilder<Self>
Add new function using dedicated builder
sourcepub fn memory(self) -> MemoryBuilder<Self>
pub fn memory(self) -> MemoryBuilder<Self>
Add new linear memory using dedicated builder
sourcepub fn table(self) -> TableBuilder<Self>
pub fn table(self) -> TableBuilder<Self>
Add new table using dedicated builder
sourcepub fn functions(self) -> SignaturesBuilder<Self>
pub fn functions(self) -> SignaturesBuilder<Self>
Define functions section
sourcepub fn with_export(self, entry: ExportEntry) -> Self
pub fn with_export(self, entry: ExportEntry) -> Self
With inserted export entry
sourcepub fn with_import(self, entry: ImportEntry) -> Self
pub fn with_import(self, entry: ImportEntry) -> Self
With inserted import entry
sourcepub fn import(self) -> ImportBuilder<Self>
pub fn import(self) -> ImportBuilder<Self>
Import entry builder
Examples
use parity_wasm::builder::module;
let module = module()
.import()
.module("env")
.field("memory")
.external().memory(256, Some(256))
.build()
.build();
assert_eq!(module.import_section().expect("import section to exist").entries().len(), 1);
sourcepub fn with_global(self, global: GlobalEntry) -> Self
pub fn with_global(self, global: GlobalEntry) -> Self
With global variable
sourcepub fn with_table(self, table: TableType) -> Self
pub fn with_table(self, table: TableType) -> Self
With table
sourcepub fn export(self) -> ExportBuilder<Self>
pub fn export(self) -> ExportBuilder<Self>
Export entry builder
Examples
use parity_wasm::builder::module;
use parity_wasm::elements::Instruction::*;
let module = module()
.global()
.value_type().i32()
.init_expr(I32Const(0))
.build()
.export()
.field("_zero")
.internal().global(0)
.build()
.build();
assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1);
sourcepub fn global(self) -> GlobalBuilder<Self>
pub fn global(self) -> GlobalBuilder<Self>
Glboal entry builder
Examples
use parity_wasm::builder::module;
use parity_wasm::elements::Instruction::*;
let module = module()
.global()
.value_type().i32()
.init_expr(I32Const(0))
.build()
.build();
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
sourcepub fn with_data_segment(self, segment: DataSegment) -> Self
pub fn with_data_segment(self, segment: DataSegment) -> Self
Add data segment to the builder
sourcepub fn data(self) -> DataSegmentBuilder<Self>
pub fn data(self) -> DataSegmentBuilder<Self>
Data entry builder