Add functions to ModuleEnvironment to support reserving buffers up front.
These default to doing nothing, but implementations can override them to preallocate buffers. Also, reorder the functions in `ModuleEnvironment` to more closely reflect the sequence from the WebAssembly module layout.
This commit is contained in:
@@ -245,9 +245,17 @@ pub trait ModuleEnvironment<'data> {
|
||||
/// Get the information needed to produce Cranelift IR for the current target.
|
||||
fn target_config(&self) -> TargetFrontendConfig;
|
||||
|
||||
/// Provides the number of signatures up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_signatures(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a function signature to the environment.
|
||||
fn declare_signature(&mut self, sig: &ir::Signature);
|
||||
|
||||
/// Provides the number of imports up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_imports(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a function import to the environment.
|
||||
fn declare_func_import(
|
||||
&mut self,
|
||||
@@ -256,20 +264,71 @@ pub trait ModuleEnvironment<'data> {
|
||||
field: &'data str,
|
||||
);
|
||||
|
||||
/// Declares the type (signature) of a local function in the module.
|
||||
fn declare_func_type(&mut self, sig_index: SignatureIndex);
|
||||
/// Declares a table import to the environment.
|
||||
fn declare_table_import(&mut self, table: Table, module: &'data str, field: &'data str);
|
||||
|
||||
/// Declares a global to the environment.
|
||||
fn declare_global(&mut self, global: Global);
|
||||
/// Declares a memory import to the environment.
|
||||
fn declare_memory_import(&mut self, memory: Memory, module: &'data str, field: &'data str);
|
||||
|
||||
/// Declares a global import to the environment.
|
||||
fn declare_global_import(&mut self, global: Global, module: &'data str, field: &'data str);
|
||||
|
||||
/// Notifies the implementation that all imports have been declared.
|
||||
fn finish_imports(&mut self) {}
|
||||
|
||||
/// Provides the number of defined functions up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_func_types(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares the type (signature) of a local function in the module.
|
||||
fn declare_func_type(&mut self, sig_index: SignatureIndex);
|
||||
|
||||
/// Provides the number of defined tables up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_tables(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a table to the environment.
|
||||
fn declare_table(&mut self, table: Table);
|
||||
|
||||
/// Declares a table import to the environment.
|
||||
fn declare_table_import(&mut self, table: Table, module: &'data str, field: &'data str);
|
||||
/// Provides the number of defined memories up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_memories(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a memory to the environment
|
||||
fn declare_memory(&mut self, memory: Memory);
|
||||
|
||||
/// Provides the number of defined globals up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_globals(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a global to the environment.
|
||||
fn declare_global(&mut self, global: Global);
|
||||
|
||||
/// Provides the number of exports up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_exports(&mut self, _num: u32) {}
|
||||
|
||||
/// Declares a function export to the environment.
|
||||
fn declare_func_export(&mut self, func_index: FuncIndex, name: &'data str);
|
||||
|
||||
/// Declares a table export to the environment.
|
||||
fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str);
|
||||
|
||||
/// Declares a memory export to the environment.
|
||||
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str);
|
||||
|
||||
/// Declares a global export to the environment.
|
||||
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str);
|
||||
|
||||
/// Notifies the implementation that all exports have been declared.
|
||||
fn finish_exports(&mut self) {}
|
||||
|
||||
/// Declares the optional start function.
|
||||
fn declare_start_func(&mut self, index: FuncIndex);
|
||||
|
||||
/// Provides the number of element initializers up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_table_elements(&mut self, _num: u32) {}
|
||||
|
||||
/// Fills a declared table with references to functions in the module.
|
||||
fn declare_table_elements(
|
||||
@@ -280,11 +339,12 @@ pub trait ModuleEnvironment<'data> {
|
||||
elements: Vec<FuncIndex>,
|
||||
);
|
||||
|
||||
/// Declares a memory to the environment
|
||||
fn declare_memory(&mut self, memory: Memory);
|
||||
/// Provides the contents of a function body.
|
||||
fn define_function_body(&mut self, body_bytes: &'data [u8]) -> WasmResult<()>;
|
||||
|
||||
/// Declares a memory import to the environment.
|
||||
fn declare_memory_import(&mut self, memory: Memory, module: &'data str, field: &'data str);
|
||||
/// Provides the number of data initializers up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_data_initializers(&mut self, _num: u32) {}
|
||||
|
||||
/// Fills a declared memory with bytes at module instantiation.
|
||||
fn declare_data_initialization(
|
||||
@@ -294,19 +354,4 @@ pub trait ModuleEnvironment<'data> {
|
||||
offset: usize,
|
||||
data: &'data [u8],
|
||||
);
|
||||
|
||||
/// Declares a function export to the environment.
|
||||
fn declare_func_export(&mut self, func_index: FuncIndex, name: &'data str);
|
||||
/// Declares a table export to the environment.
|
||||
fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str);
|
||||
/// Declares a memory export to the environment.
|
||||
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str);
|
||||
/// Declares a global export to the environment.
|
||||
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str);
|
||||
|
||||
/// Declares a start function.
|
||||
fn declare_start_func(&mut self, index: FuncIndex);
|
||||
|
||||
/// Provides the contents of a function body.
|
||||
fn define_function_body(&mut self, body_bytes: &'data [u8]) -> WasmResult<()>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user