Update to Cranelift 0.24.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use cranelift_codegen::binemit::Reloc;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||
use cranelift_wasm::{DefinedFuncIndex, MemoryIndex};
|
||||
use cranelift_wasm::{DefinedFuncIndex, MemoryIndex, TableIndex};
|
||||
use instance::Instance;
|
||||
use memory::LinearMemory;
|
||||
use region::protect;
|
||||
@@ -87,7 +87,7 @@ extern "C" fn grow_memory(size: u32, memory_index: u32, vmctx: *mut *mut u8) ->
|
||||
// FIXME: update the VMMemory's size
|
||||
let instance = (*vmctx.offset(4)) as *mut Instance;
|
||||
(*instance)
|
||||
.memory_mut(memory_index as MemoryIndex)
|
||||
.memory_mut(MemoryIndex::new(memory_index as usize))
|
||||
.grow(size)
|
||||
.unwrap_or(u32::max_value())
|
||||
}
|
||||
@@ -98,7 +98,7 @@ extern "C" fn current_memory(memory_index: u32, vmctx: *mut *mut u8) -> u32 {
|
||||
// FIXME: read the VMMemory's size instead
|
||||
let instance = (*vmctx.offset(4)) as *mut Instance;
|
||||
(*instance)
|
||||
.memory_mut(memory_index as MemoryIndex)
|
||||
.memory_mut(MemoryIndex::new(memory_index as usize))
|
||||
.current_size()
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ fn make_vmctx(instance: &mut Instance, mem_base_addrs: &mut [*mut u8]) -> Vec<*m
|
||||
|
||||
let (default_table_ptr, default_table_len) = instance
|
||||
.tables
|
||||
.get_mut(0)
|
||||
.get_mut(TableIndex::new(0))
|
||||
.map(|table| (table.as_mut_ptr() as *mut u8, table.len()))
|
||||
.unwrap_or((ptr::null_mut(), 0));
|
||||
|
||||
@@ -167,7 +167,7 @@ pub fn execute(
|
||||
// Collect all memory base addresses and Vec.
|
||||
let mut mem_base_addrs = instance
|
||||
.memories
|
||||
.iter_mut()
|
||||
.values_mut()
|
||||
.map(LinearMemory::base_addr)
|
||||
.collect::<Vec<_>>();
|
||||
let vmctx = make_vmctx(instance, &mut mem_base_addrs);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
//! module.
|
||||
|
||||
use cranelift_codegen::ir;
|
||||
use cranelift_wasm::GlobalIndex;
|
||||
use cranelift_entity::EntityRef;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{GlobalIndex, MemoryIndex, TableIndex};
|
||||
use memory::LinearMemory;
|
||||
use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
|
||||
|
||||
@@ -10,10 +12,10 @@ use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
|
||||
#[derive(Debug)]
|
||||
pub struct Instance {
|
||||
/// WebAssembly table data.
|
||||
pub tables: Vec<Vec<usize>>,
|
||||
pub tables: PrimaryMap<TableIndex, Vec<usize>>,
|
||||
|
||||
/// WebAssembly linear memory data.
|
||||
pub memories: Vec<LinearMemory>,
|
||||
pub memories: PrimaryMap<MemoryIndex, LinearMemory>,
|
||||
|
||||
/// WebAssembly global variable data.
|
||||
pub globals: Vec<u8>,
|
||||
@@ -27,8 +29,8 @@ impl Instance {
|
||||
data_initializers: &[DataInitializer],
|
||||
) -> Self {
|
||||
let mut result = Self {
|
||||
tables: Vec::new(),
|
||||
memories: Vec::new(),
|
||||
tables: PrimaryMap::new(),
|
||||
memories: PrimaryMap::new(),
|
||||
globals: Vec::new(),
|
||||
};
|
||||
result.instantiate_tables(module, compilation, &module.table_elements);
|
||||
@@ -45,8 +47,9 @@ impl Instance {
|
||||
table_initializers: &[TableElements],
|
||||
) {
|
||||
debug_assert!(self.tables.is_empty());
|
||||
self.tables.reserve_exact(module.tables.len());
|
||||
for table in &module.tables {
|
||||
// TODO: Enable this once PrimaryMap supports this.
|
||||
//self.tables.reserve_exact(module.tables.len());
|
||||
for table in module.tables.values() {
|
||||
let len = table.size;
|
||||
let mut v = Vec::with_capacity(len);
|
||||
v.resize(len, 0);
|
||||
@@ -69,8 +72,9 @@ impl Instance {
|
||||
fn instantiate_memories(&mut self, module: &Module, data_initializers: &[DataInitializer]) {
|
||||
debug_assert!(self.memories.is_empty());
|
||||
// Allocate the underlying memory and initialize it to all zeros.
|
||||
self.memories.reserve_exact(module.memories.len());
|
||||
for memory in &module.memories {
|
||||
// TODO: Enable this once PrimaryMap supports it.
|
||||
//self.memories.reserve_exact(module.memories.len());
|
||||
for memory in module.memories.values() {
|
||||
let v = LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32));
|
||||
self.memories.push(v);
|
||||
}
|
||||
@@ -92,24 +96,24 @@ impl Instance {
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to a linear memory under the specified index.
|
||||
pub fn memory_mut(&mut self, memory_index: usize) -> &mut LinearMemory {
|
||||
pub fn memory_mut(&mut self, memory_index: MemoryIndex) -> &mut LinearMemory {
|
||||
self.memories
|
||||
.get_mut(memory_index)
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index))
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index.index()))
|
||||
}
|
||||
|
||||
/// Returns a slice of the contents of allocated linear memory.
|
||||
pub fn inspect_memory(&self, memory_index: usize, address: usize, len: usize) -> &[u8] {
|
||||
pub fn inspect_memory(&self, memory_index: MemoryIndex, address: usize, len: usize) -> &[u8] {
|
||||
&self
|
||||
.memories
|
||||
.get(memory_index)
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index))
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index.index()))
|
||||
.as_ref()[address..address + len]
|
||||
}
|
||||
|
||||
/// Shows the value of a global variable.
|
||||
pub fn inspect_global(&self, global_index: GlobalIndex, ty: ir::Type) -> &[u8] {
|
||||
let offset = global_index * 8;
|
||||
let offset = global_index.index() * 8;
|
||||
let len = ty.bytes() as usize;
|
||||
&self.globals[offset..offset + len]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user