use super::instruction::Instruction;
#[derive(Debug, Clone)]
pub struct BasicBlock {
pub label: Option<String>,
pub instructions: Vec<Instruction>,
}
impl BasicBlock {
#[must_use]
pub const fn new() -> Self {
Self {
label: None,
instructions: Vec::new(),
}
}
#[must_use]
pub fn with_label(label: impl Into<String>) -> Self {
Self {
label: Some(label.into()),
instructions: Vec::new(),
}
}
pub fn push(&mut self, inst: Instruction) {
self.instructions.push(inst);
}
#[must_use]
pub fn len(&self) -> usize {
self.instructions.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.instructions.is_empty()
}
}
impl Default for BasicBlock {
fn default() -> Self {
Self::new()
}
}