pub struct Block<'a> {
pub label: String,
pub items: Vec<BlockItem<'a>>,
}Expand description
A block of QBE instructions with a label.
Blocks are the basic units of control flow in QBE. Each block has a label that can be the target of jumps, and contains a sequence of instructions. A block typically ends with a control flow instruction like jump or return.
§Examples
use qbe::{Block, BlockItem, Instr, Statement, Type, Value};
// Create a block for a loop body
let mut block = Block {
label: "loop".to_string(),
items: Vec::new(),
};
// Add a helpful comment
block.add_comment("Loop body - increment counter and accumulate sum");
// Increment loop counter: %i = %i + 1
block.assign_instr(
Value::Temporary("i".to_string()),
Type::Word,
Instr::Add(
Value::Temporary("i".to_string()),
Value::Const(1),
),
);
// Update sum: %sum = %sum + %value
block.assign_instr(
Value::Temporary("sum".to_string()),
Type::Word,
Instr::Add(
Value::Temporary("sum".to_string()),
Value::Temporary("value".to_string()),
),
);
// Jump to condition check block
block.add_instr(Instr::Jmp("cond".to_string()));
// Check if block ends with a jump (it does)
assert!(block.jumps());Fields§
§label: StringLabel before the block
items: Vec<BlockItem<'a>>A list of statements in the block
Implementations§
Trait Implementations§
Source§impl<'a> Ord for Block<'a>
impl<'a> Ord for Block<'a>
Source§impl<'a> PartialOrd for Block<'a>
impl<'a> PartialOrd for Block<'a>
impl<'a> Eq for Block<'a>
impl<'a> StructuralPartialEq for Block<'a>
Auto Trait Implementations§
impl<'a> Freeze for Block<'a>
impl<'a> RefUnwindSafe for Block<'a>
impl<'a> Send for Block<'a>
impl<'a> Sync for Block<'a>
impl<'a> Unpin for Block<'a>
impl<'a> UnwindSafe for Block<'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