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:
Jakob Stoklund Olesen
2017-09-14 12:25:59 -07:00
parent 78c39ce078
commit 39992014e0
3 changed files with 19 additions and 19 deletions

View File

@@ -47,7 +47,7 @@ impl FuncEnvironment for DummyRuntime {
&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.
let offset = ((index * 8) as i32 + 8).into();
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 {
base: ir::HeapBase::ReservedReg,
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
// signature index arguments.
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];
// A real implementation would probably add a `vmctx` argument.
// And maybe attempt some signature de-duplication.
@@ -87,7 +87,7 @@ impl FuncEnvironment for DummyRuntime {
}
fn translate_call_indirect(
&self,
&mut self,
mut pos: FuncCursor,
_table_index: TableIndex,
_sig_index: SignatureIndex,
@@ -99,7 +99,7 @@ impl FuncEnvironment for DummyRuntime {
}
fn translate_grow_memory(
&self,
&mut self,
mut pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
@@ -109,7 +109,7 @@ impl FuncEnvironment for DummyRuntime {
}
fn translate_current_memory(
&self,
&mut self,
mut pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,

View File

@@ -48,13 +48,13 @@ pub trait FuncEnvironment {
///
/// Return the global variable reference that should be used to access the global and the
/// 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
/// by `index`.
///
/// 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
/// 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
/// 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
/// 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
/// 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`.
///
@@ -90,7 +90,7 @@ pub trait FuncEnvironment {
///
/// Return the call instruction whose results are the WebAssembly return values.
fn translate_call_indirect(
&self,
&mut self,
pos: FuncCursor,
table_index: TableIndex,
sig_index: SignatureIndex,
@@ -107,7 +107,7 @@ pub trait FuncEnvironment {
///
/// Return the call instruction whose results are the WebAssembly return values.
fn translate_call(
&self,
&mut self,
mut pos: FuncCursor,
_callee_index: FunctionIndex,
callee: ir::FuncRef,
@@ -125,7 +125,7 @@ pub trait FuncEnvironment {
///
/// Returns the old size (in pages) of the memory.
fn translate_grow_memory(
&self,
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: ir::Heap,
@@ -139,7 +139,7 @@ pub trait FuncEnvironment {
///
/// Returns the size in pages of the memory.
fn translate_current_memory(
&self,
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: ir::Heap,

View File

@@ -266,7 +266,7 @@ impl TranslationState {
&mut self,
func: &mut ir::Function,
index: u32,
environ: &FE,
environ: &mut FE,
) -> GlobalValue {
let index = index as GlobalIndex;
*self.globals.entry(index).or_insert_with(
@@ -280,7 +280,7 @@ impl TranslationState {
&mut self,
func: &mut ir::Function,
index: u32,
environ: &FE,
environ: &mut FE,
) -> ir::Heap {
let index = index as MemoryIndex;
*self.heaps.entry(index).or_insert_with(
@@ -296,7 +296,7 @@ impl TranslationState {
&mut self,
func: &mut ir::Function,
index: u32,
environ: &FE,
environ: &mut FE,
) -> (ir::SigRef, usize) {
let index = index as SignatureIndex;
*self.signatures.entry(index).or_insert_with(|| {
@@ -313,7 +313,7 @@ impl TranslationState {
&mut self,
func: &mut ir::Function,
index: u32,
environ: &FE,
environ: &mut FE,
) -> (ir::FuncRef, usize) {
let index = index as FunctionIndex;
*self.functions.entry(index).or_insert_with(|| {