deimos-lang/dmc-lib/src/ir/ir_block.rs
2026-08-08 12:13:11 -05:00

77 lines
2.0 KiB
Rust

use crate::ir::ir_statement::IrStatement;
use crate::ir::register_allocation::{VrCollector, VrUser};
pub type IrBlockId = usize;
#[derive(Debug)]
pub struct IrBlock {
id: IrBlockId,
debug_label: String,
statements: Vec<IrStatement>,
}
impl IrBlock {
pub fn new(id: usize, debug_label: &str, statements: Vec<IrStatement>) -> Self {
Self {
id,
debug_label: debug_label.into(),
statements,
}
}
pub fn id(&self) -> IrBlockId {
self.id
}
pub fn debug_label(&self) -> &str {
&self.debug_label
}
pub fn statements(&self) -> &[IrStatement] {
&self.statements
}
}
impl VrUser for IrBlock {
fn vr_definitions(&self, vrs: &mut VrCollector) {
for statement in &self.statements {
statement.vr_definitions(vrs);
}
}
fn vr_uses(&self, vrs: &mut VrCollector) {
for statement in &self.statements {
statement.vr_uses(vrs);
}
}
}
//
// impl Display for IrBlock {
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// writeln!(f, " {}:", self.debug_label)?;
//
// let (live_in, live_out) = self.live_in_live_out();
//
// for (statement_index, statement) in self.statements.iter().enumerate() {
// let statement_live_in = live_in.get(&statement_index).unwrap();
// let statement_live_out = live_out.get(&statement_index).unwrap();
//
// writeln!(
// f,
// " {} // live_in: {:?}, live_out: {:?}",
// statement, statement_live_in, statement_live_out
// )?;
// }
// writeln!(f, " // ---- {} meta ----", self.debug_label)?;
// writeln!(f, " // definitions: {:?}", self.vr_definitions())?;
// writeln!(f, " // uses: {:?}", self.vr_uses())?;
// writeln!(
// f,
// " // interference graph: {:?}",
// self.interference_graph()
// )?;
// Ok(())
// }
// }