Struct wasmtime_environ::ModuleEnvironment
source · [−]pub struct ModuleEnvironment<'data> { /* private fields */ }
Expand description
Object containing the standalone environment information.
Implementations
sourceimpl<'data> ModuleEnvironment<'data>
impl<'data> ModuleEnvironment<'data>
sourcepub fn new(
target_config: TargetFrontendConfig,
tunables: &Tunables,
features: &WasmFeatures
) -> Self
pub fn new(
target_config: TargetFrontendConfig,
tunables: &Tunables,
features: &WasmFeatures
) -> Self
Allocates the environment data structures.
sourcepub fn translate(
self,
data: &'data [u8]
) -> WasmResult<(Vec<ModuleTranslation<'data>>, TypeTables)>
pub fn translate(
self,
data: &'data [u8]
) -> WasmResult<(Vec<ModuleTranslation<'data>>, TypeTables)>
Translate a wasm module using this environment.
This consumes the ModuleEnvironment
and produces a list of
ModuleTranslation
s as well as a TypeTables
. The list of module
translations corresponds to all wasm modules found in the input data
.
Note that for MVP modules this will always be a list with one element,
but with the module linking proposal this may have many elements.
For the module linking proposal the top-level module is at index 0.
The TypeTables
structure returned contains intern’d versions of types
referenced from each module translation. This primarily serves as the
source of truth for module-linking use cases where modules can refer to
other module’s types. All SignatureIndex
, ModuleTypeIndex
, and
InstanceTypeIndex
values are resolved through the returned tables.
Trait Implementations
sourceimpl<'data> ModuleEnvironment<'data> for ModuleEnvironment<'data>
impl<'data> ModuleEnvironment<'data> for ModuleEnvironment<'data>
This trait is useful for translate_module
because it tells how to translate
environment-dependent wasm instructions. These functions should not be called by the user.
sourcefn reserve_types(&mut self, num: u32) -> WasmResult<()>
fn reserve_types(&mut self, num: u32) -> WasmResult<()>
Provides the number of types up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_type_func(
&mut self,
wasm: WasmFuncType,
sig: Signature
) -> WasmResult<()>
fn declare_type_func(
&mut self,
wasm: WasmFuncType,
sig: Signature
) -> WasmResult<()>
Declares a function signature to the environment.
sourcefn declare_type_module(
&mut self,
imports: &[(&'data str, Option<&'data str>, EntityType)],
exports: &[(&'data str, EntityType)]
) -> WasmResult<()>
fn declare_type_module(
&mut self,
imports: &[(&'data str, Option<&'data str>, EntityType)],
exports: &[(&'data str, EntityType)]
) -> WasmResult<()>
Declares a module type signature to the environment.
sourcefn declare_type_instance(
&mut self,
exports: &[(&'data str, EntityType)]
) -> WasmResult<()>
fn declare_type_instance(
&mut self,
exports: &[(&'data str, EntityType)]
) -> WasmResult<()>
Declares an instance type signature to the environment.
sourcefn type_to_signature(&self, index: TypeIndex) -> WasmResult<SignatureIndex>
fn type_to_signature(&self, index: TypeIndex) -> WasmResult<SignatureIndex>
Translates a type index to its signature index, only called for type indices which point to functions. Read more
sourcefn type_to_module_type(&self, index: TypeIndex) -> WasmResult<ModuleTypeIndex>
fn type_to_module_type(&self, index: TypeIndex) -> WasmResult<ModuleTypeIndex>
Translates a type index to its module type index, only called for type indices which point to modules. Read more
sourcefn type_to_instance_type(
&self,
index: TypeIndex
) -> WasmResult<InstanceTypeIndex>
fn type_to_instance_type(
&self,
index: TypeIndex
) -> WasmResult<InstanceTypeIndex>
Translates a type index to its instance type index, only called for type indices which point to instances. Read more
sourcefn reserve_imports(&mut self, num: u32) -> WasmResult<()>
fn reserve_imports(&mut self, num: u32) -> WasmResult<()>
Provides the number of imports up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_func_import(
&mut self,
index: TypeIndex,
module: &str,
field: Option<&str>
) -> WasmResult<()>
fn declare_func_import(
&mut self,
index: TypeIndex,
module: &str,
field: Option<&str>
) -> WasmResult<()>
Declares a function import to the environment.
sourcefn declare_table_import(
&mut self,
table: Table,
module: &str,
field: Option<&str>
) -> WasmResult<()>
fn declare_table_import(
&mut self,
table: Table,
module: &str,
field: Option<&str>
) -> WasmResult<()>
Declares a table import to the environment.
sourcefn declare_memory_import(
&mut self,
memory: Memory,
module: &str,
field: Option<&str>
) -> WasmResult<()>
fn declare_memory_import(
&mut self,
memory: Memory,
module: &str,
field: Option<&str>
) -> WasmResult<()>
Declares a memory import to the environment.
sourcefn declare_global_import(
&mut self,
global: Global,
module: &str,
field: Option<&str>
) -> WasmResult<()>
fn declare_global_import(
&mut self,
global: Global,
module: &str,
field: Option<&str>
) -> WasmResult<()>
Declares a global import to the environment.
sourcefn declare_module_import(
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: Option<&'data str>
) -> WasmResult<()>
fn declare_module_import(
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: Option<&'data str>
) -> WasmResult<()>
Declares a module import to the environment.
sourcefn declare_instance_import(
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: Option<&'data str>
) -> WasmResult<()>
fn declare_instance_import(
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: Option<&'data str>
) -> WasmResult<()>
Declares an instance import to the environment.
sourcefn reserve_func_types(&mut self, num: u32) -> WasmResult<()>
fn reserve_func_types(&mut self, num: u32) -> WasmResult<()>
Provides the number of defined functions up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_func_type(&mut self, index: TypeIndex) -> WasmResult<()>
fn declare_func_type(&mut self, index: TypeIndex) -> WasmResult<()>
Declares the type (signature) of a local function in the module.
sourcefn reserve_tables(&mut self, num: u32) -> WasmResult<()>
fn reserve_tables(&mut self, num: u32) -> WasmResult<()>
Provides the number of defined tables up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_table(&mut self, table: Table) -> WasmResult<()>
fn declare_table(&mut self, table: Table) -> WasmResult<()>
Declares a table to the environment.
sourcefn reserve_memories(&mut self, num: u32) -> WasmResult<()>
fn reserve_memories(&mut self, num: u32) -> WasmResult<()>
Provides the number of defined memories up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_memory(&mut self, memory: Memory) -> WasmResult<()>
fn declare_memory(&mut self, memory: Memory) -> WasmResult<()>
Declares a memory to the environment
sourcefn reserve_globals(&mut self, num: u32) -> WasmResult<()>
fn reserve_globals(&mut self, num: u32) -> WasmResult<()>
Provides the number of defined globals up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_global(&mut self, global: Global) -> WasmResult<()>
fn declare_global(&mut self, global: Global) -> WasmResult<()>
Declares a global to the environment.
sourcefn reserve_exports(&mut self, num: u32) -> WasmResult<()>
fn reserve_exports(&mut self, num: u32) -> WasmResult<()>
Provides the number of exports up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_func_export(
&mut self,
func_index: FuncIndex,
name: &str
) -> WasmResult<()>
fn declare_func_export(
&mut self,
func_index: FuncIndex,
name: &str
) -> WasmResult<()>
Declares a function export to the environment.
sourcefn declare_table_export(
&mut self,
table_index: TableIndex,
name: &str
) -> WasmResult<()>
fn declare_table_export(
&mut self,
table_index: TableIndex,
name: &str
) -> WasmResult<()>
Declares a table export to the environment.
sourcefn declare_memory_export(
&mut self,
memory_index: MemoryIndex,
name: &str
) -> WasmResult<()>
fn declare_memory_export(
&mut self,
memory_index: MemoryIndex,
name: &str
) -> WasmResult<()>
Declares a memory export to the environment.
sourcefn declare_global_export(
&mut self,
global_index: GlobalIndex,
name: &str
) -> WasmResult<()>
fn declare_global_export(
&mut self,
global_index: GlobalIndex,
name: &str
) -> WasmResult<()>
Declares a global export to the environment.
sourcefn declare_module_export(
&mut self,
index: ModuleIndex,
name: &str
) -> WasmResult<()>
fn declare_module_export(
&mut self,
index: ModuleIndex,
name: &str
) -> WasmResult<()>
Declares an instance export to the environment.
sourcefn declare_instance_export(
&mut self,
index: InstanceIndex,
name: &str
) -> WasmResult<()>
fn declare_instance_export(
&mut self,
index: InstanceIndex,
name: &str
) -> WasmResult<()>
Declares an instance export to the environment.
sourcefn declare_start_func(&mut self, func_index: FuncIndex) -> WasmResult<()>
fn declare_start_func(&mut self, func_index: FuncIndex) -> WasmResult<()>
Declares the optional start function.
sourcefn reserve_table_elements(&mut self, num: u32) -> WasmResult<()>
fn reserve_table_elements(&mut self, num: u32) -> WasmResult<()>
Provides the number of element initializers up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_table_elements(
&mut self,
table_index: TableIndex,
base: Option<GlobalIndex>,
offset: usize,
elements: Box<[FuncIndex]>
) -> WasmResult<()>
fn declare_table_elements(
&mut self,
table_index: TableIndex,
base: Option<GlobalIndex>,
offset: usize,
elements: Box<[FuncIndex]>
) -> WasmResult<()>
Fills a declared table with references to functions in the module.
sourcefn declare_passive_element(
&mut self,
elem_index: ElemIndex,
segments: Box<[FuncIndex]>
) -> WasmResult<()>
fn declare_passive_element(
&mut self,
elem_index: ElemIndex,
segments: Box<[FuncIndex]>
) -> WasmResult<()>
Declare a passive element segment.
sourcefn reserve_function_bodies(&mut self, _count: u32, offset: u64)
fn reserve_function_bodies(&mut self, _count: u32, offset: u64)
Indicates how many functions the code section reports and the byte offset of where the code sections starts. Read more
sourcefn define_function_body(
&mut self,
validator: FuncValidator<ValidatorResources>,
body: FunctionBody<'data>
) -> WasmResult<()>
fn define_function_body(
&mut self,
validator: FuncValidator<ValidatorResources>,
body: FunctionBody<'data>
) -> WasmResult<()>
Provides the contents of a function body.
sourcefn reserve_data_initializers(&mut self, num: u32) -> WasmResult<()>
fn reserve_data_initializers(&mut self, num: u32) -> WasmResult<()>
Provides the number of data initializers up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_data_initialization(
&mut self,
memory_index: MemoryIndex,
base: Option<GlobalIndex>,
offset: usize,
data: &'data [u8]
) -> WasmResult<()>
fn declare_data_initialization(
&mut self,
memory_index: MemoryIndex,
base: Option<GlobalIndex>,
offset: usize,
data: &'data [u8]
) -> WasmResult<()>
Fills a declared memory with bytes at module instantiation.
sourcefn reserve_passive_data(&mut self, count: u32) -> WasmResult<()>
fn reserve_passive_data(&mut self, count: u32) -> WasmResult<()>
Provides the number of passive data segments up front. Read more
sourcefn declare_passive_data(
&mut self,
data_index: DataIndex,
data: &'data [u8]
) -> WasmResult<()>
fn declare_passive_data(
&mut self,
data_index: DataIndex,
data: &'data [u8]
) -> WasmResult<()>
Declare a passive data segment.
sourcefn declare_module_name(&mut self, name: &'data str)
fn declare_module_name(&mut self, name: &'data str)
Declares the name of a module to the environment. Read more
sourcefn declare_func_name(&mut self, func_index: FuncIndex, name: &'data str)
fn declare_func_name(&mut self, func_index: FuncIndex, name: &'data str)
Declares the name of a function to the environment. Read more
sourcefn declare_local_name(
&mut self,
func_index: FuncIndex,
local: u32,
name: &'data str
)
fn declare_local_name(
&mut self,
func_index: FuncIndex,
local: u32,
name: &'data str
)
Declares the name of a function’s local to the environment. Read more
sourcefn custom_section(
&mut self,
name: &'data str,
data: &'data [u8]
) -> WasmResult<()>
fn custom_section(
&mut self,
name: &'data str,
data: &'data [u8]
) -> WasmResult<()>
Indicates that a custom section has been found in the wasm file
sourcefn wasm_features(&self) -> WasmFeatures
fn wasm_features(&self) -> WasmFeatures
Returns the list of enabled wasm features this translation will be using.
sourcefn reserve_modules(&mut self, amount: u32)
fn reserve_modules(&mut self, amount: u32)
Indicates that this module will have amount
submodules. Read more
sourcefn declare_module(&mut self, ty: TypeIndex) -> WasmResult<()>
fn declare_module(&mut self, ty: TypeIndex) -> WasmResult<()>
Declares that a module will come later with the type signature provided.
sourcefn module_start(&mut self, index: usize)
fn module_start(&mut self, index: usize)
Called at the beginning of translating a module. Read more
sourcefn module_end(&mut self, index: usize)
fn module_end(&mut self, index: usize)
Called at the end of translating a module. Read more
sourcefn reserve_instances(&mut self, amt: u32)
fn reserve_instances(&mut self, amt: u32)
Indicates that this module will have amount
instances.
sourcefn declare_instance(
&mut self,
module: ModuleIndex,
args: Vec<EntityIndex>
) -> WasmResult<()>
fn declare_instance(
&mut self,
module: ModuleIndex,
args: Vec<EntityIndex>
) -> WasmResult<()>
Declares a new instance which this module will instantiate before it’s instantiated. Read more
sourcefn declare_alias(&mut self, alias: Alias) -> WasmResult<()>
fn declare_alias(&mut self, alias: Alias) -> WasmResult<()>
Declares a new alias being added to this module. Read more
sourcefn declare_event_import(
&mut self,
event: Event,
module: &'data str,
field: Option<&'data str>
) -> Result<(), WasmError>
fn declare_event_import(
&mut self,
event: Event,
module: &'data str,
field: Option<&'data str>
) -> Result<(), WasmError>
Declares an event import to the environment.
sourcefn finish_imports(&mut self) -> Result<(), WasmError>
fn finish_imports(&mut self) -> Result<(), WasmError>
Notifies the implementation that all imports have been declared.
sourcefn reserve_events(&mut self, _num: u32) -> Result<(), WasmError>
fn reserve_events(&mut self, _num: u32) -> Result<(), WasmError>
Provides the number of defined events up front. By default this does nothing, but implementations can use this to preallocate memory if desired. Read more
sourcefn declare_event(&mut self, event: Event) -> Result<(), WasmError>
fn declare_event(&mut self, event: Event) -> Result<(), WasmError>
Declares an event to the environment
sourcefn declare_event_export(
&mut self,
event_index: EventIndex,
name: &'data str
) -> Result<(), WasmError>
fn declare_event_export(
&mut self,
event_index: EventIndex,
name: &'data str
) -> Result<(), WasmError>
Declares an event export to the environment.
sourcefn finish_exports(&mut self) -> Result<(), WasmError>
fn finish_exports(&mut self) -> Result<(), WasmError>
Notifies the implementation that all exports have been declared.
sourceimpl<'data> TargetEnvironment for ModuleEnvironment<'data>
impl<'data> TargetEnvironment for ModuleEnvironment<'data>
sourcefn target_config(&self) -> TargetFrontendConfig
fn target_config(&self) -> TargetFrontendConfig
Get the information needed to produce Cranelift IR for the given target.
sourcefn reference_type(&self, ty: WasmType) -> Type
fn reference_type(&self, ty: WasmType) -> Type
Get the Cranelift reference type to use for the given Wasm reference type. Read more
sourcefn pointer_type(&self) -> Type
fn pointer_type(&self) -> Type
Get the Cranelift integer type to use for native pointers. Read more
sourcefn pointer_bytes(&self) -> u8
fn pointer_bytes(&self) -> u8
Get the size of a native pointer, in bytes.
Auto Trait Implementations
impl<'data> RefUnwindSafe for ModuleEnvironment<'data>
impl<'data> Send for ModuleEnvironment<'data>
impl<'data> Sync for ModuleEnvironment<'data>
impl<'data> Unpin for ModuleEnvironment<'data>
impl<'data> UnwindSafe for ModuleEnvironment<'data>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more