Struct cairo_lang_casm::builder::CasmBuilder
source · pub struct CasmBuilder { /* private fields */ }
Expand description
Builder to more easily write casm code without specifically thinking about ap changes and the sizes of opcodes. Wrong usages of it would panic instead of returning a result, as this builder assumes we are in a post validation of parameters stage.
Implementations§
source§impl CasmBuilder
impl CasmBuilder
sourcepub fn build<const BRANCH_COUNT: usize>(
self,
branch_names: [&str; BRANCH_COUNT]
) -> CasmBuildResult<BRANCH_COUNT>
pub fn build<const BRANCH_COUNT: usize>(
self,
branch_names: [&str; BRANCH_COUNT]
) -> CasmBuildResult<BRANCH_COUNT>
Finalizes the builder, with the requested labels as the returning branches. “Fallthrough” is a special case for the fallthrough case.
sourcepub fn add_var(&mut self, value: CellExpression) -> Var
pub fn add_var(&mut self, value: CellExpression) -> Var
Adds a variable pointing to value
.
sourcepub fn alloc_var(&mut self, local_var: bool) -> Var
pub fn alloc_var(&mut self, local_var: bool) -> Var
Allocates a new variable in memory, either local (FP-baser) or temp (AP-based).
sourcepub fn duplicate_var(&mut self, var: Var) -> Var
pub fn duplicate_var(&mut self, var: Var) -> Var
Returns an additional variable pointing to the same value.
sourcepub fn add_hint<const INPUTS_COUNT: usize, const OUTPUTS_COUNT: usize, F: FnOnce([ResOperand; INPUTS_COUNT], [CellRef; OUTPUTS_COUNT]) -> Hint>(
&mut self,
f: F,
inputs: [Var; INPUTS_COUNT],
outputs: [Var; OUTPUTS_COUNT]
)
pub fn add_hint<const INPUTS_COUNT: usize, const OUTPUTS_COUNT: usize, F: FnOnce([ResOperand; INPUTS_COUNT], [CellRef; OUTPUTS_COUNT]) -> Hint>(
&mut self,
f: F,
inputs: [Var; INPUTS_COUNT],
outputs: [Var; OUTPUTS_COUNT]
)
Adds a hint, generated from inputs
which are cell refs or immediates and outputs
which
must be cell refs.
sourcepub fn assert_vars_eq(&mut self, dst: Var, res: Var)
pub fn assert_vars_eq(&mut self, dst: Var, res: Var)
Adds an assertion that dst = res
.
dst
must be a cell reference.
sourcepub fn buffer_write_and_inc(&mut self, buffer: Var, value: Var)
pub fn buffer_write_and_inc(&mut self, buffer: Var, value: Var)
Writes and increments a buffer.
Useful for RangeCheck and similar buffers.
buffer
must be a cell reference, or a cell reference with a small added constant.
value
must be a cell reference.
sourcepub fn get_ref_and_inc(&mut self, buffer: Var) -> Var
pub fn get_ref_and_inc(&mut self, buffer: Var) -> Var
Increments a buffer and allocates and returns variable pointing to its previous value.
sourcepub fn bin_op(&mut self, op: CellOperator, lhs: Var, rhs: Var) -> Var
pub fn bin_op(&mut self, op: CellOperator, lhs: Var, rhs: Var) -> Var
Returns a variable that is the op
of lhs
and rhs
.
lhs
must be a cell reference and rhs
must be deref or immediate.
sourcepub fn double_deref(&mut self, var: Var, offset: i16) -> Var
pub fn double_deref(&mut self, var: Var, offset: i16) -> Var
Returns a variable that is [[var] + offset]
.
var
must be a cell reference, or a cell ref plus a small constant.
sourcepub fn jump_nz(&mut self, condition: Var, label: String)
pub fn jump_nz(&mut self, condition: Var, label: String)
Add a statement to jump to label
if condition != 0
.
condition
must be a cell reference.
sourcepub fn rescope<const VAR_COUNT: usize>(&mut self, vars: [(Var, Var); VAR_COUNT])
pub fn rescope<const VAR_COUNT: usize>(&mut self, vars: [(Var, Var); VAR_COUNT])
Rescoping the values, while ignoring all vars not stated in vars
and giving the vars on
the left side the values of the vars on the right side.