pub struct CodeGen { /* private fields */ }Expand description
The code generation abstraction.
TODO: add codegen context for backtrace. (#21)
Implementations§
source§impl CodeGen
impl CodeGen
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 CodeGen
impl CodeGen
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.
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 CodeGen
impl CodeGen
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.