pub struct BasicBlock<'a> {
pub instructions: Vec<Instruction<'a>>,
}Expand description
Represents a basic block within a function.
A basic block is a sequence of instructions that execute sequentially and end with a terminator instruction (branch, jump, or return). This structure enables control flow analysis and optimization.
§Invariants
- The last instruction MUST be a terminator (
Br,Jmp, orRet) - Instructions within a block execute in order
- Control flow only changes at block boundaries
§Examples
use lamina::ir::{IRBuilder, Type, PrimitiveType, BinaryOp};
use lamina::ir::builder::{var, i32};
let mut builder = IRBuilder::new();
builder
.function("example", Type::Void)
.binary(BinaryOp::Add, "sum", PrimitiveType::I32, i32(10), i32(20))
.print(var("sum"))
.ret_void();
let module = builder.build();
let func = &module.functions["example"];
let entry_block = &func.basic_blocks["entry"];
// entry_block.instructions contains: [Binary, Print, Ret]Fields§
§instructions: Vec<Instruction<'a>>Instructions in this block (must end with a terminator)
Trait Implementations§
Source§impl<'a> Clone for BasicBlock<'a>
impl<'a> Clone for BasicBlock<'a>
Source§fn clone(&self) -> BasicBlock<'a>
fn clone(&self) -> BasicBlock<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for BasicBlock<'a>
impl<'a> Debug for BasicBlock<'a>
Source§impl Display for BasicBlock<'_>
impl Display for BasicBlock<'_>
Source§impl<'a> PartialEq for BasicBlock<'a>
impl<'a> PartialEq for BasicBlock<'a>
impl<'a> StructuralPartialEq for BasicBlock<'a>
Auto Trait Implementations§
impl<'a> Freeze for BasicBlock<'a>
impl<'a> RefUnwindSafe for BasicBlock<'a>
impl<'a> Send for BasicBlock<'a>
impl<'a> Sync for BasicBlock<'a>
impl<'a> Unpin for BasicBlock<'a>
impl<'a> UnwindSafe for BasicBlock<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more