pub mod cfg;
pub mod terminating;
pub mod vec;
use std::marker::PhantomData;
use crate::analysis::pcode_store::PcodeOpRef;
use crate::analysis::cpa::{ConfigurableProgramAnalysis, state::AbstractState};
pub trait Residue<'a, S> {
type Output;
fn new_state(&mut self, _state: &S, _dest_state: &S, _op: &Option<PcodeOpRef<'a>>) {}
fn merged_state(
&mut self,
_curr_state: &S,
_original_merged_state: &S,
_merged_state: &S,
_op: &Option<PcodeOpRef<'a>>,
) {
}
fn new() -> Self;
fn finalize(self) -> Self::Output;
}
pub struct EmptyResidue<T>(PhantomData<T>);
impl<'a, T: AbstractState> Residue<'a, T> for EmptyResidue<T> {
type Output = ();
fn new() -> Self {
Self(Default::default())
}
fn finalize(self) -> Self::Output {}
}
pub trait ReducerFactoryForState<A: ConfigurableProgramAnalysis> {
type Reducer<'op>: Residue<'op, A::State>;
fn make<'op>(&self) -> Self::Reducer<'op>;
}
pub struct ResidueWrapper<A: ConfigurableProgramAnalysis, F>
where
for<'op> F: ReducerFactoryForState<A>,
{
a: A,
_phantom: PhantomData<F>,
}
impl<A: ConfigurableProgramAnalysis, F> ResidueWrapper<A, F>
where
for<'op> F: ReducerFactoryForState<A>,
{
pub fn wrap(a: A, _: F) -> Self {
Self {
a,
_phantom: Default::default(),
}
}
pub fn with_residue<G>(self, _: G) -> ResidueWrapper<A, G>
where
for<'op> G: ReducerFactoryForState<A>,
{
ResidueWrapper {
a: self.a,
_phantom: Default::default(),
}
}
}
impl<A: ConfigurableProgramAnalysis, F> ConfigurableProgramAnalysis for ResidueWrapper<A, F>
where
for<'op> F: ReducerFactoryForState<A>,
{
type State = A::State;
type Reducer<'op> = <F as ReducerFactoryForState<A>>::Reducer<'op>;
}
impl<T, A, F> crate::analysis::cpa::IntoState<ResidueWrapper<A, F>> for T
where
A: crate::analysis::cpa::ConfigurableProgramAnalysis,
for<'op> F: ReducerFactoryForState<A>,
T: crate::analysis::cpa::IntoState<A> + Clone,
{
fn into_state(
self,
c: &ResidueWrapper<A, F>,
) -> <ResidueWrapper<A, F> as crate::analysis::cpa::ConfigurableProgramAnalysis>::State {
self.into_state(&c.a)
}
}
pub use self::cfg::{CFG, CfgReducer, CfgReducerFactory};
pub use self::terminating::TerminatingReducer;
pub use self::vec::{VEC, VecReducer, VecReducerFactory};