Remove the local field of Module (#2091)
This was added long ago at this point to assist with caching, but caching has moved to a different level such that this wonky second level of a `Module` isn't necessary. This commit removes the `ModuleLocal` type to simplify accessors and generally make it easier to work with.
This commit is contained in:
@@ -302,17 +302,17 @@ impl Compiler for Cranelift {
|
|||||||
input: &FunctionBodyData<'_>,
|
input: &FunctionBodyData<'_>,
|
||||||
isa: &dyn isa::TargetIsa,
|
isa: &dyn isa::TargetIsa,
|
||||||
) -> Result<CompiledFunction, CompileError> {
|
) -> Result<CompiledFunction, CompileError> {
|
||||||
let local = &translation.module.local;
|
let module = &translation.module;
|
||||||
let tunables = &translation.tunables;
|
let tunables = &translation.tunables;
|
||||||
let func_index = local.func_index(func_index);
|
let func_index = module.func_index(func_index);
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.func.name = get_func_name(func_index);
|
context.func.name = get_func_name(func_index);
|
||||||
context.func.signature = local.native_func_signature(func_index).clone();
|
context.func.signature = module.native_func_signature(func_index).clone();
|
||||||
if tunables.debug_info {
|
if tunables.debug_info {
|
||||||
context.func.collect_debug_info();
|
context.func.collect_debug_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut func_env = FuncEnvironment::new(isa.frontend_config(), local, tunables);
|
let mut func_env = FuncEnvironment::new(isa.frontend_config(), module, tunables);
|
||||||
|
|
||||||
// We use these as constant offsets below in
|
// We use these as constant offsets below in
|
||||||
// `stack_limit_from_arguments`, so assert their values here. This
|
// `stack_limit_from_arguments`, so assert their values here. This
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::module::{MemoryPlan, MemoryStyle, ModuleLocal, TableStyle};
|
use crate::module::{MemoryPlan, MemoryStyle, TableStyle};
|
||||||
use crate::vmoffsets::VMOffsets;
|
use crate::vmoffsets::VMOffsets;
|
||||||
use crate::{Tunables, INTERRUPTED, WASM_PAGE_SIZE};
|
use crate::{Module, Tunables, INTERRUPTED, WASM_PAGE_SIZE};
|
||||||
use cranelift_codegen::cursor::FuncCursor;
|
use cranelift_codegen::cursor::FuncCursor;
|
||||||
use cranelift_codegen::ir;
|
use cranelift_codegen::ir;
|
||||||
use cranelift_codegen::ir::condcodes::*;
|
use cranelift_codegen::ir::condcodes::*;
|
||||||
@@ -203,7 +203,7 @@ pub struct FuncEnvironment<'module_environment> {
|
|||||||
target_config: TargetFrontendConfig,
|
target_config: TargetFrontendConfig,
|
||||||
|
|
||||||
/// The module-level environment which this function-level environment belongs to.
|
/// The module-level environment which this function-level environment belongs to.
|
||||||
module: &'module_environment ModuleLocal,
|
module: &'module_environment Module,
|
||||||
|
|
||||||
/// The Cranelift global holding the vmctx address.
|
/// The Cranelift global holding the vmctx address.
|
||||||
vmctx: Option<ir::GlobalValue>,
|
vmctx: Option<ir::GlobalValue>,
|
||||||
@@ -220,7 +220,7 @@ pub struct FuncEnvironment<'module_environment> {
|
|||||||
impl<'module_environment> FuncEnvironment<'module_environment> {
|
impl<'module_environment> FuncEnvironment<'module_environment> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
target_config: TargetFrontendConfig,
|
target_config: TargetFrontendConfig,
|
||||||
module: &'module_environment ModuleLocal,
|
module: &'module_environment Module,
|
||||||
tunables: &'module_environment Tunables,
|
tunables: &'module_environment Tunables,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let builtin_function_signatures = BuiltinFunctionSignatures::new(
|
let builtin_function_signatures = BuiltinFunctionSignatures::new(
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ pub use crate::func_environ::BuiltinFunctionIndex;
|
|||||||
#[cfg(feature = "lightbeam")]
|
#[cfg(feature = "lightbeam")]
|
||||||
pub use crate::lightbeam::Lightbeam;
|
pub use crate::lightbeam::Lightbeam;
|
||||||
pub use crate::module::{
|
pub use crate::module::{
|
||||||
EntityIndex, MemoryPlan, MemoryStyle, Module, ModuleLocal, TableElements, TablePlan, TableStyle,
|
EntityIndex, MemoryPlan, MemoryStyle, Module, TableElements, TablePlan, TableStyle,
|
||||||
};
|
};
|
||||||
pub use crate::module_environ::*;
|
pub use crate::module_environ::*;
|
||||||
pub use crate::tunables::Tunables;
|
pub use crate::tunables::Tunables;
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ impl Compiler for Lightbeam {
|
|||||||
if translation.tunables.debug_info {
|
if translation.tunables.debug_info {
|
||||||
return Err(CompileError::DebugInfoNotSupported);
|
return Err(CompileError::DebugInfoNotSupported);
|
||||||
}
|
}
|
||||||
let func_index = translation.module.local.func_index(i);
|
let func_index = translation.module.func_index(i);
|
||||||
|
|
||||||
let env = FuncEnvironment::new(
|
let env = FuncEnvironment::new(
|
||||||
isa.frontend_config(),
|
isa.frontend_config(),
|
||||||
&translation.module.local,
|
&translation.module,
|
||||||
&translation.tunables,
|
&translation.tunables,
|
||||||
);
|
);
|
||||||
let mut codegen_session: CodeGenSession<_> = CodeGenSession::new(
|
let mut codegen_session: CodeGenSession<_> = CodeGenSession::new(
|
||||||
|
|||||||
@@ -146,12 +146,6 @@ pub struct Module {
|
|||||||
/// The name of this wasm module, often found in the wasm file.
|
/// The name of this wasm module, often found in the wasm file.
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
||||||
/// Local information about a module which is the bare minimum necessary to
|
|
||||||
/// translate a function body. This is derived as `Hash` whereas this module
|
|
||||||
/// isn't, since it contains too much information needed to translate a
|
|
||||||
/// function.
|
|
||||||
pub local: ModuleLocal,
|
|
||||||
|
|
||||||
/// All import records, in the order they are declared in the module.
|
/// All import records, in the order they are declared in the module.
|
||||||
pub imports: Vec<(String, String, EntityIndex)>,
|
pub imports: Vec<(String, String, EntityIndex)>,
|
||||||
|
|
||||||
@@ -173,16 +167,7 @@ pub struct Module {
|
|||||||
|
|
||||||
/// WebAssembly table initializers.
|
/// WebAssembly table initializers.
|
||||||
pub func_names: HashMap<FuncIndex, String>,
|
pub func_names: HashMap<FuncIndex, String>,
|
||||||
}
|
|
||||||
|
|
||||||
/// Local information known about a wasm module, the bare minimum necessary to
|
|
||||||
/// translate function bodies.
|
|
||||||
///
|
|
||||||
/// This is stored within a `Module` and it implements `Hash`, unlike `Module`,
|
|
||||||
/// and is used as part of the cache key when we load compiled modules from the
|
|
||||||
/// global cache.
|
|
||||||
#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
|
|
||||||
pub struct ModuleLocal {
|
|
||||||
/// Unprocessed signatures exactly as provided by `declare_signature()`.
|
/// Unprocessed signatures exactly as provided by `declare_signature()`.
|
||||||
pub signatures: PrimaryMap<SignatureIndex, (WasmFuncType, ir::Signature)>,
|
pub signatures: PrimaryMap<SignatureIndex, (WasmFuncType, ir::Signature)>,
|
||||||
|
|
||||||
@@ -224,17 +209,15 @@ impl Module {
|
|||||||
passive_elements: HashMap::new(),
|
passive_elements: HashMap::new(),
|
||||||
passive_data: HashMap::new(),
|
passive_data: HashMap::new(),
|
||||||
func_names: HashMap::new(),
|
func_names: HashMap::new(),
|
||||||
local: ModuleLocal {
|
num_imported_funcs: 0,
|
||||||
num_imported_funcs: 0,
|
num_imported_tables: 0,
|
||||||
num_imported_tables: 0,
|
num_imported_memories: 0,
|
||||||
num_imported_memories: 0,
|
num_imported_globals: 0,
|
||||||
num_imported_globals: 0,
|
signatures: PrimaryMap::new(),
|
||||||
signatures: PrimaryMap::new(),
|
functions: PrimaryMap::new(),
|
||||||
functions: PrimaryMap::new(),
|
table_plans: PrimaryMap::new(),
|
||||||
table_plans: PrimaryMap::new(),
|
memory_plans: PrimaryMap::new(),
|
||||||
memory_plans: PrimaryMap::new(),
|
globals: PrimaryMap::new(),
|
||||||
globals: PrimaryMap::new(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +230,7 @@ impl Module {
|
|||||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||||
NEXT_ID.fetch_add(1, SeqCst)
|
NEXT_ID.fetch_add(1, SeqCst)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ModuleLocal {
|
|
||||||
/// Convert a `DefinedFuncIndex` into a `FuncIndex`.
|
/// Convert a `DefinedFuncIndex` into a `FuncIndex`.
|
||||||
pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
|
pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
|
||||||
FuncIndex::new(self.num_imported_funcs + defined_func.index())
|
FuncIndex::new(self.num_imported_funcs + defined_func.index())
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> {
|
fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -204,7 +203,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
fn declare_signature(&mut self, wasm: WasmFuncType, sig: ir::Signature) -> WasmResult<()> {
|
fn declare_signature(&mut self, wasm: WasmFuncType, sig: ir::Signature) -> WasmResult<()> {
|
||||||
let sig = translate_signature(sig, self.pointer_type());
|
let sig = translate_signature(sig, self.pointer_type());
|
||||||
// TODO: Deduplicate signatures.
|
// TODO: Deduplicate signatures.
|
||||||
self.result.module.local.signatures.push((wasm, sig));
|
self.result.module.signatures.push((wasm, sig));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,17 +222,17 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
field: &str,
|
field: &str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
self.result.module.local.functions.len(),
|
self.result.module.functions.len(),
|
||||||
self.result.module.local.num_imported_funcs,
|
self.result.module.num_imported_funcs,
|
||||||
"Imported functions must be declared first"
|
"Imported functions must be declared first"
|
||||||
);
|
);
|
||||||
let func_index = self.result.module.local.functions.push(sig_index);
|
let func_index = self.result.module.functions.push(sig_index);
|
||||||
self.result.module.imports.push((
|
self.result.module.imports.push((
|
||||||
module.to_owned(),
|
module.to_owned(),
|
||||||
field.to_owned(),
|
field.to_owned(),
|
||||||
EntityIndex::Function(func_index),
|
EntityIndex::Function(func_index),
|
||||||
));
|
));
|
||||||
self.result.module.local.num_imported_funcs += 1;
|
self.result.module.num_imported_funcs += 1;
|
||||||
if let Some(info) = &mut self.result.debuginfo {
|
if let Some(info) = &mut self.result.debuginfo {
|
||||||
info.wasm_file.imported_func_count += 1;
|
info.wasm_file.imported_func_count += 1;
|
||||||
}
|
}
|
||||||
@@ -242,18 +241,18 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
|
|
||||||
fn declare_table_import(&mut self, table: Table, module: &str, field: &str) -> WasmResult<()> {
|
fn declare_table_import(&mut self, table: Table, module: &str, field: &str) -> WasmResult<()> {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
self.result.module.local.table_plans.len(),
|
self.result.module.table_plans.len(),
|
||||||
self.result.module.local.num_imported_tables,
|
self.result.module.num_imported_tables,
|
||||||
"Imported tables must be declared first"
|
"Imported tables must be declared first"
|
||||||
);
|
);
|
||||||
let plan = TablePlan::for_table(table, &self.result.tunables);
|
let plan = TablePlan::for_table(table, &self.result.tunables);
|
||||||
let table_index = self.result.module.local.table_plans.push(plan);
|
let table_index = self.result.module.table_plans.push(plan);
|
||||||
self.result.module.imports.push((
|
self.result.module.imports.push((
|
||||||
module.to_owned(),
|
module.to_owned(),
|
||||||
field.to_owned(),
|
field.to_owned(),
|
||||||
EntityIndex::Table(table_index),
|
EntityIndex::Table(table_index),
|
||||||
));
|
));
|
||||||
self.result.module.local.num_imported_tables += 1;
|
self.result.module.num_imported_tables += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,21 +263,21 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
field: &str,
|
field: &str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
self.result.module.local.memory_plans.len(),
|
self.result.module.memory_plans.len(),
|
||||||
self.result.module.local.num_imported_memories,
|
self.result.module.num_imported_memories,
|
||||||
"Imported memories must be declared first"
|
"Imported memories must be declared first"
|
||||||
);
|
);
|
||||||
if memory.shared {
|
if memory.shared {
|
||||||
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
||||||
}
|
}
|
||||||
let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
|
let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
|
||||||
let memory_index = self.result.module.local.memory_plans.push(plan);
|
let memory_index = self.result.module.memory_plans.push(plan);
|
||||||
self.result.module.imports.push((
|
self.result.module.imports.push((
|
||||||
module.to_owned(),
|
module.to_owned(),
|
||||||
field.to_owned(),
|
field.to_owned(),
|
||||||
EntityIndex::Memory(memory_index),
|
EntityIndex::Memory(memory_index),
|
||||||
));
|
));
|
||||||
self.result.module.local.num_imported_memories += 1;
|
self.result.module.num_imported_memories += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,24 +288,23 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
field: &str,
|
field: &str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
self.result.module.local.globals.len(),
|
self.result.module.globals.len(),
|
||||||
self.result.module.local.num_imported_globals,
|
self.result.module.num_imported_globals,
|
||||||
"Imported globals must be declared first"
|
"Imported globals must be declared first"
|
||||||
);
|
);
|
||||||
let global_index = self.result.module.local.globals.push(global);
|
let global_index = self.result.module.globals.push(global);
|
||||||
self.result.module.imports.push((
|
self.result.module.imports.push((
|
||||||
module.to_owned(),
|
module.to_owned(),
|
||||||
field.to_owned(),
|
field.to_owned(),
|
||||||
EntityIndex::Global(global_index),
|
EntityIndex::Global(global_index),
|
||||||
));
|
));
|
||||||
self.result.module.local.num_imported_globals += 1;
|
self.result.module.num_imported_globals += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reserve_func_types(&mut self, num: u32) -> WasmResult<()> {
|
fn reserve_func_types(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.functions
|
.functions
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
self.result
|
self.result
|
||||||
@@ -316,14 +314,13 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn declare_func_type(&mut self, sig_index: SignatureIndex) -> WasmResult<()> {
|
fn declare_func_type(&mut self, sig_index: SignatureIndex) -> WasmResult<()> {
|
||||||
self.result.module.local.functions.push(sig_index);
|
self.result.module.functions.push(sig_index);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reserve_tables(&mut self, num: u32) -> WasmResult<()> {
|
fn reserve_tables(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.table_plans
|
.table_plans
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -331,14 +328,13 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
|
|
||||||
fn declare_table(&mut self, table: Table) -> WasmResult<()> {
|
fn declare_table(&mut self, table: Table) -> WasmResult<()> {
|
||||||
let plan = TablePlan::for_table(table, &self.result.tunables);
|
let plan = TablePlan::for_table(table, &self.result.tunables);
|
||||||
self.result.module.local.table_plans.push(plan);
|
self.result.module.table_plans.push(plan);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reserve_memories(&mut self, num: u32) -> WasmResult<()> {
|
fn reserve_memories(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.memory_plans
|
.memory_plans
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -349,21 +345,20 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
||||||
}
|
}
|
||||||
let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
|
let plan = MemoryPlan::for_memory(memory, &self.result.tunables);
|
||||||
self.result.module.local.memory_plans.push(plan);
|
self.result.module.memory_plans.push(plan);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reserve_globals(&mut self, num: u32) -> WasmResult<()> {
|
fn reserve_globals(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.globals
|
.globals
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn declare_global(&mut self, global: Global) -> WasmResult<()> {
|
fn declare_global(&mut self, global: Global) -> WasmResult<()> {
|
||||||
self.result.module.local.globals.push(global);
|
self.result.module.globals.push(global);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,10 +451,10 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
|
|||||||
module_offset: body_offset,
|
module_offset: body_offset,
|
||||||
});
|
});
|
||||||
if let Some(info) = &mut self.result.debuginfo {
|
if let Some(info) = &mut self.result.debuginfo {
|
||||||
let func_index = self.code_index + self.result.module.local.num_imported_funcs as u32;
|
let func_index = self.code_index + self.result.module.num_imported_funcs as u32;
|
||||||
let func_index = FuncIndex::from_u32(func_index);
|
let func_index = FuncIndex::from_u32(func_index);
|
||||||
let sig_index = self.result.module.local.functions[func_index];
|
let sig_index = self.result.module.functions[func_index];
|
||||||
let sig = &self.result.module.local.signatures[sig_index];
|
let sig = &self.result.module.signatures[sig_index];
|
||||||
let mut locals = Vec::new();
|
let mut locals = Vec::new();
|
||||||
let body = wasmparser::FunctionBody::new(body_offset, body_bytes);
|
let body = wasmparser::FunctionBody::new(body_offset, body_bytes);
|
||||||
for pair in body.get_locals_reader()? {
|
for pair in body.get_locals_reader()? {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
// builtins: VMBuiltinFunctionsArray,
|
// builtins: VMBuiltinFunctionsArray,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
use crate::module::ModuleLocal;
|
use crate::module::Module;
|
||||||
use crate::BuiltinFunctionIndex;
|
use crate::BuiltinFunctionIndex;
|
||||||
use cranelift_codegen::ir;
|
use cranelift_codegen::ir;
|
||||||
use cranelift_wasm::{
|
use cranelift_wasm::{
|
||||||
@@ -75,7 +75,7 @@ pub struct VMOffsets {
|
|||||||
|
|
||||||
impl VMOffsets {
|
impl VMOffsets {
|
||||||
/// Return a new `VMOffsets` instance, for a given pointer size.
|
/// Return a new `VMOffsets` instance, for a given pointer size.
|
||||||
pub fn new(pointer_size: u8, module: &ModuleLocal) -> Self {
|
pub fn new(pointer_size: u8, module: &Module) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pointer_size,
|
pointer_size,
|
||||||
num_signature_ids: cast_to_u32(module.signatures.len()),
|
num_signature_ids: cast_to_u32(module.signatures.len()),
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ fn transform_dwarf_data(
|
|||||||
funcs: &CompiledFunctions,
|
funcs: &CompiledFunctions,
|
||||||
) -> Result<Vec<DwarfSection>, SetupError> {
|
) -> Result<Vec<DwarfSection>, SetupError> {
|
||||||
let target_config = isa.frontend_config();
|
let target_config = isa.frontend_config();
|
||||||
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local);
|
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module);
|
||||||
|
|
||||||
let memory_offset = if ofs.num_imported_memories > 0 {
|
let memory_offset = if ofs.num_imported_memories > 0 {
|
||||||
ModuleMemoryOffset::Imported(ofs.vmctx_vmmemory_import(MemoryIndex::new(0)))
|
ModuleMemoryOffset::Imported(ofs.vmctx_vmmemory_import(MemoryIndex::new(0)))
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ pub fn resolve_imports(
|
|||||||
signatures: &SignatureRegistry,
|
signatures: &SignatureRegistry,
|
||||||
resolver: &mut dyn Resolver,
|
resolver: &mut dyn Resolver,
|
||||||
) -> Result<Imports, LinkError> {
|
) -> Result<Imports, LinkError> {
|
||||||
let mut function_imports = PrimaryMap::with_capacity(module.local.num_imported_funcs);
|
let mut function_imports = PrimaryMap::with_capacity(module.num_imported_funcs);
|
||||||
let mut table_imports = PrimaryMap::with_capacity(module.local.num_imported_tables);
|
let mut table_imports = PrimaryMap::with_capacity(module.num_imported_tables);
|
||||||
let mut memory_imports = PrimaryMap::with_capacity(module.local.num_imported_memories);
|
let mut memory_imports = PrimaryMap::with_capacity(module.num_imported_memories);
|
||||||
let mut global_imports = PrimaryMap::with_capacity(module.local.num_imported_globals);
|
let mut global_imports = PrimaryMap::with_capacity(module.num_imported_globals);
|
||||||
|
|
||||||
for (import_idx, (module_name, field_name, import)) in module.imports.iter().enumerate() {
|
for (import_idx, (module_name, field_name, import)) in module.imports.iter().enumerate() {
|
||||||
let import_idx = import_idx.try_into().unwrap();
|
let import_idx = import_idx.try_into().unwrap();
|
||||||
@@ -31,7 +31,7 @@ pub fn resolve_imports(
|
|||||||
|
|
||||||
match (import, &export) {
|
match (import, &export) {
|
||||||
(EntityIndex::Function(func_index), Some(Export::Function(f))) => {
|
(EntityIndex::Function(func_index), Some(Export::Function(f))) => {
|
||||||
let import_signature = module.local.native_func_signature(*func_index);
|
let import_signature = module.native_func_signature(*func_index);
|
||||||
let signature = signatures
|
let signature = signatures
|
||||||
.lookup_native(unsafe { f.anyfunc.as_ref().type_index })
|
.lookup_native(unsafe { f.anyfunc.as_ref().type_index })
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -63,7 +63,7 @@ pub fn resolve_imports(
|
|||||||
}
|
}
|
||||||
|
|
||||||
(EntityIndex::Table(table_index), Some(Export::Table(t))) => {
|
(EntityIndex::Table(table_index), Some(Export::Table(t))) => {
|
||||||
let import_table = &module.local.table_plans[*table_index];
|
let import_table = &module.table_plans[*table_index];
|
||||||
if !is_table_compatible(&t.table, import_table) {
|
if !is_table_compatible(&t.table, import_table) {
|
||||||
return Err(LinkError(format!(
|
return Err(LinkError(format!(
|
||||||
"{}/{}: incompatible import type: exported table incompatible with \
|
"{}/{}: incompatible import type: exported table incompatible with \
|
||||||
@@ -90,7 +90,7 @@ pub fn resolve_imports(
|
|||||||
}
|
}
|
||||||
|
|
||||||
(EntityIndex::Memory(memory_index), Some(Export::Memory(m))) => {
|
(EntityIndex::Memory(memory_index), Some(Export::Memory(m))) => {
|
||||||
let import_memory = &module.local.memory_plans[*memory_index];
|
let import_memory = &module.memory_plans[*memory_index];
|
||||||
if !is_memory_compatible(&m.memory, import_memory) {
|
if !is_memory_compatible(&m.memory, import_memory) {
|
||||||
return Err(LinkError(format!(
|
return Err(LinkError(format!(
|
||||||
"{}/{}: incompatible import type: exported memory incompatible with \
|
"{}/{}: incompatible import type: exported memory incompatible with \
|
||||||
@@ -131,7 +131,7 @@ pub fn resolve_imports(
|
|||||||
}
|
}
|
||||||
|
|
||||||
(EntityIndex::Global(global_index), Some(Export::Global(g))) => {
|
(EntityIndex::Global(global_index), Some(Export::Global(g))) => {
|
||||||
let imported_global = module.local.globals[*global_index];
|
let imported_global = module.globals[*global_index];
|
||||||
if !is_global_compatible(&g.global, &imported_global) {
|
if !is_global_compatible(&g.global, &imported_global) {
|
||||||
return Err(LinkError(format!(
|
return Err(LinkError(format!(
|
||||||
"{}/{}: incompatible import type: exported global incompatible with \
|
"{}/{}: incompatible import type: exported global incompatible with \
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ impl CompiledModule {
|
|||||||
// Compute indices into the shared signature table.
|
// Compute indices into the shared signature table.
|
||||||
let signatures = {
|
let signatures = {
|
||||||
self.module
|
self.module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.values()
|
.values()
|
||||||
.map(|(wasm_sig, native)| {
|
.map(|(wasm_sig, native)| {
|
||||||
@@ -387,7 +386,7 @@ fn create_dbg_image(
|
|||||||
.values()
|
.values()
|
||||||
.map(|allocated: &*mut [VMFunctionBody]| (*allocated) as *const u8)
|
.map(|allocated: &*mut [VMFunctionBody]| (*allocated) as *const u8)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
create_gdbjit_image(obj, code_range, module.local.num_imported_funcs, &funcs)
|
create_gdbjit_image(obj, code_range, module.num_imported_funcs, &funcs)
|
||||||
.map_err(SetupError::DebugInfo)
|
.map_err(SetupError::DebugInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,7 +416,7 @@ fn build_code_memory(
|
|||||||
let fat_ptr: *mut [VMFunctionBody] = fat_ptr;
|
let fat_ptr: *mut [VMFunctionBody] = fat_ptr;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some(finished_functions.push(fat_ptr)),
|
Some(finished_functions.push(fat_ptr)),
|
||||||
module.local.defined_func_index(i)
|
module.defined_func_index(i)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ fn apply_reloc(
|
|||||||
match sym.name() {
|
match sym.name() {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
if let Some(index) = try_parse_func_name(name) {
|
if let Some(index) = try_parse_func_name(name) {
|
||||||
match module.local.defined_func_index(index) {
|
match module.defined_func_index(index) {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
let fatptr: *const [VMFunctionBody] = finished_functions[f];
|
let fatptr: *const [VMFunctionBody] = finished_functions[f];
|
||||||
fatptr as *const VMFunctionBody as usize
|
fatptr as *const VMFunctionBody as usize
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ pub(crate) fn build_object(
|
|||||||
unwind_info.extend(funcs.iter().filter_map(|(index, func)| {
|
unwind_info.extend(funcs.iter().filter_map(|(index, func)| {
|
||||||
func.unwind_info
|
func.unwind_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|info| ObjectUnwindInfo::Func(module.local.func_index(index), info.clone()))
|
.map(|info| ObjectUnwindInfo::Func(module.func_index(index), info.clone()))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let mut trampolines = PrimaryMap::with_capacity(module.local.signatures.len());
|
let mut trampolines = PrimaryMap::with_capacity(module.signatures.len());
|
||||||
let mut cx = FunctionBuilderContext::new();
|
let mut cx = FunctionBuilderContext::new();
|
||||||
// Build trampolines for every signature.
|
// Build trampolines for every signature.
|
||||||
for (i, (_, native_sig)) in module.local.signatures.iter() {
|
for (i, (_, native_sig)) in module.signatures.iter() {
|
||||||
let func = build_trampoline(isa, &mut cx, native_sig, std::mem::size_of::<u128>())?;
|
let func = build_trampoline(isa, &mut cx, native_sig, std::mem::size_of::<u128>())?;
|
||||||
// Preserve trampoline function unwind info.
|
// Preserve trampoline function unwind info.
|
||||||
if let Some(info) = &func.unwind_info {
|
if let Some(info) = &func.unwind_info {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fn to_object_relocations<'a>(
|
|||||||
RelocationTarget::UserFunc(index) => (funcs[index], 0),
|
RelocationTarget::UserFunc(index) => (funcs[index], 0),
|
||||||
RelocationTarget::LibCall(call) => (libcalls[&call], 0),
|
RelocationTarget::LibCall(call) => (libcalls[&call], 0),
|
||||||
RelocationTarget::JumpTable(f, jt) => {
|
RelocationTarget::JumpTable(f, jt) => {
|
||||||
let df = module.local.defined_func_index(f).unwrap();
|
let df = module.defined_func_index(f).unwrap();
|
||||||
let offset = *compiled_funcs
|
let offset = *compiled_funcs
|
||||||
.get(df)
|
.get(df)
|
||||||
.and_then(|f| f.jt_offsets.get(jt))
|
.and_then(|f| f.jt_offsets.get(jt))
|
||||||
@@ -314,7 +314,7 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
|
|
||||||
// Create symbols for imports -- needed during linking.
|
// Create symbols for imports -- needed during linking.
|
||||||
let mut func_symbols = PrimaryMap::with_capacity(self.compilation.len());
|
let mut func_symbols = PrimaryMap::with_capacity(self.compilation.len());
|
||||||
for index in 0..module.local.num_imported_funcs {
|
for index in 0..module.num_imported_funcs {
|
||||||
let symbol_id = obj.add_symbol(Symbol {
|
let symbol_id = obj.add_symbol(Symbol {
|
||||||
name: utils::func_symbol_name(FuncIndex::new(index))
|
name: utils::func_symbol_name(FuncIndex::new(index))
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
@@ -351,7 +351,7 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
|
|
||||||
// Create symbols and section data for the compiled functions.
|
// Create symbols and section data for the compiled functions.
|
||||||
for (index, func) in self.compilation.iter() {
|
for (index, func) in self.compilation.iter() {
|
||||||
let name = utils::func_symbol_name(module.local.func_index(index))
|
let name = utils::func_symbol_name(module.func_index(index))
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.to_vec();
|
.to_vec();
|
||||||
let symbol_id = append_func(name, func);
|
let symbol_id = append_func(name, func);
|
||||||
@@ -383,7 +383,7 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
|
|
||||||
// Write all functions relocations.
|
// Write all functions relocations.
|
||||||
for (index, func) in self.compilation.into_iter() {
|
for (index, func) in self.compilation.into_iter() {
|
||||||
let func_index = module.local.func_index(index);
|
let func_index = module.func_index(index);
|
||||||
let (_, off) = obj
|
let (_, off) = obj
|
||||||
.symbol_section_and_offset(func_symbols[func_index])
|
.symbol_section_and_offset(func_symbols[func_index])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -419,7 +419,7 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
for reloc in relocs {
|
for reloc in relocs {
|
||||||
let target_symbol = match reloc.target {
|
let target_symbol = match reloc.target {
|
||||||
DwarfSectionRelocTarget::Func(index) => {
|
DwarfSectionRelocTarget::Func(index) => {
|
||||||
func_symbols[module.local.func_index(DefinedFuncIndex::new(index))]
|
func_symbols[module.func_index(DefinedFuncIndex::new(index))]
|
||||||
}
|
}
|
||||||
DwarfSectionRelocTarget::Section(name) => {
|
DwarfSectionRelocTarget::Section(name) => {
|
||||||
obj.section_symbol(*dwarf_sections_ids.get(name).unwrap())
|
obj.section_symbol(*dwarf_sections_ids.get(name).unwrap())
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ pub fn layout_vmcontext(
|
|||||||
module: &Module,
|
module: &Module,
|
||||||
target_config: &TargetFrontendConfig,
|
target_config: &TargetFrontendConfig,
|
||||||
) -> (Box<[u8]>, Box<[TableRelocation]>) {
|
) -> (Box<[u8]>, Box<[TableRelocation]>) {
|
||||||
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local);
|
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module);
|
||||||
let out_len = ofs.size_of_vmctx() as usize;
|
let out_len = ofs.size_of_vmctx() as usize;
|
||||||
let mut out = vec![0; out_len];
|
let mut out = vec![0; out_len];
|
||||||
|
|
||||||
// Assign unique indices to unique signatures.
|
// Assign unique indices to unique signatures.
|
||||||
let mut signature_registry = HashMap::new();
|
let mut signature_registry = HashMap::new();
|
||||||
let mut signature_registry_len = signature_registry.len();
|
let mut signature_registry_len = signature_registry.len();
|
||||||
for (index, sig) in module.local.signatures.iter() {
|
for (index, sig) in module.signatures.iter() {
|
||||||
let offset = ofs.vmctx_vmshared_signature_id(index) as usize;
|
let offset = ofs.vmctx_vmshared_signature_id(index) as usize;
|
||||||
let target_index = match signature_registry.entry(sig) {
|
let target_index = match signature_registry.entry(sig) {
|
||||||
Entry::Occupied(o) => *o.get(),
|
Entry::Occupied(o) => *o.get(),
|
||||||
@@ -42,10 +42,10 @@ pub fn layout_vmcontext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let num_tables_imports = module.local.num_imported_tables;
|
let num_tables_imports = module.num_imported_tables;
|
||||||
let mut table_relocs = Vec::with_capacity(module.local.table_plans.len() - num_tables_imports);
|
let mut table_relocs = Vec::with_capacity(module.table_plans.len() - num_tables_imports);
|
||||||
for (index, table) in module.local.table_plans.iter().skip(num_tables_imports) {
|
for (index, table) in module.table_plans.iter().skip(num_tables_imports) {
|
||||||
let def_index = module.local.defined_table_index(index).unwrap();
|
let def_index = module.defined_table_index(index).unwrap();
|
||||||
let offset = ofs.vmctx_vmtable_definition(def_index) as usize;
|
let offset = ofs.vmctx_vmtable_definition(def_index) as usize;
|
||||||
let current_elements = table.table.minimum;
|
let current_elements = table.table.minimum;
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -66,9 +66,9 @@ pub fn layout_vmcontext(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let num_globals_imports = module.local.num_imported_globals;
|
let num_globals_imports = module.num_imported_globals;
|
||||||
for (index, global) in module.local.globals.iter().skip(num_globals_imports) {
|
for (index, global) in module.globals.iter().skip(num_globals_imports) {
|
||||||
let def_index = module.local.defined_global_index(index).unwrap();
|
let def_index = module.defined_global_index(index).unwrap();
|
||||||
let offset = ofs.vmctx_vmglobal_definition(def_index) as usize;
|
let offset = ofs.vmctx_vmglobal_definition(def_index) as usize;
|
||||||
let to = unsafe { out.as_mut_ptr().add(offset) };
|
let to = unsafe { out.as_mut_ptr().add(offset) };
|
||||||
match global.initializer {
|
match global.initializer {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ pub fn emit_module(
|
|||||||
declare_data_segment(&mut obj, initializer, i)?;
|
declare_data_segment(&mut obj, initializer, i)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..module.local.table_plans.len() {
|
for i in 0..module.table_plans.len() {
|
||||||
declare_table(&mut obj, i)?;
|
declare_table(&mut obj, i)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ pub fn emit_module(
|
|||||||
emit_data_segment(&mut obj, initializer, i)?;
|
emit_data_segment(&mut obj, initializer, i)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..module.local.table_plans.len() {
|
for i in 0..module.table_plans.len() {
|
||||||
emit_table(&mut obj, i)?;
|
emit_table(&mut obj, i)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ impl ProfilingAgent for NullProfilerAgent {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn debug_name(module: &Module, index: DefinedFuncIndex) -> String {
|
fn debug_name(module: &Module, index: DefinedFuncIndex) -> String {
|
||||||
let index = module.local.func_index(index);
|
let index = module.func_index(index);
|
||||||
match module.func_names.get(&index) {
|
match module.func_names.get(&index) {
|
||||||
Some(s) => s.clone(),
|
Some(s) => s.clone(),
|
||||||
None => format!("wasm::wasm-function[{}]", index.index()),
|
None => format!("wasm::wasm-function[{}]", index.index()),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub unsafe extern "C" fn resolve_vmctx_memory_ptr(p: *const u32) -> *const u8 {
|
|||||||
);
|
);
|
||||||
let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
|
let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
|
||||||
assert!(
|
assert!(
|
||||||
VMCTX_AND_MEMORY.1 < handle.module().local.memory_plans.len(),
|
VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(),
|
||||||
"memory index for debugger is out of bounds"
|
"memory index for debugger is out of bounds"
|
||||||
);
|
);
|
||||||
let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
|
let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ impl Instance {
|
|||||||
|
|
||||||
/// Get a locally defined or imported memory.
|
/// Get a locally defined or imported memory.
|
||||||
pub(crate) fn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition {
|
pub(crate) fn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition {
|
||||||
if let Some(defined_index) = self.module.local.defined_memory_index(index) {
|
if let Some(defined_index) = self.module.defined_memory_index(index) {
|
||||||
self.memory(defined_index)
|
self.memory(defined_index)
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_memory(index);
|
let import = self.imported_memory(index);
|
||||||
@@ -234,7 +234,7 @@ impl Instance {
|
|||||||
&self,
|
&self,
|
||||||
index: GlobalIndex,
|
index: GlobalIndex,
|
||||||
) -> *mut VMGlobalDefinition {
|
) -> *mut VMGlobalDefinition {
|
||||||
if let Some(index) = self.module.local.defined_global_index(index) {
|
if let Some(index) = self.module.defined_global_index(index) {
|
||||||
self.global_ptr(index)
|
self.global_ptr(index)
|
||||||
} else {
|
} else {
|
||||||
self.imported_global(index).from
|
self.imported_global(index).from
|
||||||
@@ -297,7 +297,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
EntityIndex::Table(index) => {
|
EntityIndex::Table(index) => {
|
||||||
let (definition, vmctx) =
|
let (definition, vmctx) =
|
||||||
if let Some(def_index) = self.module.local.defined_table_index(*index) {
|
if let Some(def_index) = self.module.defined_table_index(*index) {
|
||||||
(self.table_ptr(def_index), self.vmctx_ptr())
|
(self.table_ptr(def_index), self.vmctx_ptr())
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_table(*index);
|
let import = self.imported_table(*index);
|
||||||
@@ -306,13 +306,13 @@ impl Instance {
|
|||||||
ExportTable {
|
ExportTable {
|
||||||
definition,
|
definition,
|
||||||
vmctx,
|
vmctx,
|
||||||
table: self.module.local.table_plans[*index].clone(),
|
table: self.module.table_plans[*index].clone(),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
EntityIndex::Memory(index) => {
|
EntityIndex::Memory(index) => {
|
||||||
let (definition, vmctx) =
|
let (definition, vmctx) =
|
||||||
if let Some(def_index) = self.module.local.defined_memory_index(*index) {
|
if let Some(def_index) = self.module.defined_memory_index(*index) {
|
||||||
(self.memory_ptr(def_index), self.vmctx_ptr())
|
(self.memory_ptr(def_index), self.vmctx_ptr())
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_memory(*index);
|
let import = self.imported_memory(*index);
|
||||||
@@ -321,19 +321,18 @@ impl Instance {
|
|||||||
ExportMemory {
|
ExportMemory {
|
||||||
definition,
|
definition,
|
||||||
vmctx,
|
vmctx,
|
||||||
memory: self.module.local.memory_plans[*index].clone(),
|
memory: self.module.memory_plans[*index].clone(),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
EntityIndex::Global(index) => ExportGlobal {
|
EntityIndex::Global(index) => ExportGlobal {
|
||||||
definition: if let Some(def_index) = self.module.local.defined_global_index(*index)
|
definition: if let Some(def_index) = self.module.defined_global_index(*index) {
|
||||||
{
|
|
||||||
self.global_ptr(def_index)
|
self.global_ptr(def_index)
|
||||||
} else {
|
} else {
|
||||||
self.imported_global(*index).from
|
self.imported_global(*index).from
|
||||||
},
|
},
|
||||||
vmctx: self.vmctx_ptr(),
|
vmctx: self.vmctx_ptr(),
|
||||||
global: self.module.local.globals[*index],
|
global: self.module.globals[*index],
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
@@ -771,7 +770,7 @@ impl Instance {
|
|||||||
/// Get a table by index regardless of whether it is locally-defined or an
|
/// Get a table by index regardless of whether it is locally-defined or an
|
||||||
/// imported, foreign table.
|
/// imported, foreign table.
|
||||||
pub(crate) fn get_table(&self, table_index: TableIndex) -> &Table {
|
pub(crate) fn get_table(&self, table_index: TableIndex) -> &Table {
|
||||||
if let Some(defined_table_index) = self.module.local.defined_table_index(table_index) {
|
if let Some(defined_table_index) = self.module.defined_table_index(table_index) {
|
||||||
self.get_defined_table(defined_table_index)
|
self.get_defined_table(defined_table_index)
|
||||||
} else {
|
} else {
|
||||||
self.get_foreign_table(table_index)
|
self.get_foreign_table(table_index)
|
||||||
@@ -796,7 +795,7 @@ impl Instance {
|
|||||||
&self,
|
&self,
|
||||||
index: TableIndex,
|
index: TableIndex,
|
||||||
) -> (DefinedTableIndex, &Instance) {
|
) -> (DefinedTableIndex, &Instance) {
|
||||||
if let Some(defined_table_index) = self.module.local.defined_table_index(index) {
|
if let Some(defined_table_index) = self.module.defined_table_index(index) {
|
||||||
(defined_table_index, self)
|
(defined_table_index, self)
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_table(index);
|
let import = self.imported_table(index);
|
||||||
@@ -867,7 +866,7 @@ impl InstanceHandle {
|
|||||||
|
|
||||||
let vmctx_globals = create_globals(&module);
|
let vmctx_globals = create_globals(&module);
|
||||||
|
|
||||||
let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module);
|
||||||
|
|
||||||
let passive_data = RefCell::new(module.passive_data.clone());
|
let passive_data = RefCell::new(module.passive_data.clone());
|
||||||
|
|
||||||
@@ -946,11 +945,11 @@ impl InstanceHandle {
|
|||||||
*instance.externref_activations_table() = externref_activations_table;
|
*instance.externref_activations_table() = externref_activations_table;
|
||||||
*instance.stack_map_registry() = stack_map_registry;
|
*instance.stack_map_registry() = stack_map_registry;
|
||||||
|
|
||||||
for (index, sig) in instance.module.local.functions.iter() {
|
for (index, sig) in instance.module.functions.iter() {
|
||||||
let type_index = instance.signature_id(*sig);
|
let type_index = instance.signature_id(*sig);
|
||||||
|
|
||||||
let (func_ptr, vmctx) =
|
let (func_ptr, vmctx) =
|
||||||
if let Some(def_index) = instance.module.local.defined_func_index(index) {
|
if let Some(def_index) = instance.module.defined_func_index(index) {
|
||||||
(
|
(
|
||||||
NonNull::new(instance.finished_functions[def_index] as *mut _).unwrap(),
|
NonNull::new(instance.finished_functions[def_index] as *mut _).unwrap(),
|
||||||
instance.vmctx_ptr(),
|
instance.vmctx_ptr(),
|
||||||
@@ -1202,7 +1201,7 @@ fn get_memory_init_start(init: &DataInitializer<'_>, instance: &Instance) -> usi
|
|||||||
|
|
||||||
if let Some(base) = init.location.base {
|
if let Some(base) = init.location.base {
|
||||||
let val = unsafe {
|
let val = unsafe {
|
||||||
if let Some(def_index) = instance.module.local.defined_global_index(base) {
|
if let Some(def_index) = instance.module.defined_global_index(base) {
|
||||||
*instance.global(def_index).as_u32()
|
*instance.global(def_index).as_u32()
|
||||||
} else {
|
} else {
|
||||||
*(*instance.imported_global(base).from).as_u32()
|
*(*instance.imported_global(base).from).as_u32()
|
||||||
@@ -1221,7 +1220,6 @@ unsafe fn get_memory_slice<'instance>(
|
|||||||
) -> &'instance mut [u8] {
|
) -> &'instance mut [u8] {
|
||||||
let memory = if let Some(defined_memory_index) = instance
|
let memory = if let Some(defined_memory_index) = instance
|
||||||
.module
|
.module
|
||||||
.local
|
|
||||||
.defined_memory_index(init.location.memory_index)
|
.defined_memory_index(init.location.memory_index)
|
||||||
{
|
{
|
||||||
instance.memory(defined_memory_index)
|
instance.memory(defined_memory_index)
|
||||||
@@ -1256,10 +1254,10 @@ fn check_memory_init_bounds(
|
|||||||
|
|
||||||
/// Allocate memory for just the tables of the current module.
|
/// Allocate memory for just the tables of the current module.
|
||||||
fn create_tables(module: &Module) -> BoxedSlice<DefinedTableIndex, Table> {
|
fn create_tables(module: &Module) -> BoxedSlice<DefinedTableIndex, Table> {
|
||||||
let num_imports = module.local.num_imported_tables;
|
let num_imports = module.num_imported_tables;
|
||||||
let mut tables: PrimaryMap<DefinedTableIndex, _> =
|
let mut tables: PrimaryMap<DefinedTableIndex, _> =
|
||||||
PrimaryMap::with_capacity(module.local.table_plans.len() - num_imports);
|
PrimaryMap::with_capacity(module.table_plans.len() - num_imports);
|
||||||
for table in &module.local.table_plans.values().as_slice()[num_imports..] {
|
for table in &module.table_plans.values().as_slice()[num_imports..] {
|
||||||
tables.push(Table::new(table));
|
tables.push(Table::new(table));
|
||||||
}
|
}
|
||||||
tables.into_boxed_slice()
|
tables.into_boxed_slice()
|
||||||
@@ -1271,7 +1269,7 @@ fn get_table_init_start(init: &TableElements, instance: &Instance) -> usize {
|
|||||||
|
|
||||||
if let Some(base) = init.base {
|
if let Some(base) = init.base {
|
||||||
let val = unsafe {
|
let val = unsafe {
|
||||||
if let Some(def_index) = instance.module.local.defined_global_index(base) {
|
if let Some(def_index) = instance.module.defined_global_index(base) {
|
||||||
*instance.global(def_index).as_u32()
|
*instance.global(def_index).as_u32()
|
||||||
} else {
|
} else {
|
||||||
*(*instance.imported_global(base).from).as_u32()
|
*(*instance.imported_global(base).from).as_u32()
|
||||||
@@ -1354,10 +1352,10 @@ fn create_memories(
|
|||||||
module: &Module,
|
module: &Module,
|
||||||
mem_creator: &dyn RuntimeMemoryCreator,
|
mem_creator: &dyn RuntimeMemoryCreator,
|
||||||
) -> Result<BoxedSlice<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>, InstantiationError> {
|
) -> Result<BoxedSlice<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>, InstantiationError> {
|
||||||
let num_imports = module.local.num_imported_memories;
|
let num_imports = module.num_imported_memories;
|
||||||
let mut memories: PrimaryMap<DefinedMemoryIndex, _> =
|
let mut memories: PrimaryMap<DefinedMemoryIndex, _> =
|
||||||
PrimaryMap::with_capacity(module.local.memory_plans.len() - num_imports);
|
PrimaryMap::with_capacity(module.memory_plans.len() - num_imports);
|
||||||
for plan in &module.local.memory_plans.values().as_slice()[num_imports..] {
|
for plan in &module.memory_plans.values().as_slice()[num_imports..] {
|
||||||
memories.push(
|
memories.push(
|
||||||
mem_creator
|
mem_creator
|
||||||
.new_memory(plan)
|
.new_memory(plan)
|
||||||
@@ -1399,10 +1397,10 @@ fn initialize_memories(
|
|||||||
/// Allocate memory for just the globals of the current module,
|
/// Allocate memory for just the globals of the current module,
|
||||||
/// with initializers applied.
|
/// with initializers applied.
|
||||||
fn create_globals(module: &Module) -> BoxedSlice<DefinedGlobalIndex, VMGlobalDefinition> {
|
fn create_globals(module: &Module) -> BoxedSlice<DefinedGlobalIndex, VMGlobalDefinition> {
|
||||||
let num_imports = module.local.num_imported_globals;
|
let num_imports = module.num_imported_globals;
|
||||||
let mut vmctx_globals = PrimaryMap::with_capacity(module.local.globals.len() - num_imports);
|
let mut vmctx_globals = PrimaryMap::with_capacity(module.globals.len() - num_imports);
|
||||||
|
|
||||||
for _ in &module.local.globals.values().as_slice()[num_imports..] {
|
for _ in &module.globals.values().as_slice()[num_imports..] {
|
||||||
vmctx_globals.push(VMGlobalDefinition::new());
|
vmctx_globals.push(VMGlobalDefinition::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1411,9 +1409,9 @@ fn create_globals(module: &Module) -> BoxedSlice<DefinedGlobalIndex, VMGlobalDef
|
|||||||
|
|
||||||
fn initialize_globals(instance: &Instance) {
|
fn initialize_globals(instance: &Instance) {
|
||||||
let module = instance.module();
|
let module = instance.module();
|
||||||
let num_imports = module.local.num_imported_globals;
|
let num_imports = module.num_imported_globals;
|
||||||
for (index, global) in module.local.globals.iter().skip(num_imports) {
|
for (index, global) in module.globals.iter().skip(num_imports) {
|
||||||
let def_index = module.local.defined_global_index(index).unwrap();
|
let def_index = module.defined_global_index(index).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
let to = instance.global_ptr(def_index);
|
let to = instance.global_ptr(def_index);
|
||||||
match global.initializer {
|
match global.initializer {
|
||||||
@@ -1423,7 +1421,7 @@ fn initialize_globals(instance: &Instance) {
|
|||||||
GlobalInit::F64Const(x) => *(*to).as_f64_bits_mut() = x,
|
GlobalInit::F64Const(x) => *(*to).as_f64_bits_mut() = x,
|
||||||
GlobalInit::V128Const(x) => *(*to).as_u128_bits_mut() = x.0,
|
GlobalInit::V128Const(x) => *(*to).as_u128_bits_mut() = x.0,
|
||||||
GlobalInit::GetGlobal(x) => {
|
GlobalInit::GetGlobal(x) => {
|
||||||
let from = if let Some(def_x) = module.local.defined_global_index(x) {
|
let from = if let Some(def_x) = module.defined_global_index(x) {
|
||||||
instance.global(def_x)
|
instance.global(def_x)
|
||||||
} else {
|
} else {
|
||||||
*instance.imported_global(x).from
|
*instance.imported_global(x).from
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ mod test_vmfunction_import {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmfunction_import_offsets() {
|
fn check_vmfunction_import_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMFunctionImport>(),
|
size_of::<VMFunctionImport>(),
|
||||||
usize::from(offsets.size_of_vmfunction_import())
|
usize::from(offsets.size_of_vmfunction_import())
|
||||||
@@ -86,7 +86,7 @@ mod test_vmtable_import {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmtable_import_offsets() {
|
fn check_vmtable_import_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMTableImport>(),
|
size_of::<VMTableImport>(),
|
||||||
usize::from(offsets.size_of_vmtable_import())
|
usize::from(offsets.size_of_vmtable_import())
|
||||||
@@ -124,7 +124,7 @@ mod test_vmmemory_import {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmmemory_import_offsets() {
|
fn check_vmmemory_import_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMMemoryImport>(),
|
size_of::<VMMemoryImport>(),
|
||||||
usize::from(offsets.size_of_vmmemory_import())
|
usize::from(offsets.size_of_vmmemory_import())
|
||||||
@@ -159,7 +159,7 @@ mod test_vmglobal_import {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmglobal_import_offsets() {
|
fn check_vmglobal_import_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMGlobalImport>(),
|
size_of::<VMGlobalImport>(),
|
||||||
usize::from(offsets.size_of_vmglobal_import())
|
usize::from(offsets.size_of_vmglobal_import())
|
||||||
@@ -194,7 +194,7 @@ mod test_vmmemory_definition {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmmemory_definition_offsets() {
|
fn check_vmmemory_definition_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMMemoryDefinition>(),
|
size_of::<VMMemoryDefinition>(),
|
||||||
usize::from(offsets.size_of_vmmemory_definition())
|
usize::from(offsets.size_of_vmmemory_definition())
|
||||||
@@ -238,7 +238,7 @@ mod test_vmtable_definition {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmtable_definition_offsets() {
|
fn check_vmtable_definition_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMTableDefinition>(),
|
size_of::<VMTableDefinition>(),
|
||||||
usize::from(offsets.size_of_vmtable_definition())
|
usize::from(offsets.size_of_vmtable_definition())
|
||||||
@@ -285,7 +285,7 @@ mod test_vmglobal_definition {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmglobal_definition_offsets() {
|
fn check_vmglobal_definition_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMGlobalDefinition>(),
|
size_of::<VMGlobalDefinition>(),
|
||||||
usize::from(offsets.size_of_vmglobal_definition())
|
usize::from(offsets.size_of_vmglobal_definition())
|
||||||
@@ -295,7 +295,7 @@ mod test_vmglobal_definition {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmglobal_begins_aligned() {
|
fn check_vmglobal_begins_aligned() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(offsets.vmctx_globals_begin() % 16, 0);
|
assert_eq!(offsets.vmctx_globals_begin() % 16, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ mod test_vmshared_signature_index {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmshared_signature_index() {
|
fn check_vmshared_signature_index() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMSharedSignatureIndex>(),
|
size_of::<VMSharedSignatureIndex>(),
|
||||||
usize::from(offsets.size_of_vmshared_signature_index())
|
usize::from(offsets.size_of_vmshared_signature_index())
|
||||||
@@ -525,7 +525,7 @@ mod test_vmcaller_checked_anyfunc {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmcaller_checked_anyfunc_offsets() {
|
fn check_vmcaller_checked_anyfunc_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMCallerCheckedAnyfunc>(),
|
size_of::<VMCallerCheckedAnyfunc>(),
|
||||||
usize::from(offsets.size_of_vmcaller_checked_anyfunc())
|
usize::from(offsets.size_of_vmcaller_checked_anyfunc())
|
||||||
@@ -629,7 +629,7 @@ mod test_vm_invoke_argument {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vmglobal_definition_offsets() {
|
fn check_vmglobal_definition_offsets() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
size_of::<VMInvokeArgument>(),
|
size_of::<VMInvokeArgument>(),
|
||||||
usize::from(offsets.size_of_vmglobal_definition())
|
usize::from(offsets.size_of_vmglobal_definition())
|
||||||
@@ -682,7 +682,7 @@ mod test_vminterrupts {
|
|||||||
#[test]
|
#[test]
|
||||||
fn check_vminterrupts_interrupted_offset() {
|
fn check_vminterrupts_interrupted_offset() {
|
||||||
let module = Module::new();
|
let module = Module::new();
|
||||||
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local);
|
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
offset_of!(VMInterrupts, stack_limit),
|
offset_of!(VMInterrupts, stack_limit),
|
||||||
usize::from(offsets.vminterrupts_stack_limit())
|
usize::from(offsets.vminterrupts_stack_limit())
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ pub fn register(module: &CompiledModule) -> Option<GlobalFrameInfoRegistration>
|
|||||||
max = cmp::max(max, end);
|
max = cmp::max(max, end);
|
||||||
let func = FunctionInfo {
|
let func = FunctionInfo {
|
||||||
start,
|
start,
|
||||||
index: module.module().local.func_index(i),
|
index: module.module().func_index(i),
|
||||||
traps: traps.to_vec(),
|
traps: traps.to_vec(),
|
||||||
instr_map: address_map.clone(),
|
instr_map: address_map.clone(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ pub(crate) fn create_handle(
|
|||||||
|
|
||||||
// Compute indices into the shared signature table.
|
// Compute indices into the shared signature table.
|
||||||
let signatures = module
|
let signatures = module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.values()
|
.values()
|
||||||
.map(|(wasm, native)| store.register_signature(wasm.clone(), native.clone()))
|
.map(|(wasm, native)| store.register_signature(wasm.clone(), native.clone()))
|
||||||
|
|||||||
@@ -229,10 +229,9 @@ pub fn create_handle_with_function(
|
|||||||
// First up we manufacture a trampoline which has the ABI specified by `ft`
|
// First up we manufacture a trampoline which has the ABI specified by `ft`
|
||||||
// and calls into `stub_fn`...
|
// and calls into `stub_fn`...
|
||||||
let sig_id = module
|
let sig_id = module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.push((ft.to_wasm_func_type(), sig.clone()));
|
.push((ft.to_wasm_func_type(), sig.clone()));
|
||||||
let func_id = module.local.functions.push(sig_id);
|
let func_id = module.functions.push(sig_id);
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("trampoline".to_string(), EntityIndex::Function(func_id));
|
.insert("trampoline".to_string(), EntityIndex::Function(func_id));
|
||||||
@@ -289,10 +288,9 @@ pub unsafe fn create_handle_with_raw_function(
|
|||||||
let mut trampolines = HashMap::new();
|
let mut trampolines = HashMap::new();
|
||||||
|
|
||||||
let sig_id = module
|
let sig_id = module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.push((ft.to_wasm_func_type(), sig.clone()));
|
.push((ft.to_wasm_func_type(), sig.clone()));
|
||||||
let func_id = module.local.functions.push(sig_id);
|
let func_id = module.functions.push(sig_id);
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("trampoline".to_string(), EntityIndex::Function(func_id));
|
.insert("trampoline".to_string(), EntityIndex::Function(func_id));
|
||||||
|
|||||||
@@ -37,11 +37,10 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
|
|||||||
// our global with a `ref.func` to grab that imported function.
|
// our global with a `ref.func` to grab that imported function.
|
||||||
let shared_sig_index = f.sig_index();
|
let shared_sig_index = f.sig_index();
|
||||||
let local_sig_index = module
|
let local_sig_index = module
|
||||||
.local
|
|
||||||
.signatures
|
.signatures
|
||||||
.push(store.lookup_wasm_and_native_signatures(shared_sig_index));
|
.push(store.lookup_wasm_and_native_signatures(shared_sig_index));
|
||||||
let func_index = module.local.functions.push(local_sig_index);
|
let func_index = module.functions.push(local_sig_index);
|
||||||
module.local.num_imported_funcs = 1;
|
module.num_imported_funcs = 1;
|
||||||
module
|
module
|
||||||
.imports
|
.imports
|
||||||
.push(("".into(), "".into(), EntityIndex::Function(func_index)));
|
.push(("".into(), "".into(), EntityIndex::Function(func_index)));
|
||||||
@@ -59,7 +58,7 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let global_id = module.local.globals.push(global);
|
let global_id = module.globals.push(global);
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("global".to_string(), EntityIndex::Global(global_id));
|
.insert("global".to_string(), EntityIndex::Global(global_id));
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub fn create_handle_with_memory(
|
|||||||
|
|
||||||
let memory_plan =
|
let memory_plan =
|
||||||
wasmtime_environ::MemoryPlan::for_memory(memory, &store.engine().config().tunables);
|
wasmtime_environ::MemoryPlan::for_memory(memory, &store.engine().config().tunables);
|
||||||
let memory_id = module.local.memory_plans.push(memory_plan);
|
let memory_id = module.memory_plans.push(memory_plan);
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("memory".to_string(), EntityIndex::Memory(memory_id));
|
.insert("memory".to_string(), EntityIndex::Memory(memory_id));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub fn create_handle_with_table(store: &Store, table: &TableType) -> Result<Stor
|
|||||||
let tunable = Default::default();
|
let tunable = Default::default();
|
||||||
|
|
||||||
let table_plan = wasmtime_environ::TablePlan::for_table(table, &tunable);
|
let table_plan = wasmtime_environ::TablePlan::for_table(table, &tunable);
|
||||||
let table_id = module.local.table_plans.push(table_plan);
|
let table_id = module.table_plans.push(table_plan);
|
||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("table".to_string(), EntityIndex::Table(table_id));
|
.insert("table".to_string(), EntityIndex::Table(table_id));
|
||||||
|
|||||||
@@ -432,18 +432,16 @@ impl<'module> EntityType<'module> {
|
|||||||
) -> EntityType<'module> {
|
) -> EntityType<'module> {
|
||||||
match entity_index {
|
match entity_index {
|
||||||
EntityIndex::Function(func_index) => {
|
EntityIndex::Function(func_index) => {
|
||||||
let sig = module.local.wasm_func_type(*func_index);
|
let sig = module.wasm_func_type(*func_index);
|
||||||
EntityType::Function(&sig)
|
EntityType::Function(&sig)
|
||||||
}
|
}
|
||||||
EntityIndex::Table(table_index) => {
|
EntityIndex::Table(table_index) => {
|
||||||
EntityType::Table(&module.local.table_plans[*table_index].table)
|
EntityType::Table(&module.table_plans[*table_index].table)
|
||||||
}
|
}
|
||||||
EntityIndex::Memory(memory_index) => {
|
EntityIndex::Memory(memory_index) => {
|
||||||
EntityType::Memory(&module.local.memory_plans[*memory_index].memory)
|
EntityType::Memory(&module.memory_plans[*memory_index].memory)
|
||||||
}
|
|
||||||
EntityIndex::Global(global_index) => {
|
|
||||||
EntityType::Global(&module.local.globals[*global_index])
|
|
||||||
}
|
}
|
||||||
|
EntityIndex::Global(global_index) => EntityType::Global(&module.globals[*global_index]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user