Make FuncEnvironment callbacks take an &mut self parameter.
The WasmRuntime trait already does this, and nothing in the function translator requires the environment trait object to be non-mutable.
This commit is contained in:
@@ -47,7 +47,7 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
&self.flags
|
&self.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_global(&self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue {
|
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue {
|
||||||
// Just create a dummy `vmctx` global.
|
// Just create a dummy `vmctx` global.
|
||||||
let offset = ((index * 8) as i32 + 8).into();
|
let offset = ((index * 8) as i32 + 8).into();
|
||||||
let gv = func.create_global_var(ir::GlobalVarData::VmCtx { offset });
|
let gv = func.create_global_var(ir::GlobalVarData::VmCtx { offset });
|
||||||
@@ -57,7 +57,7 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_heap(&self, func: &mut ir::Function, _index: MemoryIndex) -> ir::Heap {
|
fn make_heap(&mut self, func: &mut ir::Function, _index: MemoryIndex) -> ir::Heap {
|
||||||
func.create_heap(ir::HeapData {
|
func.create_heap(ir::HeapData {
|
||||||
base: ir::HeapBase::ReservedReg,
|
base: ir::HeapBase::ReservedReg,
|
||||||
min_size: 0.into(),
|
min_size: 0.into(),
|
||||||
@@ -66,13 +66,13 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_indirect_sig(&self, func: &mut ir::Function, index: SignatureIndex) -> ir::SigRef {
|
fn make_indirect_sig(&mut self, func: &mut ir::Function, index: SignatureIndex) -> ir::SigRef {
|
||||||
// A real implementation would probably change the calling convention and add `vmctx` and
|
// A real implementation would probably change the calling convention and add `vmctx` and
|
||||||
// signature index arguments.
|
// signature index arguments.
|
||||||
func.import_signature(self.signatures[index].clone())
|
func.import_signature(self.signatures[index].clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_direct_func(&self, func: &mut ir::Function, index: FunctionIndex) -> ir::FuncRef {
|
fn make_direct_func(&mut self, func: &mut ir::Function, index: FunctionIndex) -> ir::FuncRef {
|
||||||
let sigidx = self.func_types[index];
|
let sigidx = self.func_types[index];
|
||||||
// A real implementation would probably add a `vmctx` argument.
|
// A real implementation would probably add a `vmctx` argument.
|
||||||
// And maybe attempt some signature de-duplication.
|
// And maybe attempt some signature de-duplication.
|
||||||
@@ -87,7 +87,7 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn translate_call_indirect(
|
fn translate_call_indirect(
|
||||||
&self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_table_index: TableIndex,
|
_table_index: TableIndex,
|
||||||
_sig_index: SignatureIndex,
|
_sig_index: SignatureIndex,
|
||||||
@@ -99,7 +99,7 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn translate_grow_memory(
|
fn translate_grow_memory(
|
||||||
&self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_index: MemoryIndex,
|
_index: MemoryIndex,
|
||||||
_heap: ir::Heap,
|
_heap: ir::Heap,
|
||||||
@@ -109,7 +109,7 @@ impl FuncEnvironment for DummyRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn translate_current_memory(
|
fn translate_current_memory(
|
||||||
&self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_index: MemoryIndex,
|
_index: MemoryIndex,
|
||||||
_heap: ir::Heap,
|
_heap: ir::Heap,
|
||||||
|
|||||||
@@ -48,13 +48,13 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// Return the global variable reference that should be used to access the global and the
|
/// Return the global variable reference that should be used to access the global and the
|
||||||
/// WebAssembly type of the global.
|
/// WebAssembly type of the global.
|
||||||
fn make_global(&self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue;
|
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue;
|
||||||
|
|
||||||
/// Set up the necessary preamble definitions in `func` to access the linear memory identified
|
/// Set up the necessary preamble definitions in `func` to access the linear memory identified
|
||||||
/// by `index`.
|
/// by `index`.
|
||||||
///
|
///
|
||||||
/// The index space covers both imported and locally declared memories.
|
/// The index space covers both imported and locally declared memories.
|
||||||
fn make_heap(&self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap;
|
fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap;
|
||||||
|
|
||||||
/// Set up a signature definition in the preamble of `func` that can be used for an indirect
|
/// Set up a signature definition in the preamble of `func` that can be used for an indirect
|
||||||
/// call with signature `index`.
|
/// call with signature `index`.
|
||||||
@@ -65,7 +65,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// The signature will only be used for indirect calls, even if the module has direct function
|
/// The signature will only be used for indirect calls, even if the module has direct function
|
||||||
/// calls with the same WebAssembly type.
|
/// calls with the same WebAssembly type.
|
||||||
fn make_indirect_sig(&self, func: &mut ir::Function, index: SignatureIndex) -> ir::SigRef;
|
fn make_indirect_sig(&mut self, func: &mut ir::Function, index: SignatureIndex) -> ir::SigRef;
|
||||||
|
|
||||||
/// Set up an external function definition in the preamble of `func` that can be used to
|
/// Set up an external function definition in the preamble of `func` that can be used to
|
||||||
/// directly call the function `index`.
|
/// directly call the function `index`.
|
||||||
@@ -78,7 +78,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// The function's signature will only be used for direct calls, even if the module has
|
/// The function's signature will only be used for direct calls, even if the module has
|
||||||
/// indirect calls with the same WebAssembly type.
|
/// indirect calls with the same WebAssembly type.
|
||||||
fn make_direct_func(&self, func: &mut ir::Function, index: FunctionIndex) -> ir::FuncRef;
|
fn make_direct_func(&mut self, func: &mut ir::Function, index: FunctionIndex) -> ir::FuncRef;
|
||||||
|
|
||||||
/// Translate a `call_indirect` WebAssembly instruction at `pos`.
|
/// Translate a `call_indirect` WebAssembly instruction at `pos`.
|
||||||
///
|
///
|
||||||
@@ -90,7 +90,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// Return the call instruction whose results are the WebAssembly return values.
|
/// Return the call instruction whose results are the WebAssembly return values.
|
||||||
fn translate_call_indirect(
|
fn translate_call_indirect(
|
||||||
&self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
sig_index: SignatureIndex,
|
sig_index: SignatureIndex,
|
||||||
@@ -107,7 +107,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// Return the call instruction whose results are the WebAssembly return values.
|
/// Return the call instruction whose results are the WebAssembly return values.
|
||||||
fn translate_call(
|
fn translate_call(
|
||||||
&self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_callee_index: FunctionIndex,
|
_callee_index: FunctionIndex,
|
||||||
callee: ir::FuncRef,
|
callee: ir::FuncRef,
|
||||||
@@ -125,7 +125,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// Returns the old size (in pages) of the memory.
|
/// Returns the old size (in pages) of the memory.
|
||||||
fn translate_grow_memory(
|
fn translate_grow_memory(
|
||||||
&self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
heap: ir::Heap,
|
heap: ir::Heap,
|
||||||
@@ -139,7 +139,7 @@ pub trait FuncEnvironment {
|
|||||||
///
|
///
|
||||||
/// Returns the size in pages of the memory.
|
/// Returns the size in pages of the memory.
|
||||||
fn translate_current_memory(
|
fn translate_current_memory(
|
||||||
&self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
heap: ir::Heap,
|
heap: ir::Heap,
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ impl TranslationState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
index: u32,
|
index: u32,
|
||||||
environ: &FE,
|
environ: &mut FE,
|
||||||
) -> GlobalValue {
|
) -> GlobalValue {
|
||||||
let index = index as GlobalIndex;
|
let index = index as GlobalIndex;
|
||||||
*self.globals.entry(index).or_insert_with(
|
*self.globals.entry(index).or_insert_with(
|
||||||
@@ -280,7 +280,7 @@ impl TranslationState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
index: u32,
|
index: u32,
|
||||||
environ: &FE,
|
environ: &mut FE,
|
||||||
) -> ir::Heap {
|
) -> ir::Heap {
|
||||||
let index = index as MemoryIndex;
|
let index = index as MemoryIndex;
|
||||||
*self.heaps.entry(index).or_insert_with(
|
*self.heaps.entry(index).or_insert_with(
|
||||||
@@ -296,7 +296,7 @@ impl TranslationState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
index: u32,
|
index: u32,
|
||||||
environ: &FE,
|
environ: &mut FE,
|
||||||
) -> (ir::SigRef, usize) {
|
) -> (ir::SigRef, usize) {
|
||||||
let index = index as SignatureIndex;
|
let index = index as SignatureIndex;
|
||||||
*self.signatures.entry(index).or_insert_with(|| {
|
*self.signatures.entry(index).or_insert_with(|| {
|
||||||
@@ -313,7 +313,7 @@ impl TranslationState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
index: u32,
|
index: u32,
|
||||||
environ: &FE,
|
environ: &mut FE,
|
||||||
) -> (ir::FuncRef, usize) {
|
) -> (ir::FuncRef, usize) {
|
||||||
let index = index as FunctionIndex;
|
let index = index as FunctionIndex;
|
||||||
*self.functions.entry(index).or_insert_with(|| {
|
*self.functions.entry(index).or_insert_with(|| {
|
||||||
|
|||||||
Reference in New Issue
Block a user