Improved imports (#612)
* Impoved support for wasm global imports * Refactored parse_import_section improving readability * Improved support for wasm table imports * Improved support for wasm memory imports * Improved formatting * Added DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex structs
This commit is contained in:
@@ -52,6 +52,15 @@ pub struct DummyModuleInfo {
|
||||
/// Module and field names of imported functions as provided by `declare_func_import`.
|
||||
pub imported_funcs: Vec<(String, String)>,
|
||||
|
||||
/// Module and field names of imported globals as provided by `declare_global_import`.
|
||||
pub imported_globals: Vec<(String, String)>,
|
||||
|
||||
/// Module and field names of imported tables as provided by `declare_table_import`.
|
||||
pub imported_tables: Vec<(String, String)>,
|
||||
|
||||
/// Module and field names of imported memories as provided by `declare_memory_import`.
|
||||
pub imported_memories: Vec<(String, String)>,
|
||||
|
||||
/// Functions, imported and local.
|
||||
pub functions: PrimaryMap<FuncIndex, Exportable<SignatureIndex>>,
|
||||
|
||||
@@ -78,6 +87,9 @@ impl DummyModuleInfo {
|
||||
config,
|
||||
signatures: PrimaryMap::new(),
|
||||
imported_funcs: Vec::new(),
|
||||
imported_globals: Vec::new(),
|
||||
imported_tables: Vec::new(),
|
||||
imported_memories: Vec::new(),
|
||||
functions: PrimaryMap::new(),
|
||||
function_bodies: PrimaryMap::new(),
|
||||
tables: PrimaryMap::new(),
|
||||
@@ -375,6 +387,13 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
||||
self.info.globals.push(Exportable::new(global));
|
||||
}
|
||||
|
||||
fn declare_global_import(&mut self, global: Global, module: &'data str, field: &'data str) {
|
||||
self.info.globals.push(Exportable::new(global));
|
||||
self.info
|
||||
.imported_globals
|
||||
.push((String::from(module), String::from(field)));
|
||||
}
|
||||
|
||||
fn get_global(&self, global_index: GlobalIndex) -> &Global {
|
||||
&self.info.globals[global_index].entity
|
||||
}
|
||||
@@ -382,6 +401,14 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
||||
fn declare_table(&mut self, table: Table) {
|
||||
self.info.tables.push(Exportable::new(table));
|
||||
}
|
||||
|
||||
fn declare_table_import(&mut self, table: Table, module: &'data str, field: &'data str) {
|
||||
self.info.tables.push(Exportable::new(table));
|
||||
self.info
|
||||
.imported_tables
|
||||
.push((String::from(module), String::from(field)));
|
||||
}
|
||||
|
||||
fn declare_table_elements(
|
||||
&mut self,
|
||||
_table_index: TableIndex,
|
||||
@@ -391,9 +418,18 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
||||
) {
|
||||
// We do nothing
|
||||
}
|
||||
|
||||
fn declare_memory(&mut self, memory: Memory) {
|
||||
self.info.memories.push(Exportable::new(memory));
|
||||
}
|
||||
|
||||
fn declare_memory_import(&mut self, memory: Memory, module: &'data str, field: &'data str) {
|
||||
self.info.memories.push(Exportable::new(memory));
|
||||
self.info
|
||||
.imported_memories
|
||||
.push((String::from(module), String::from(field)));
|
||||
}
|
||||
|
||||
fn declare_data_initialization(
|
||||
&mut self,
|
||||
_memory_index: MemoryIndex,
|
||||
|
||||
Reference in New Issue
Block a user