[−][src]Trait wasmer_clif_fork_wasm::FuncEnvironment
Environment affecting the translation of a single WebAssembly function.
A FuncEnvironment
trait object is required to translate a WebAssembly function to Cranelift
IR. The function environment provides information about the WebAssembly module as well as the
runtime environment.
Required methods
fn target_config(&self) -> TargetFrontendConfig
Get the information needed to produce Cranelift IR for the given target.
fn make_global(
&mut self,
func: &mut Function,
index: GlobalIndex
) -> WasmResult<GlobalVariable>
&mut self,
func: &mut Function,
index: GlobalIndex
) -> WasmResult<GlobalVariable>
Set up the necessary preamble definitions in func
to access the global variable
identified by index
.
The index space covers both imported globals and globals defined by the module.
Return the global variable reference that should be used to access the global and the WebAssembly type of the global.
fn make_heap(
&mut self,
func: &mut Function,
index: MemoryIndex
) -> WasmResult<Heap>
&mut self,
func: &mut Function,
index: MemoryIndex
) -> WasmResult<Heap>
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_table(
&mut self,
func: &mut Function,
index: TableIndex
) -> WasmResult<Table>
&mut self,
func: &mut Function,
index: TableIndex
) -> WasmResult<Table>
Set up the necessary preamble definitions in func
to access the table identified
by index
.
The index space covers both imported and locally declared tables.
fn make_indirect_sig(
&mut self,
func: &mut Function,
index: SignatureIndex
) -> WasmResult<SigRef>
&mut self,
func: &mut Function,
index: SignatureIndex
) -> WasmResult<SigRef>
Set up a signature definition in the preamble of func
that can be used for an indirect
call with signature index
.
The signature may contain additional arguments needed for an indirect call, but the
arguments marked as ArgumentPurpose::Normal
must correspond to the WebAssembly signature
arguments.
The signature will only be used for indirect calls, even if the module has direct function calls with the same WebAssembly type.
fn make_direct_func(
&mut self,
func: &mut Function,
index: FuncIndex
) -> WasmResult<FuncRef>
&mut self,
func: &mut Function,
index: FuncIndex
) -> WasmResult<FuncRef>
Set up an external function definition in the preamble of func
that can be used to
directly call the function index
.
The index space covers both imported functions and functions defined in the current module.
The function's signature may contain additional arguments needed for a direct call, but the
arguments marked as ArgumentPurpose::Normal
must correspond to the WebAssembly signature
arguments.
The function's signature will only be used for direct calls, even if the module has indirect calls with the same WebAssembly type.
fn translate_call_indirect(
&mut self,
pos: FuncCursor,
table_index: TableIndex,
table: Table,
sig_index: SignatureIndex,
sig_ref: SigRef,
callee: Value,
call_args: &[Value]
) -> WasmResult<Inst>
&mut self,
pos: FuncCursor,
table_index: TableIndex,
table: Table,
sig_index: SignatureIndex,
sig_ref: SigRef,
callee: Value,
call_args: &[Value]
) -> WasmResult<Inst>
Translate a call_indirect
WebAssembly instruction at pos
.
Insert instructions at pos
for an indirect call to the function callee
in the table
table_index
with WebAssembly signature sig_index
. The callee
value will have type
i32
.
The signature sig_ref
was previously created by make_indirect_sig()
.
Return the call instruction whose results are the WebAssembly return values.
fn translate_memory_grow(
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: Heap,
val: Value
) -> WasmResult<Value>
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: Heap,
val: Value
) -> WasmResult<Value>
Translate a memory.grow
WebAssembly instruction.
The index
provided identifies the linear memory to grow, and heap
is the heap reference
returned by make_heap
for the same index.
The val
value is the requested memory size in pages.
Returns the old size (in pages) of the memory.
fn translate_memory_size(
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: Heap
) -> WasmResult<Value>
&mut self,
pos: FuncCursor,
index: MemoryIndex,
heap: Heap
) -> WasmResult<Value>
Translates a memory.size
WebAssembly instruction.
The index
provided identifies the linear memory to query, and heap
is the heap reference
returned by make_heap
for the same index.
Returns the size in pages of the memory.
Provided methods
fn pointer_type(&self) -> Type
Get the Cranelift integer type to use for native pointers.
This returns I64
for 64-bit architectures and I32
for 32-bit architectures.
fn pointer_bytes(&self) -> u8
Get the size of a native pointer, in bytes.
fn return_mode(&self) -> ReturnMode
Should the code be structured to use a single fallthrough_return
instruction at the end
of the function body, rather than return
instructions as needed? This is used by VMs
to append custom epilogues.
fn translate_call(
&mut self,
pos: FuncCursor,
_callee_index: FuncIndex,
callee: FuncRef,
call_args: &[Value]
) -> WasmResult<Inst>
&mut self,
pos: FuncCursor,
_callee_index: FuncIndex,
callee: FuncRef,
call_args: &[Value]
) -> WasmResult<Inst>
Translate a call
WebAssembly instruction at pos
.
Insert instructions at pos
for a direct call to the function callee_index
.
The function reference callee
was previously created by make_direct_func()
.
Return the call instruction whose results are the WebAssembly return values.
fn translate_loop_header(&mut self, _pos: FuncCursor) -> WasmResult<()>
Emit code at the beginning of every wasm loop.
This can be used to insert explicit interrupt or safepoint checking at the beginnings of loops.