Fix broken reference

This commit is contained in:
Lachlan Sneff
2019-01-18 14:18:06 -08:00
parent 4f8e567d91
commit c34df39095
5 changed files with 21 additions and 14 deletions

View File

@ -351,9 +351,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
let mut func = ir::Function::with_name_signature(name, sig);
println!("translating function");
func_translator.translate(body_bytes, &mut func, &mut func_env)?;
println!("done translating function");
func
};

View File

@ -4,7 +4,7 @@ use wasmer_runtime::{import::Imports, Instance};
fn main() {
let mut instance = create_module_1();
let result = instance.call("get-0", &[]);
let result = instance.call("call-overwritten-element", &[]);
println!("result: {:?}", result);
}
@ -20,14 +20,17 @@ fn main() {
fn create_module_1() -> Instance {
let module_str = r#"(module
(type (;0;) (func (result i32)))
(import "spectest" "global_i32" (global (;0;) i32))
(import "spectest" "table" (table (;0;) 10 anyfunc))
(func (;0;) (type 0) (result i32)
get_global 0)
i32.const 65)
(func (;1;) (type 0) (result i32)
get_global 1)
(global (;1;) i32 (get_global 0))
(export "get-0" (func 0))
(export "get-0-ref" (func 1)))
i32.const 66)
(func (;2;) (type 0) (result i32)
i32.const 9
call_indirect (type 0))
(export "call-overwritten-element" (func 2))
(elem (;0;) (i32.const 9) 0)
(elem (;1;) (i32.const 9) 1))
"#;
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new())

View File

@ -307,29 +307,34 @@ impl ImportBacking {
imports: &mut Imports,
vmctx: *mut vm::Ctx,
) -> LinkResult<Self> {
let mut failed = false;
let mut link_errors = vec![];
let functions = import_functions(module, imports, vmctx).unwrap_or_else(|le| {
failed = true;
link_errors.extend(le);
Map::new().into_boxed_map()
});
let memories = import_memories(module, imports, vmctx).unwrap_or_else(|le| {
failed = true;
link_errors.extend(le);
Map::new().into_boxed_map()
});
let tables = import_tables(module, imports, vmctx).unwrap_or_else(|le| {
failed = true;
link_errors.extend(le);
Map::new().into_boxed_map()
});
let globals = import_globals(module, imports).unwrap_or_else(|le| {
failed = true;
link_errors.extend(le);
Map::new().into_boxed_map()
});
if link_errors.len() > 0 {
if failed {
Err(link_errors)
} else {
Ok(ImportBacking {

View File

@ -248,9 +248,9 @@ impl InstanceInner {
) -> (MemoryPointer, Context, Memory) {
match mem_index.local_or_import(module) {
LocalOrImport::Local(local_mem_index) => {
let vm_mem = &mut self.backing.memories[local_mem_index];
let vm_mem = &mut self.backing.vm_memories[local_mem_index];
(
unsafe { MemoryPointer::new(&mut vm_mem.into_vm_memory(local_mem_index)) },
unsafe { MemoryPointer::new(vm_mem) },
Context::Internal,
*module
.memories
@ -313,9 +313,9 @@ impl InstanceInner {
) -> (TablePointer, Context, Table) {
match table_index.local_or_import(module) {
LocalOrImport::Local(local_table_index) => {
let vm_table = &mut self.backing.tables[local_table_index];
let vm_table = &mut self.backing.vm_tables[local_table_index];
(
unsafe { TablePointer::new(&mut vm_table.into_vm_table()) },
unsafe { TablePointer::new(vm_table) },
Context::Internal,
*module
.tables

View File

@ -7,6 +7,7 @@ use std::{
/// This is a dynamically-sized slice
/// that can only be indexed by the
/// correct index type.
#[derive(Debug)]
pub struct SliceMap<K, V>
where
K: TypedIndex,