use super::instruction::LValInstruct;
use super::value::Value;
use crate::lowering::ir::{instruction::RValInstruct, symbols::TypeIndex};
use crate::parser::Span;
pub type BlockId = usize;
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct BasicBlock {
pub id: BlockId,
pub instructions: Vec<LValInstruct>,
pub terminator: Terminator,
pub span: Option<Span>,
}
impl BasicBlock {
pub fn new(id: BlockId, terminator: Terminator, span: Option<Span>) -> Self {
Self {
id,
instructions: Vec::new(),
terminator,
span,
}
}
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum Terminator {
Return(Option<RValInstruct>, Option<Span>),
Branch { target: BlockId, span: Option<Span> },
CondBranch {
condition: RValInstruct,
true_block: BlockId,
false_block: BlockId,
span: Option<Span>,
},
Unreachable(Option<Span>),
Call {
callee: String,
args: Vec<RValInstruct>,
span: Option<Span>,
return_dest: Value,
return_ty: TypeIndex,
dest_block: usize,
},
Eval {
expr: RValInstruct,
sym_name: String,
value: RValInstruct,
span: Option<Span>,
return_dest: Value,
return_ty_idx: TypeIndex,
dest_block: usize,
},
}