Rename the address field of Table/Memory/Global exports to definition.

For functions, `address` makes sense because it's the address of the
function. Bt for Table/Memory/Global, it points to a `VM*Definition` field.
This commit is contained in:
Dan Gohman
2018-12-24 18:20:15 -08:00
parent 8f74c7f3d5
commit 71c0142cd4
4 changed files with 31 additions and 27 deletions

View File

@@ -213,12 +213,12 @@ impl InstancePlus {
start: usize, start: usize,
len: usize, len: usize,
) -> Result<&[u8], ActionError> { ) -> Result<&[u8], ActionError> {
let address = match unsafe { self.instance.lookup_immutable(memory_name) } { let definition = match unsafe { self.instance.lookup_immutable(memory_name) } {
Some(Export::Memory { Some(Export::Memory {
address, definition,
memory: _memory, memory: _memory,
vmctx: _vmctx, vmctx: _vmctx,
}) => address, }) => definition,
Some(_) => { Some(_) => {
return Err(ActionError::Kind(format!( return Err(ActionError::Kind(format!(
"exported item \"{}\" is not a linear memory", "exported item \"{}\" is not a linear memory",
@@ -234,15 +234,15 @@ impl InstancePlus {
}; };
Ok(unsafe { Ok(unsafe {
let memory_def = &*address; let memory_def = &*definition;
&slice::from_raw_parts(memory_def.base, memory_def.current_length)[start..start + len] &slice::from_raw_parts(memory_def.base, memory_def.current_length)[start..start + len]
}) })
} }
/// Read a global in this `Instance` identified by an export name. /// Read a global in this `Instance` identified by an export name.
pub fn get(&self, global_name: &str) -> Result<RuntimeValue, ActionError> { pub fn get(&self, global_name: &str) -> Result<RuntimeValue, ActionError> {
let (address, global) = match unsafe { self.instance.lookup_immutable(global_name) } { let (definition, global) = match unsafe { self.instance.lookup_immutable(global_name) } {
Some(Export::Global { address, global }) => (address, global), Some(Export::Global { definition, global }) => (definition, global),
Some(_) => { Some(_) => {
return Err(ActionError::Kind(format!( return Err(ActionError::Kind(format!(
"exported item \"{}\" is not a global variable", "exported item \"{}\" is not a global variable",
@@ -258,7 +258,7 @@ impl InstancePlus {
}; };
unsafe { unsafe {
let global_def = &*address; let global_def = &*definition;
Ok(match global.ty { Ok(match global.ty {
ir::types::I32 => RuntimeValue::I32(*global_def.as_i32()), ir::types::I32 => RuntimeValue::I32(*global_def.as_i32()),
ir::types::I64 => RuntimeValue::I64(*global_def.as_i64()), ir::types::I64 => RuntimeValue::I64(*global_def.as_i64()),

View File

@@ -71,7 +71,7 @@ pub fn link_module(
match resolver.resolve(module_name, field) { match resolver.resolve(module_name, field) {
Some(export_value) => match export_value { Some(export_value) => match export_value {
Export::Table { Export::Table {
address, definition,
vmctx, vmctx,
table, table,
} => { } => {
@@ -83,7 +83,7 @@ pub fn link_module(
))); )));
} }
table_imports.push(VMTableImport { table_imports.push(VMTableImport {
from: address, from: definition,
vmctx, vmctx,
}); });
} }
@@ -108,7 +108,7 @@ pub fn link_module(
match resolver.resolve(module_name, field) { match resolver.resolve(module_name, field) {
Some(export_value) => match export_value { Some(export_value) => match export_value {
Export::Memory { Export::Memory {
address, definition,
vmctx, vmctx,
memory, memory,
} => { } => {
@@ -136,7 +136,7 @@ pub fn link_module(
assert!(memory.offset_guard_size >= import_memory.offset_guard_size); assert!(memory.offset_guard_size >= import_memory.offset_guard_size);
memory_imports.push(VMMemoryImport { memory_imports.push(VMMemoryImport {
from: address, from: definition,
vmctx, vmctx,
}); });
} }
@@ -160,7 +160,7 @@ pub fn link_module(
for (index, (ref module_name, ref field)) in module.imported_globals.iter() { for (index, (ref module_name, ref field)) in module.imported_globals.iter() {
match resolver.resolve(module_name, field) { match resolver.resolve(module_name, field) {
Some(export_value) => match export_value { Some(export_value) => match export_value {
Export::Global { address, global } => { Export::Global { definition, global } => {
let imported_global = module.globals[index]; let imported_global = module.globals[index];
if !is_global_compatible(&global, &imported_global) { if !is_global_compatible(&global, &imported_global) {
return Err(LinkError(format!( return Err(LinkError(format!(
@@ -168,7 +168,7 @@ pub fn link_module(
module_name, field module_name, field
))); )));
} }
global_imports.push(VMGlobalImport { from: address }); global_imports.push(VMGlobalImport { from: definition });
} }
Export::Table { .. } | Export::Memory { .. } | Export::Function { .. } => { Export::Table { .. } | Export::Memory { .. } | Export::Function { .. } => {
return Err(LinkError(format!( return Err(LinkError(format!(

View File

@@ -21,7 +21,7 @@ pub enum Export {
/// A table export value. /// A table export value.
Table { Table {
/// The address of the table descriptor. /// The address of the table descriptor.
address: *mut VMTableDefinition, definition: *mut VMTableDefinition,
/// Pointer to the containing VMContext. /// Pointer to the containing VMContext.
vmctx: *mut VMContext, vmctx: *mut VMContext,
/// The table declaration, used for compatibilty checking. /// The table declaration, used for compatibilty checking.
@@ -31,7 +31,7 @@ pub enum Export {
/// A memory export value. /// A memory export value.
Memory { Memory {
/// The address of the memory descriptor. /// The address of the memory descriptor.
address: *mut VMMemoryDefinition, definition: *mut VMMemoryDefinition,
/// Pointer to the containing VMContext. /// Pointer to the containing VMContext.
vmctx: *mut VMContext, vmctx: *mut VMContext,
/// The memory declaration, used for compatibilty checking. /// The memory declaration, used for compatibilty checking.
@@ -41,7 +41,7 @@ pub enum Export {
/// A global export value. /// A global export value.
Global { Global {
/// The address of the global storage. /// The address of the global storage.
address: *mut VMGlobalDefinition, definition: *mut VMGlobalDefinition,
/// The global declaration, used for compatibilty checking. /// The global declaration, used for compatibilty checking.
global: Global, global: Global,
}, },
@@ -62,9 +62,13 @@ impl Export {
} }
/// Construct a table export value. /// Construct a table export value.
pub fn table(address: *mut VMTableDefinition, vmctx: *mut VMContext, table: TablePlan) -> Self { pub fn table(
definition: *mut VMTableDefinition,
vmctx: *mut VMContext,
table: TablePlan,
) -> Self {
Export::Table { Export::Table {
address, definition,
vmctx, vmctx,
table, table,
} }
@@ -72,19 +76,19 @@ impl Export {
/// Construct a memory export value. /// Construct a memory export value.
pub fn memory( pub fn memory(
address: *mut VMMemoryDefinition, definition: *mut VMMemoryDefinition,
vmctx: *mut VMContext, vmctx: *mut VMContext,
memory: MemoryPlan, memory: MemoryPlan,
) -> Self { ) -> Self {
Export::Memory { Export::Memory {
address, definition,
vmctx, vmctx,
memory, memory,
} }
} }
/// Construct a global export value. /// Construct a global export value.
pub fn global(address: *mut VMGlobalDefinition, global: Global) -> Self { pub fn global(definition: *mut VMGlobalDefinition, global: Global) -> Self {
Export::Global { address, global } Export::Global { definition, global }
} }
} }

View File

@@ -260,7 +260,7 @@ impl Instance {
} }
} }
wasmtime_environ::Export::Table(index) => { wasmtime_environ::Export::Table(index) => {
let (address, vmctx) = if let Some(def_index) = let (definition, vmctx) = if let Some(def_index) =
self.module.defined_table_index(*index) self.module.defined_table_index(*index)
{ {
( (
@@ -272,13 +272,13 @@ impl Instance {
(import.from, import.vmctx) (import.from, import.vmctx)
}; };
Export::Table { Export::Table {
address, definition,
vmctx, vmctx,
table: self.module.table_plans[*index].clone(), table: self.module.table_plans[*index].clone(),
} }
} }
wasmtime_environ::Export::Memory(index) => { wasmtime_environ::Export::Memory(index) => {
let (address, vmctx) = if let Some(def_index) = let (definition, vmctx) = if let Some(def_index) =
self.module.defined_memory_index(*index) self.module.defined_memory_index(*index)
{ {
( (
@@ -290,13 +290,13 @@ impl Instance {
(import.from, import.vmctx) (import.from, import.vmctx)
}; };
Export::Memory { Export::Memory {
address, definition,
vmctx, vmctx,
memory: self.module.memory_plans[*index].clone(), memory: self.module.memory_plans[*index].clone(),
} }
} }
wasmtime_environ::Export::Global(index) => Export::Global { wasmtime_environ::Export::Global(index) => Export::Global {
address: if let Some(def_index) = self.module.defined_global_index(*index) { definition: if let Some(def_index) = self.module.defined_global_index(*index) {
unsafe { self.vmctx.global_mut(def_index) } unsafe { self.vmctx.global_mut(def_index) }
} else { } else {
unsafe { self.vmctx.imported_global(*index).from } unsafe { self.vmctx.imported_global(*index).from }