forked from cdkersey/chdl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.cpp
More file actions
90 lines (74 loc) · 2.17 KB
/
input.cpp
File metadata and controls
90 lines (74 loc) · 2.17 KB
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
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "input.h"
#include "nodeimpl.h"
#include "reset.h"
using namespace std;
using namespace chdl;
map <string, vector<node>> inputs;
static void clear_inputs() { inputs.clear(); }
CHDL_REGISTER_RESET(clear_inputs);
class inputimpl : public nodeimpl {
public:
inputimpl(string n, int i=-1): nodeimpl(), name(n), pos(i) {}
bool eval(cdomain_handle_t) {
cerr << "Attempted to simulate a design with unassociated inputs."
<< endl;
abort();
}
void print(ostream &) {}
void print_vl(ostream &) {}
private:
string name; // Name of input in input map
int pos; // Position in vector in input map. -1 for no name
};
node chdl::Input(std::string name) {
inputimpl *n = new inputimpl(name, -1);
inputs[name] = vector<node>(1, n->id);
return node(n->id);
}
void chdl::print_inputs_vl_head(std::ostream &out) {
for (auto i : inputs)
out << ',' << endl << " " << i.first;
}
void chdl::print_inputs_vl_body(std::ostream &out) {
for (auto in : inputs) {
out << " input ";
if (in.second.size() > 1)
out << '[' << in.second.size()-1 << ":0] ";
out << in.first << ';' << endl;
if (in.second.size() > 1) {
for (unsigned i = 0; i < in.second.size(); ++i) {
out << " assign __x" << in.second[i] << " = "
<< in.first << '[' << i << "];" << endl;
}
} else {
out << " assign __x" << in.second[0] << " = "
<< in.first << ';' << endl;
}
}
}
void chdl::print_input_nodes(std::ostream &out) {
for (auto in : inputs) {
out << " " << in.first;
for (unsigned i = 0; i < in.second.size(); ++i)
out << ' ' << in.second[i];
out << endl;
}
}
void chdl::get_input_nodes(std::set<nodeid_t> &s) {
for (auto in : inputs)
for (unsigned i = 0; i < in.second.size(); ++i)
s.insert(in.second[i]);
}
vector<node> chdl::input_internal(std::string name, unsigned n) {
inputs[name] = vector<node>();
for (unsigned i = 0; i < n; ++i) {
inputimpl *n = new inputimpl(name, i);
inputs[name].push_back(n->id);
}
return inputs[name];
}