use std::collections::HashMap;
use crate::analysis::{
cfg::{BlockSemantics, LoopSemantics, SemanticAnalyzer},
ssa::SsaFunction,
LoopInfo,
};
impl SsaFunction {
#[must_use]
pub fn analyze_block_semantics(&self, block_idx: usize) -> BlockSemantics {
let mut analyzer = SemanticAnalyzer::new(self);
analyzer.analyze_block(block_idx).clone()
}
#[must_use]
pub fn analyze_blocks_semantics(&self, blocks: &[usize]) -> HashMap<usize, BlockSemantics> {
let mut analyzer = SemanticAnalyzer::new(self);
let mut results = HashMap::new();
for &block in blocks {
results.insert(block, analyzer.analyze_block(block).clone());
}
results
}
#[must_use]
pub fn analyze_loop_semantics(&self, loop_info: &LoopInfo) -> LoopSemantics {
let mut analyzer = SemanticAnalyzer::new(self);
analyzer.analyze_loop(loop_info)
}
#[must_use]
pub fn recover_loop_from_cases(
&self,
case_blocks: &[usize],
dispatcher_block: Option<usize>,
) -> LoopSemantics {
let mut analyzer = SemanticAnalyzer::new(self);
if let Some(disp) = dispatcher_block {
analyzer.mark_dispatcher(disp);
}
analyzer.recover_loop_from_cases(case_blocks)
}
#[must_use]
pub fn semantic_analyzer(&self) -> SemanticAnalyzer<'_> {
SemanticAnalyzer::new(self)
}
}