use core::hash::Hash;
use crate::dataflow::cfg::Cfg;
mod sealed {
pub trait Sealed {}
}
pub struct Forward;
pub struct Backward;
impl sealed::Sealed for Forward {}
impl sealed::Sealed for Backward {}
pub trait Direction: sealed::Sealed {
fn boundary_node<N: Eq + Hash + Clone>(cfg: &Cfg<N>) -> &N;
fn input_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N];
fn output_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N];
}
impl Direction for Forward {
fn boundary_node<N: Eq + Hash + Clone>(cfg: &Cfg<N>) -> &N {
cfg.entry()
}
fn input_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N] {
cfg.predecessors(node)
}
fn output_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N] {
cfg.successors(node)
}
}
impl Direction for Backward {
fn boundary_node<N: Eq + Hash + Clone>(cfg: &Cfg<N>) -> &N {
cfg.exit()
}
fn input_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N] {
cfg.successors(node)
}
fn output_edges<'g, N: Eq + Hash + Clone>(cfg: &'g Cfg<N>, node: &N) -> &'g [N] {
cfg.predecessors(node)
}
}