pub struct ProgramBuilder { /* private fields */ }Expand description
A VDBE bytecode program under construction.
Provides methods to emit instructions, create/resolve labels for forward
jumps, and allocate registers. Once construction is complete, call
finish to validate and extract the final instruction
sequence.
Implementations§
Source§impl ProgramBuilder
impl ProgramBuilder
Sourcepub fn emit(&mut self, op: VdbeOp) -> usize
pub fn emit(&mut self, op: VdbeOp) -> usize
Emit a single instruction and return its address (index in ops).
Sourcepub fn emit_op(
&mut self,
opcode: Opcode,
p1: i32,
p2: i32,
p3: i32,
p4: P4,
p5: u16,
) -> usize
pub fn emit_op( &mut self, opcode: Opcode, p1: i32, p2: i32, p3: i32, p4: P4, p5: u16, ) -> usize
Emit a simple instruction from parts.
Sourcepub fn current_addr(&self) -> usize
pub fn current_addr(&self) -> usize
The current address (index of the next instruction to be emitted).
Sourcepub fn op_at(&self, addr: usize) -> Option<&VdbeOp>
pub fn op_at(&self, addr: usize) -> Option<&VdbeOp>
Get a reference to the instruction at addr.
Sourcepub fn op_at_mut(&mut self, addr: usize) -> Option<&mut VdbeOp>
pub fn op_at_mut(&mut self, addr: usize) -> Option<&mut VdbeOp>
Get a mutable reference to the instruction at addr.
Sourcepub fn emit_label(&mut self) -> Label
pub fn emit_label(&mut self) -> Label
Create a new label for forward-reference jumps.
Sourcepub fn emit_jump_to_label(
&mut self,
opcode: Opcode,
p1: i32,
p3: i32,
label: Label,
p4: P4,
p5: u16,
) -> usize
pub fn emit_jump_to_label( &mut self, opcode: Opcode, p1: i32, p3: i32, label: Label, p4: P4, p5: u16, ) -> usize
Emit a jump instruction whose p2 target is a label (forward reference).
The label’s address will be patched into p2 when resolve_label is called.
Sourcepub fn resolve_label(&mut self, label: Label)
pub fn resolve_label(&mut self, label: Label)
Resolve a label to the current address and patch all forward refs.
Sourcepub fn resolve_label_to(&mut self, label: Label, address: i32)
pub fn resolve_label_to(&mut self, label: Label, address: i32)
Resolve a label to an explicit address (used for some control patterns).
Sourcepub fn alloc_regs(&mut self, n: i32) -> i32
pub fn alloc_regs(&mut self, n: i32) -> i32
Allocate a contiguous block of persistent registers.
Sourcepub fn alloc_temp(&mut self) -> i32
pub fn alloc_temp(&mut self) -> i32
Allocate a temporary register (reusable).
Sourcepub fn register_count(&self) -> i32
pub fn register_count(&self) -> i32
Total registers allocated (high water mark).
Sourcepub fn finish(self) -> Result<VdbeProgram>
pub fn finish(self) -> Result<VdbeProgram>
Validate all labels are resolved and return the finished program.