ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rrrAnalyzer.h
Go to the documentation of this file.
1#pragma once
2
3#include "rrrParameter.h"
4#include "rrrUtils.h"
5
7
8namespace rrr {
9
10 template <typename Ntk, typename Sim, typename Sol>
11 class Analyzer {
12 private:
13 // pointer to network
14 Ntk *pNtk;
15
16 // parameters
17 bool nVerbose;
18
19 // data
20 Sim sim;
21 Sol sol;
22
23 public:
24 // constructors
25 Analyzer(Parameter const *pPar);
26 void AssignNetwork(Ntk *pNtk_, bool fReuse);
27
28 // checks
29 bool CheckRedundancy(int id, int idx);
30 bool CheckFeasibility(int id, int fi, bool c);
31
32 // summary
33 void ResetSummary();
36 };
37
38 /* {{{ Constructors */
39
40 template <typename Ntk, typename Sim, typename Sol>
42 pNtk(NULL),
43 nVerbose(pPar->nAnalyzerVerbose),
44 sim(pPar),
45 sol(pPar) {
46 }
47
48 template <typename Ntk, typename Sim, typename Sol>
49 void Analyzer<Ntk, Sim, Sol>::AssignNetwork(Ntk *pNtk_, bool fReuse) {
50 pNtk = pNtk_;
51 sim.AssignNetwork(pNtk, fReuse);
52 sol.AssignNetwork(pNtk, fReuse);
53 }
54
55 /* }}} */
56
57 /* {{{ Checks */
58
59 template <typename Ntk, typename Sim, typename Sol>
61 if(sim.CheckRedundancy(id, idx)) {
62 if(nVerbose) {
63 std::cout << "node " << id << " fanin " << (pNtk->GetCompl(id, idx)? "!": "") << pNtk->GetFanin(id, idx) << " index " << idx << " seems redundant" << std::endl;
64 }
65 SatResult r = sol.CheckRedundancy(id, idx);
66 if(r == UNSAT) {
67 if(nVerbose) {
68 std::cout << "node " << id << " fanin " << (pNtk->GetCompl(id, idx)? "!": "") << pNtk->GetFanin(id, idx) << " index " << idx << " is redundant" << std::endl;
69 }
70 return true;
71 }
72 if(r == SAT) {
73 if(nVerbose) {
74 std::cout << "node " << id << " fanin " << (pNtk->GetCompl(id, idx)? "!": "") << pNtk->GetFanin(id, idx) << " index " << idx << " is NOT redundant" << std::endl;
75 }
76 sim.AddCex(sol.GetCex());
77 }
78 } else {
79 // if(nVerbose) {
80 // std::cout << "node " << id << " fanin " << (pNtk->GetCompl(id, idx)? "!": "") << pNtk->GetFanin(id, idx) << " index " << idx << " is not redundant" << std::endl;
81 // }
82 }
83 return false;
84 }
85
86 template <typename Ntk, typename Sim, typename Sol>
87 bool Analyzer<Ntk, Sim, Sol>::CheckFeasibility(int id, int fi, bool c) {
88 if(sim.CheckFeasibility(id, fi, c)) {
89 if(nVerbose) {
90 std::cout << "node " << id << " fanin " << (c? "!": "") << fi << " seems feasible" << std::endl;
91 }
92 SatResult r = sol.CheckFeasibility(id, fi, c);
93 if(r == UNSAT) {
94 if(nVerbose) {
95 std::cout << "node " << id << " fanin " << (c? "!": "") << fi << " is feasible" << std::endl;
96 }
97 return true;
98 }
99 if(r == SAT) {
100 if(nVerbose) {
101 std::cout << "node " << id << " fanin " << (c? "!": "") << fi << " is NOT feasible" << std::endl;
102 }
103 sim.AddCex(sol.GetCex());
104 }
105 } else {
106 // if(nVerbose) {
107 // std::cout << "node " << id << " fanin " << (c? "!": "") << fi << " is not feasible" << std::endl;
108 // }
109 }
110 return false;
111 }
112
113 /* }}} */
114
115 /* {{{ Summary */
116
117 template <typename Ntk, typename Sim, typename Sol>
119 sim.ResetSummary();
120 sol.ResetSummary();
121 }
122
123 template <typename Ntk, typename Sim, typename Sol>
125 summary<int> v = sim.GetStatsSummary();
126 summary<int> v2 = sol.GetStatsSummary();
127 v.insert(v.end(), v2.begin(), v2.end());
128 return v;
129 }
130
131 template <typename Ntk, typename Sim, typename Sol>
133 summary<double> v = sim.GetTimesSummary();
134 summary<double> v2 = sol.GetTimesSummary();
135 v.insert(v.end(), v2.begin(), v2.end());
136 return v;
137 }
138
139 /* }}} */
140
141}
142
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
void AssignNetwork(Ntk *pNtk_, bool fReuse)
Definition rrrAnalyzer.h:49
summary< double > GetTimesSummary() const
summary< int > GetStatsSummary() const
bool CheckRedundancy(int id, int idx)
Definition rrrAnalyzer.h:60
void ResetSummary()
Analyzer(Parameter const *pPar)
Definition rrrAnalyzer.h:41
bool CheckFeasibility(int id, int fi, bool c)
Definition rrrAnalyzer.h:87
Definition rrr.h:16
std::vector< std::pair< std::string, T > > summary
Definition rrrTypes.h:66
SatResult
Definition rrrTypes.h:18
@ SAT
Definition rrrTypes.h:19
@ UNSAT
Definition rrrTypes.h:20