mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Renamed table_elements to table_initializers
This commit is contained in:
@@ -16,7 +16,7 @@ use wasm_common::{
|
|||||||
ExportIndex, FunctionIndex, GlobalIndex, GlobalInit, GlobalType, ImportIndex,
|
ExportIndex, FunctionIndex, GlobalIndex, GlobalInit, GlobalType, ImportIndex,
|
||||||
LocalFunctionIndex, MemoryIndex, MemoryType, SignatureIndex, TableIndex, TableType,
|
LocalFunctionIndex, MemoryIndex, MemoryType, SignatureIndex, TableIndex, TableType,
|
||||||
};
|
};
|
||||||
use wasmer_vm::{ModuleInfo, TableElements};
|
use wasmer_vm::{ModuleInfo, TableInitializer};
|
||||||
|
|
||||||
/// Contains function data: bytecode and its offset in the module.
|
/// Contains function data: bytecode and its offset in the module.
|
||||||
#[derive(Hash)]
|
#[derive(Hash)]
|
||||||
@@ -322,27 +322,30 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn reserve_table_elements(&mut self, num: u32) -> WasmResult<()> {
|
pub(crate) fn reserve_table_initializers(&mut self, num: u32) -> WasmResult<()> {
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.table_elements
|
.table_initializers
|
||||||
.reserve_exact(usize::try_from(num).unwrap());
|
.reserve_exact(usize::try_from(num).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn declare_table_elements(
|
pub(crate) fn declare_table_initializers(
|
||||||
&mut self,
|
&mut self,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
base: Option<GlobalIndex>,
|
base: Option<GlobalIndex>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
elements: Box<[FunctionIndex]>,
|
elements: Box<[FunctionIndex]>,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
self.result.module.table_elements.push(TableElements {
|
self.result
|
||||||
table_index,
|
.module
|
||||||
base,
|
.table_initializers
|
||||||
offset,
|
.push(TableInitializer {
|
||||||
elements,
|
table_index,
|
||||||
});
|
base,
|
||||||
|
offset,
|
||||||
|
elements,
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ pub fn parse_element_section<'data>(
|
|||||||
elements: ElementSectionReader<'data>,
|
elements: ElementSectionReader<'data>,
|
||||||
environ: &mut ModuleEnvironment,
|
environ: &mut ModuleEnvironment,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
environ.reserve_table_elements(elements.get_count())?;
|
environ.reserve_table_initializers(elements.get_count())?;
|
||||||
|
|
||||||
for (index, entry) in elements.into_iter().enumerate() {
|
for (index, entry) in elements.into_iter().enumerate() {
|
||||||
let Element { kind, items, ty } = entry.map_err(to_wasm_error)?;
|
let Element { kind, items, ty } = entry.map_err(to_wasm_error)?;
|
||||||
@@ -342,7 +342,7 @@ pub fn parse_element_section<'data>(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
environ.declare_table_elements(
|
environ.declare_table_initializers(
|
||||||
TableIndex::from_u32(table_index),
|
TableIndex::from_u32(table_index),
|
||||||
base,
|
base,
|
||||||
offset,
|
offset,
|
||||||
|
|||||||
@@ -483,7 +483,7 @@ struct ModuleInfo {
|
|||||||
passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
||||||
signatures: PrimaryMap<SignatureIndex, FunctionType>,
|
signatures: PrimaryMap<SignatureIndex, FunctionType>,
|
||||||
start_func: Option<FunctionIndex>,
|
start_func: Option<FunctionIndex>,
|
||||||
table_elements: Vec<TableElements>,
|
table_initializers: Vec<TableInitializer>,
|
||||||
tables: PrimaryMap<TableIndex, TableType>,
|
tables: PrimaryMap<TableIndex, TableType>,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ struct ModuleInfo {
|
|||||||
passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
||||||
signatures: PrimaryMap<SignatureIndex, FunctionType>,
|
signatures: PrimaryMap<SignatureIndex, FunctionType>,
|
||||||
start_func: Option<FunctionIndex>,
|
start_func: Option<FunctionIndex>,
|
||||||
table_elements: Vec<TableElements>,
|
table_initializers: Vec<TableInitializer>,
|
||||||
tables: PrimaryMap<TableIndex, TableType>,
|
tables: PrimaryMap<TableIndex, TableType>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub use new::wasmer_vm::{
|
|||||||
//
|
//
|
||||||
MemoryStyle as MemoryType,
|
MemoryStyle as MemoryType,
|
||||||
ModuleInfo,
|
ModuleInfo,
|
||||||
TableElements as TableInitializer,
|
TableInitializer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A compiled WebAssembly module.
|
/// A compiled WebAssembly module.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use crate::vmcontext::{
|
|||||||
VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
|
VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
|
||||||
};
|
};
|
||||||
use crate::{ExportFunction, ExportGlobal, ExportMemory, ExportTable};
|
use crate::{ExportFunction, ExportGlobal, ExportMemory, ExportTable};
|
||||||
use crate::{FunctionBodyPtr, ModuleInfo, TableElements, VMOffsets};
|
use crate::{FunctionBodyPtr, ModuleInfo, TableInitializer, VMOffsets};
|
||||||
use memoffset::offset_of;
|
use memoffset::offset_of;
|
||||||
use more_asserts::assert_lt;
|
use more_asserts::assert_lt;
|
||||||
use std::alloc::{self, Layout};
|
use std::alloc::{self, Layout};
|
||||||
@@ -1099,7 +1099,7 @@ impl Clone for InstanceHandle {
|
|||||||
|
|
||||||
fn check_table_init_bounds(instance: &Instance) -> Result<(), Trap> {
|
fn check_table_init_bounds(instance: &Instance) -> Result<(), Trap> {
|
||||||
let module = Arc::clone(&instance.module);
|
let module = Arc::clone(&instance.module);
|
||||||
for init in &module.table_elements {
|
for init in &module.table_initializers {
|
||||||
let start = get_table_init_start(init, instance);
|
let start = get_table_init_start(init, instance);
|
||||||
let table = instance.get_table(init.table_index);
|
let table = instance.get_table(init.table_index);
|
||||||
|
|
||||||
@@ -1166,7 +1166,7 @@ fn check_memory_init_bounds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compute the offset for a table element initializer.
|
/// Compute the offset for a table element initializer.
|
||||||
fn get_table_init_start(init: &TableElements, instance: &Instance) -> usize {
|
fn get_table_init_start(init: &TableInitializer, instance: &Instance) -> usize {
|
||||||
let mut start = init.offset;
|
let mut start = init.offset;
|
||||||
|
|
||||||
if let Some(base) = init.base {
|
if let Some(base) = init.base {
|
||||||
@@ -1186,7 +1186,7 @@ fn get_table_init_start(init: &TableElements, instance: &Instance) -> usize {
|
|||||||
/// Initialize the table memory from the provided initializers.
|
/// Initialize the table memory from the provided initializers.
|
||||||
fn initialize_tables(instance: &Instance) -> Result<(), Trap> {
|
fn initialize_tables(instance: &Instance) -> Result<(), Trap> {
|
||||||
let module = Arc::clone(&instance.module);
|
let module = Arc::clone(&instance.module);
|
||||||
for init in &module.table_elements {
|
for init in &module.table_initializers {
|
||||||
let start = get_table_init_start(init, instance);
|
let start = get_table_init_start(init, instance);
|
||||||
let table = instance.get_table(init.table_index);
|
let table = instance.get_table(init.table_index);
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ pub use crate::mmap::Mmap;
|
|||||||
pub use crate::module::{ExportsIterator, ImportsIterator, ModuleInfo};
|
pub use crate::module::{ExportsIterator, ImportsIterator, ModuleInfo};
|
||||||
pub use crate::probestack::PROBESTACK;
|
pub use crate::probestack::PROBESTACK;
|
||||||
pub use crate::sig_registry::SignatureRegistry;
|
pub use crate::sig_registry::SignatureRegistry;
|
||||||
pub use crate::table::{LinearTable, Table, TableElements, TableStyle};
|
pub use crate::table::{LinearTable, Table, TableInitializer, TableStyle};
|
||||||
pub use crate::trap::*;
|
pub use crate::trap::*;
|
||||||
pub use crate::vmcontext::{
|
pub use crate::vmcontext::{
|
||||||
VMBuiltinFunctionIndex, VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext,
|
VMBuiltinFunctionIndex, VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//! Data structure for representing WebAssembly modules
|
//! Data structure for representing WebAssembly modules
|
||||||
//! in a [`Module`].
|
//! in a [`Module`].
|
||||||
|
|
||||||
use crate::table::TableElements;
|
use crate::table::TableInitializer;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -68,7 +68,7 @@ pub struct ModuleInfo {
|
|||||||
pub start_func: Option<FunctionIndex>,
|
pub start_func: Option<FunctionIndex>,
|
||||||
|
|
||||||
/// WebAssembly table initializers.
|
/// WebAssembly table initializers.
|
||||||
pub table_elements: Vec<TableElements>,
|
pub table_initializers: Vec<TableInitializer>,
|
||||||
|
|
||||||
/// WebAssembly passive elements.
|
/// WebAssembly passive elements.
|
||||||
pub passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
pub passive_elements: HashMap<ElemIndex, Box<[FunctionIndex]>>,
|
||||||
@@ -125,7 +125,7 @@ impl ModuleInfo {
|
|||||||
imports: IndexMap::new(),
|
imports: IndexMap::new(),
|
||||||
exports: IndexMap::new(),
|
exports: IndexMap::new(),
|
||||||
start_func: None,
|
start_func: None,
|
||||||
table_elements: Vec::new(),
|
table_initializers: Vec::new(),
|
||||||
passive_elements: HashMap::new(),
|
passive_elements: HashMap::new(),
|
||||||
passive_data: HashMap::new(),
|
passive_data: HashMap::new(),
|
||||||
global_initializers: PrimaryMap::new(),
|
global_initializers: PrimaryMap::new(),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use wasm_common::{FunctionIndex, GlobalIndex, TableIndex, TableType, Type as Val
|
|||||||
|
|
||||||
/// A WebAssembly table initializer.
|
/// A WebAssembly table initializer.
|
||||||
#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
|
||||||
pub struct TableElements {
|
pub struct TableInitializer {
|
||||||
/// The index of a table to initialize.
|
/// The index of a table to initialize.
|
||||||
pub table_index: TableIndex,
|
pub table_index: TableIndex,
|
||||||
/// Optionally, a global variable giving a base index.
|
/// Optionally, a global variable giving a base index.
|
||||||
|
|||||||
Reference in New Issue
Block a user