use super::{FixedPointAnalysisKind, FixedPointForwardGraph};
#[derive(Clone, Debug, PartialEq)]
pub struct FixedPointAnalysisPlan {
pub(crate) kind: FixedPointAnalysisKind,
pub(crate) graph: FixedPointForwardGraph,
pub(crate) program: vyre::ir::Program,
}
impl FixedPointAnalysisPlan {
#[must_use]
pub fn new(graph: FixedPointForwardGraph, program: vyre::ir::Program) -> Self {
Self::new_for_kind(FixedPointAnalysisKind::Generic, graph, program)
}
#[must_use]
pub fn new_for_kind(
kind: FixedPointAnalysisKind,
graph: FixedPointForwardGraph,
program: vyre::ir::Program,
) -> Self {
Self {
kind,
graph,
program,
}
}
#[must_use]
pub fn kind(&self) -> FixedPointAnalysisKind {
self.kind
}
pub fn require_kind(
&self,
expected: FixedPointAnalysisKind,
consumer: &str,
) -> Result<(), String> {
if self.kind == expected {
return self.graph.require_kind(expected, consumer);
}
Err(format!(
"{consumer} received a {:?} fixed-point plan, expected {:?}. Fix: prepare the plan with the matching Weir analysis constructor.",
self.kind, expected
))
}
#[must_use]
pub fn graph(&self) -> &FixedPointForwardGraph {
&self.graph
}
#[must_use]
pub fn graph_mut(&mut self) -> &mut FixedPointForwardGraph {
&mut self.graph
}
#[must_use]
pub fn program(&self) -> &vyre::ir::Program {
&self.program
}
pub fn replace_program_for_kind(
&mut self,
kind: FixedPointAnalysisKind,
program: vyre::ir::Program,
) {
self.kind = kind;
self.program = program;
}
#[must_use]
pub fn retained_graph_bytes(&self) -> usize {
self.graph.retained_bytes()
}
#[must_use]
pub fn stable_layout_hash(&self) -> u64 {
self.graph.stable_layout_hash()
}
}