-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircuit.h
159 lines (118 loc) · 3.84 KB
/
Circuit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef CIRCUIT_H
#define CIRCUIT_H
#include <tr1/unordered_map>
#include <tr1/unordered_set>
#include <vector>
#include <iosfwd>
#include <fstream>
#include "Wire.h"
class CircuitElement;
class Inst;
class Port;
class TechLibrary;
enum ModType { FLIP, STUCK0, STUCK1 };
class Circuit {
public:
Circuit(std::string filename, TechLibrary* library_);
void write_blif(std::string filename);
bool check_input_cone(Port* port2, Port* driver);
typedef std::vector<Inst*>::iterator inst_iterator;
inst_iterator inst_begin()
{
return inst_iterator(linsts.begin());
}
inst_iterator inst_end()
{
return inst_iterator(linsts.end());
}
/*!
* Basic simulation of primary inputs using random simulation.
* Signatures are saved but the random inputs are not.
*/
void simulate(int num_sims = SIGSTEP);
/*!
* Simulate the saved random simulation vectors.
*/
void simulate_random();
/*!
* Simulate the saved test simulation vectors.
*/
void simulate_test();
void set_disable_signature_clear(bool flag)
{
disable_signature_clear = flag;
}
/*!
* Create random input vectors and store.
*/
void create_random_inputs(int num_sims = SIGSTEP);
/*!
* Checks for equivalence of signatures between circuits.
*/
virtual bool circuit_sig_equiv(Circuit* ckt1);
void clear_signatures();
void commit_signatures();
int get_num_test_vectors() const
{
return num_test_vec;
}
/*!
* Takes a series of test vectors (1st line is a list of PI
* names and the remaining lines are 0's and 1's with no spaces)
*/
void load_test_vectors(std::string testfile);
void print_info();
void output_differences(Circuit* ckt1, int& num_out_mismatch, int& num_vec_mismatch);
bool observable_signal(Inst* inst, ModType mod = FLIP);
void print_testability();
/*!
* Levelization requires that the input_wires vector
* be initialized.
*/
virtual void levelize();
std::vector<std::vector<unsigned long long> > get_random_inputs()
{
return rand_input_vecs;
}
void set_random_inputs(std::vector<std::vector<unsigned long long> >& input_vecs2, int rand_sim)
{
rand_input_vecs = input_vecs2;
num_rand_vec = rand_sim;
}
void load_test_vectors(const char* testfile);
bool wires_equal(std::string w1, std::string w2, CoverType type);
bool observable_cover(std::string inst_name, std::string wire_name, CoverType cover);
protected:
TechLibrary* library;
//! maps circuit elements to unique names
typedef std::tr1::unordered_map<std::string, CircuitElement*> sym_map;
sym_map sym_table;
std::vector<Inst*> linsts;
//! non input/output/latch instances
std::vector<Inst*> lib_insts;
int num_insts, num_wires, num_gates, num_ports, max_level;
std::string blif_name;
private:
void simulate(std::vector<std::vector<unsigned long long> >& input_vectors,
int num_sims);
void parse_blif(std::string filename);
int get_blif_token(std::string& token);
int get_blif_ttable(std::string& token);
Wire* find_wire_insert(std::string& name);
int sim_patterns;
int num_test_vec;
int num_rand_vec;
//! blif file stream
std::fstream ifile;
std::vector<Wire*> constants_list;
std::tr1::unordered_set<std::string> one_list;
std::tr1::unordered_set<std::string> zero_list;
//! includes latch outputs as primary inputs
std::vector<Wire*> input_wires;
//! includes latch inputs as primary outputs
std::vector<Wire*> output_wires;
std::vector<std::vector<unsigned long long> > input_vecs;
std::vector<std::vector<unsigned long long> > rand_input_vecs;
bool disable_signature_clear;
};
#endif