forked from cdkersey/chdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregimpl.cpp
100 lines (83 loc) · 2.3 KB
/
regimpl.cpp
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
#include <map>
#include "node.h"
#include "gates.h"
#include "reg.h"
#include "regimpl.h"
#include "nodeimpl.h"
#include "hierarchy.h"
using namespace chdl;
using namespace std;
regimpl::regimpl(node d): q(0), next_q(0), d(d), cd(cur_clock_domain()) {}
regimpl::~regimpl() {}
bool regimpl::eval(cdomain_handle_t) { return q; }
void regimpl::print(ostream &out) {
if (cd == 0) {
out << " reg " << d << ' ' << id << endl;
} else {
out << " reg<" << cd << "> " << d << ' ' << id << endl;
}
}
void regimpl::print_vl(ostream &out) {
const bool reset_signal(false), level_trig_reset(false);
if (!reset_signal) {
out << " initial" << endl
<< " begin" << endl
<< " __x" << id << " <= 0;" << endl
<< " end" << endl;
}
if (cd == 0)
out << " always @ (posedge phi)" << endl;
else
out << " always @ (posedge phi" << cd << ')' << endl;
if (reset_signal && level_trig_reset) {
out << " if (!reset)" << endl;
}
out << " begin" << endl
<< " __x" << id << " <= " << "__x" << d << ';' << endl
<< " end" << endl;
if (reset_signal) {
out << " always @ (posedge reset)" << endl
<< " begin" << endl
<< " __x" << id << " <= " << "0;" << endl
<< " end" << endl;
}
}
node chdl::Reg(node d, bool val) {
HIERARCHY_ENTER();
if (val) {
node r((new regimpl(Inv(d)))->id);
HIERARCHY_EXIT();
return Inv(r);
} else {
node r((new regimpl(d))->id);
HIERARCHY_EXIT();
return r;
}
}
node chdl::Wreg(node w, node d, bool initial) {
HIERARCHY_ENTER();
node q;
q = Reg(Mux(w, q, d), initial);
HIERARCHY_EXIT();
return q;
}
void chdl::get_reg_nodes(set<nodeid_t> &s) {
// We used to use a map<node, node> to keep track of all registers. This
// requires less maintenance:
for (size_t i = 0; i < nodes.size(); ++i) {
regimpl *r(dynamic_cast<regimpl*>(nodes[i]));
if (r) { s.insert(r->id); s.insert(r->d); }
}
}
void chdl::get_reg_q_nodes(set<nodeid_t> &s) {
for (size_t i = 0; i < nodes.size(); ++i) {
regimpl *r(dynamic_cast<regimpl*>(nodes[i]));
if (r) s.insert(r->id);
}
}
void chdl::get_reg_d_nodes(set<nodeid_t> &s) {
for (size_t i = 0; i < nodes.size(); ++i) {
regimpl *r(dynamic_cast<regimpl*>(nodes[i]));
if (r) s.insert(r->d);
}
}