use std::fmt;
use super::stmt::SsaStmt;
use crate::decompiler::cfg::ssa::variable::PhiNode;
#[derive(Debug, Clone, Default)]
pub struct SsaBlock {
pub phi_nodes: Vec<PhiNode>,
pub stmts: Vec<SsaStmt>,
}
impl SsaBlock {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn add_phi(&mut self, phi: PhiNode) {
self.phi_nodes.push(phi);
}
pub fn add_stmt(&mut self, stmt: SsaStmt) {
self.stmts.push(stmt);
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.phi_nodes.is_empty() && self.stmts.is_empty()
}
#[must_use]
pub fn phi_count(&self) -> usize {
self.phi_nodes.len()
}
#[must_use]
pub fn stmt_count(&self) -> usize {
self.stmts.len()
}
}
impl fmt::Display for SsaBlock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for phi in &self.phi_nodes {
writeln!(f, " {}", phi)?;
}
for stmt in &self.stmts {
writeln!(f, " {}", stmt)?;
}
Ok(())
}
}