[][src]Trait cranelift_wasm::FuncEnvironment

pub trait FuncEnvironment: TargetEnvironment {
    fn is_wasm_parameter(&self, func: &Function, index: usize) -> bool;
fn make_global(
        &mut self,
        func: &mut Function,
        index: GlobalIndex
    ) -> WasmResult<GlobalVariable>;
fn make_heap(
        &mut self,
        func: &mut Function,
        index: MemoryIndex
    ) -> WasmResult<Heap>;
fn make_table(
        &mut self,
        func: &mut Function,
        index: TableIndex
    ) -> WasmResult<Table>;
fn make_indirect_sig(
        &mut self,
        func: &mut Function,
        index: SignatureIndex
    ) -> WasmResult<SigRef>;
fn make_direct_func(
        &mut self,
        func: &mut Function,
        index: FuncIndex
    ) -> WasmResult<FuncRef>;
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>;
fn translate_memory_grow(
        &mut self,
        pos: FuncCursor,
        index: MemoryIndex,
        heap: Heap,
        val: Value
    ) -> WasmResult<Value>;
fn translate_memory_size(
        &mut self,
        pos: FuncCursor,
        index: MemoryIndex,
        heap: Heap
    ) -> WasmResult<Value>;
fn translate_memory_copy(
        &mut self,
        pos: FuncCursor,
        index: MemoryIndex,
        heap: Heap,
        dst: Value,
        src: Value,
        len: Value
    ) -> WasmResult<()>;
fn translate_memory_fill(
        &mut self,
        pos: FuncCursor,
        index: MemoryIndex,
        heap: Heap,
        dst: Value,
        val: Value,
        len: Value
    ) -> WasmResult<()>;
fn translate_memory_init(
        &mut self,
        pos: FuncCursor,
        index: MemoryIndex,
        heap: Heap,
        seg_index: u32,
        dst: Value,
        src: Value,
        len: Value
    ) -> WasmResult<()>;
fn translate_data_drop(
        &mut self,
        pos: FuncCursor,
        seg_index: u32
    ) -> WasmResult<()>;
fn translate_table_size(
        &mut self,
        pos: FuncCursor,
        index: TableIndex,
        table: Table
    ) -> WasmResult<Value>;
fn translate_table_copy(
        &mut self,
        pos: FuncCursor,
        dst_table_index: TableIndex,
        dst_table: Table,
        src_table_index: TableIndex,
        src_table: Table,
        dst: Value,
        src: Value,
        len: Value
    ) -> WasmResult<()>;
fn translate_table_init(
        &mut self,
        pos: FuncCursor,
        seg_index: u32,
        table_index: TableIndex,
        table: Table,
        dst: Value,
        src: Value,
        len: Value
    ) -> WasmResult<()>;
fn translate_elem_drop(
        &mut self,
        pos: FuncCursor,
        seg_index: u32
    ) -> WasmResult<()>; fn return_mode(&self) -> ReturnMode { ... }
fn translate_call(
        &mut self,
        pos: FuncCursor,
        _callee_index: FuncIndex,
        callee: FuncRef,
        call_args: &[Value]
    ) -> WasmResult<Inst> { ... }
fn translate_loop_header(&mut self, _pos: FuncCursor) -> WasmResult<()> { ... }
fn before_translate_operator(
        &mut self,
        _op: &Operator,
        _builder: &mut FunctionBuilder,
        _state: &FuncTranslationState
    ) -> WasmResult<()> { ... }
fn after_translate_operator(
        &mut self,
        _op: &Operator,
        _builder: &mut FunctionBuilder,
        _state: &FuncTranslationState
    ) -> WasmResult<()> { ... } }

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 is_wasm_parameter(&self, func: &Function, index: usize) -> bool

Is the given parameter of the given function a wasm-level parameter, as opposed to a hidden parameter added for use by the implementation?

fn make_global(
    &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>

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>

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>

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>

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>

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>

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>

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.

fn translate_memory_copy(
    &mut self,
    pos: FuncCursor,
    index: MemoryIndex,
    heap: Heap,
    dst: Value,
    src: Value,
    len: Value
) -> WasmResult<()>

Translate a memory.copy 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.

fn translate_memory_fill(
    &mut self,
    pos: FuncCursor,
    index: MemoryIndex,
    heap: Heap,
    dst: Value,
    val: Value,
    len: Value
) -> WasmResult<()>

Translate a memory.fill 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.

fn translate_memory_init(
    &mut self,
    pos: FuncCursor,
    index: MemoryIndex,
    heap: Heap,
    seg_index: u32,
    dst: Value,
    src: Value,
    len: Value
) -> WasmResult<()>

Translate a memory.init 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. seg_index is the index of the segment to copy from.

fn translate_data_drop(
    &mut self,
    pos: FuncCursor,
    seg_index: u32
) -> WasmResult<()>

Translate a data.drop WebAssembly instruction.

fn translate_table_size(
    &mut self,
    pos: FuncCursor,
    index: TableIndex,
    table: Table
) -> WasmResult<Value>

Translate a table.size WebAssembly instruction.

fn translate_table_copy(
    &mut self,
    pos: FuncCursor,
    dst_table_index: TableIndex,
    dst_table: Table,
    src_table_index: TableIndex,
    src_table: Table,
    dst: Value,
    src: Value,
    len: Value
) -> WasmResult<()>

Translate a table.copy WebAssembly instruction.

fn translate_table_init(
    &mut self,
    pos: FuncCursor,
    seg_index: u32,
    table_index: TableIndex,
    table: Table,
    dst: Value,
    src: Value,
    len: Value
) -> WasmResult<()>

Translate a table.init WebAssembly instruction.

fn translate_elem_drop(
    &mut self,
    pos: FuncCursor,
    seg_index: u32
) -> WasmResult<()>

Translate a elem.drop WebAssembly instruction.

Loading content...

Provided methods

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>

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.

fn before_translate_operator(
    &mut self,
    _op: &Operator,
    _builder: &mut FunctionBuilder,
    _state: &FuncTranslationState
) -> WasmResult<()>

Optional callback for the FunctionEnvironment performing this translation to maintain internal state or prepare custom state for the operator to translate

fn after_translate_operator(
    &mut self,
    _op: &Operator,
    _builder: &mut FunctionBuilder,
    _state: &FuncTranslationState
) -> WasmResult<()>

Optional callback for the FunctionEnvironment performing this translation to maintain internal state or finalize custom state for the operator that was translated

Loading content...

Implementors

Loading content...