Skip to main content

litex/fact/
fact.rs

1use crate::prelude::*;
2use std::fmt;
3#[derive(Clone)]
4pub enum Fact {
5    AtomicFact(AtomicFact),
6    ExistFact(ExistFactEnum),
7    OrFact(OrFact),
8    AndFact(AndFact),
9    ChainFact(ChainFact),
10    ForallFact(ForallFact),
11    ForallFactWithIff(ForallFactWithIff),
12}
13
14impl fmt::Debug for Fact {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "{}", self)
17    }
18}
19
20impl Fact {
21    pub fn fact_type_string(&self) -> String {
22        match self {
23            Fact::AtomicFact(_) => "AtomicFact".to_string(),
24            Fact::ExistFact(_) => "ExistFact".to_string(),
25            Fact::OrFact(_) => "OrFact".to_string(),
26            Fact::AndFact(_) => "AndFact".to_string(),
27            Fact::ChainFact(_) => "ChainFact".to_string(),
28            Fact::ForallFact(_) => "ForallFact".to_string(),
29            Fact::ForallFactWithIff(_) => "ForallFactWithIff".to_string(),
30        }
31    }
32}
33
34impl fmt::Display for Fact {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Fact::AtomicFact(atomic_fact) => write!(f, "{}", atomic_fact),
38            Fact::ExistFact(exist_fact) => write!(f, "{}", exist_fact),
39            Fact::OrFact(or_fact) => write!(f, "{}", or_fact),
40            Fact::AndFact(and_fact) => write!(f, "{}", and_fact),
41            Fact::ChainFact(chain_fact) => write!(f, "{}", chain_fact),
42            Fact::ForallFact(forall_fact) => write!(f, "{}", forall_fact),
43            Fact::ForallFactWithIff(forall_fact_with_iff) => write!(f, "{}", forall_fact_with_iff),
44        }
45    }
46}
47
48impl Fact {
49    pub fn line_file(&self) -> LineFile {
50        match self {
51            Fact::AtomicFact(a) => a.line_file(),
52            Fact::ExistFact(e) => e.line_file(),
53            Fact::OrFact(o) => o.line_file.clone(),
54            Fact::AndFact(a) => a.line_file(),
55            Fact::ChainFact(c) => c.line_file(),
56            Fact::ForallFact(f) => f.line_file.clone(),
57            Fact::ForallFactWithIff(f) => f.line_file.clone(),
58        }
59    }
60
61    pub fn into_stmt(self) -> Stmt {
62        self.into()
63    }
64}
65
66impl From<AtomicFact> for Fact {
67    fn from(atomic_fact: AtomicFact) -> Self {
68        Fact::AtomicFact(atomic_fact)
69    }
70}
71
72impl From<OrFact> for Fact {
73    fn from(or_fact: OrFact) -> Self {
74        Fact::OrFact(or_fact)
75    }
76}
77
78impl From<ForallFact> for Fact {
79    fn from(forall_fact: ForallFact) -> Self {
80        Fact::ForallFact(forall_fact)
81    }
82}
83
84impl From<ExistFactEnum> for Fact {
85    fn from(exist_fact: ExistFactEnum) -> Self {
86        Fact::ExistFact(exist_fact)
87    }
88}
89
90impl From<AndFact> for Fact {
91    fn from(and_fact: AndFact) -> Self {
92        Fact::AndFact(and_fact)
93    }
94}
95
96impl From<ChainFact> for Fact {
97    fn from(chain_fact: ChainFact) -> Self {
98        Fact::ChainFact(chain_fact)
99    }
100}
101
102impl From<AndChainAtomicFact> for Fact {
103    fn from(f: AndChainAtomicFact) -> Self {
104        match f {
105            AndChainAtomicFact::AtomicFact(a) => a.into(),
106            AndChainAtomicFact::AndFact(a) => a.into(),
107            AndChainAtomicFact::ChainFact(c) => c.into(),
108        }
109    }
110}
111
112impl From<OrAndChainAtomicFact> for Fact {
113    fn from(f: OrAndChainAtomicFact) -> Self {
114        match f {
115            OrAndChainAtomicFact::AtomicFact(a) => a.into(),
116            OrAndChainAtomicFact::AndFact(a) => a.into(),
117            OrAndChainAtomicFact::ChainFact(c) => c.into(),
118            OrAndChainAtomicFact::OrFact(o) => o.into(),
119        }
120    }
121}
122
123impl From<ForallFactWithIff> for Fact {
124    fn from(forall_fact_with_iff: ForallFactWithIff) -> Self {
125        Fact::ForallFactWithIff(forall_fact_with_iff)
126    }
127}