pub struct Function {
pub backtrace: Backtrace,
pub control: ControlStack,
pub env: Env,
pub locals: Locals,
pub masm: MacroAssembler,
pub table: JumpTable,
pub ty: FuncType,
pub is_main: bool,
}
Expand description
The code generation abstraction.
Fields§
§backtrace: Backtrace
The backtrace.
control: ControlStack
Control stack frames.
env: Env
WASM environment.
locals: Locals
The defined locals for a function.
masm: MacroAssembler
The macro assembler.
table: JumpTable
The jump table.
ty: FuncType
The function type.
is_main: bool
If this function is the main function.
Implementations§
source§impl Function
impl Function
sourcepub fn emit_locals(
&mut self,
locals: &mut LocalsReader<'_>,
validator: &mut FuncValidator<ValidatorResources>
) -> Result<()>
pub fn emit_locals( &mut self, locals: &mut LocalsReader<'_>, validator: &mut FuncValidator<ValidatorResources> ) -> Result<()>
Emit function locals
- the function parameters.
- function body locals.
NOTE: we don’t care about the origin offset of the locals. bcz we will serialize the locals to an index map anyway.
sourcepub fn emit_operators(
&mut self,
ops: &mut OperatorsReader<'_>,
validator: &mut FuncValidator<ValidatorResources>
) -> Result<()>
pub fn emit_operators( &mut self, ops: &mut OperatorsReader<'_>, validator: &mut FuncValidator<ValidatorResources> ) -> Result<()>
Emit function operators.
source§impl Function
impl Function
sourcepub fn _call_indirect(
&mut self,
_type_index: u32,
_table_index: u32,
_table_byte: u8
) -> Result<()>
pub fn _call_indirect( &mut self, _type_index: u32, _table_index: u32, _table_byte: u8 ) -> Result<()>
The call indirect instruction calls a function indirectly through an operand indexing into a table.
sourcepub fn _call(&mut self, index: u32) -> Result<()>
pub fn _call(&mut self, index: u32) -> Result<()>
The call instruction calls a function specified by its index.
sourcefn call_internal(&mut self, index: u32) -> Result<()>
fn call_internal(&mut self, index: u32) -> Result<()>
Call internal functions
sourcefn call_imported(&mut self, index: u32) -> Result<()>
fn call_imported(&mut self, index: u32) -> Result<()>
Call imported functions
source§impl Function
impl Function
sourcepub fn _if(&mut self, blockty: BlockType) -> Result<()>
pub fn _if(&mut self, blockty: BlockType) -> Result<()>
The beginning of an if construct with an implicit block.
sourcepub fn _block(&mut self, blockty: BlockType) -> Result<()>
pub fn _block(&mut self, blockty: BlockType) -> Result<()>
The begeinning of a block construct. A sequence of instructions with a label at the end.
sourcepub fn _loop(&mut self, blockty: BlockType) -> Result<()>
pub fn _loop(&mut self, blockty: BlockType) -> Result<()>
A block with a label which may be used to form loops.
sourcepub fn _select(&mut self) -> Result<()>
pub fn _select(&mut self) -> Result<()>
The select instruction selects one of its first two operands based on whether its third oprand is zero or not.
STACK: [cond, val2, val1] -> [val1] if cond is non-zero, [val2] otherwise.
sourcepub fn _br(&mut self, _depth: u32) -> Result<()>
pub fn _br(&mut self, _depth: u32) -> Result<()>
Branch to a given label in an enclosing construct.
Performs an unconditional branch.
sourcepub fn _br_if(&mut self, depth: u32) -> Result<()>
pub fn _br_if(&mut self, depth: u32) -> Result<()>
Performs a conditional branch if i32 is non-zero.
Conditional branch to a given label in an enclosing construct.
sourcepub fn _br_table(&mut self, _table: BrTable<'_>) -> Result<()>
pub fn _br_table(&mut self, _table: BrTable<'_>) -> Result<()>
A jump table which jumps to a label in an enclosing construct.
Performs an indirect branch through an operand indexing into the label vector that is an immediate to the instruction, or to the default target if the operand is out of bounds.
sourcepub fn _end(&mut self) -> Result<()>
pub fn _end(&mut self) -> Result<()>
Handle the end of instructions for different situations.
TODO: (#28)
- End of control flow operators.
- End of function.
- End of program.
sourcepub fn _unreachable(&mut self) -> Result<()>
pub fn _unreachable(&mut self) -> Result<()>
Mark as invalid for now.
TODO: recheck this implementation, if it is okay, provide more docs.
source§impl Function
impl Function
sourcepub(crate) fn handle_return(&mut self) -> Result<()>
pub(crate) fn handle_return(&mut self) -> Result<()>
Handle the end of the function.
sourcepub(crate) fn handle_call_return(&mut self) -> Result<()>
pub(crate) fn handle_call_return(&mut self) -> Result<()>
Handle the return of a call.
sourcepub(crate) fn handle_frame_popping(
&mut self,
frame: ControlStackFrame
) -> Result<()>
pub(crate) fn handle_frame_popping( &mut self, frame: ControlStackFrame ) -> Result<()>
Handle the popping of a frame.
TODO: validate stack IO for all frames (#59)
sourcepub(crate) fn handle_jumpdest(&mut self, original_pc: u16) -> Result<()>
pub(crate) fn handle_jumpdest(&mut self, original_pc: u16) -> Result<()>
Handle jumpdest.
source§impl Function
impl Function
sourcepub fn _local_get(&mut self, local_index: u32) -> Result<()>
pub fn _local_get(&mut self, local_index: u32) -> Result<()>
This instruction gets the value of a variable.
sourcepub fn _local_set(&mut self, local_index: u32) -> Result<()>
pub fn _local_set(&mut self, local_index: u32) -> Result<()>
This instruction sets the value of a variable.
sourcepub fn _local_tee(&mut self, index: u32) -> Result<()>
pub fn _local_tee(&mut self, index: u32) -> Result<()>
This _local_tee is like _local_set, but it also returns the value on the stack.
sourcepub fn _global_get(&mut self, _: u32) -> Result<()>
pub fn _global_get(&mut self, _: u32) -> Result<()>
This instruction gets the value of a variable.
sourcepub fn _global_set(&mut self, _: u32) -> Result<()>
pub fn _global_set(&mut self, _: u32) -> Result<()>
This instruction sets the value of a variable.
sourcefn _local_get_calldata(&mut self, local_index: usize) -> Result<()>
fn _local_get_calldata(&mut self, local_index: usize) -> Result<()>
Local get from calldata.
sourcefn _local_get_var(&mut self, local_index: usize) -> Result<()>
fn _local_get_var(&mut self, local_index: usize) -> Result<()>
Local get for variables.