-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogicBoard.h
101 lines (80 loc) · 2.35 KB
/
LogicBoard.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
//
// Created by Sankalp Bhamare on 04/09/21.
//
#ifndef BISIM_LOGICBOARD_H
#define BISIM_LOGICBOARD_H
#include <vector>
#include <unordered_map>
#include "Primitive/CustomGates.h"
class Component : public BasicGate {
public:
string name;
shared_ptr<SignalMesh> internalSignalMesh;
IOPort internalInputPort, internalOutputPort;
vector<shared_ptr<BasicGate>> gates;
Component() {
internalSignalMesh = make_shared<SignalMesh>();
}
Component(const Component &c2);
void generateSignalMesh(const vector<string> &signalNames) {
internalSignalMesh->generateMapping(signalNames);
}
void clearGates() {
gates.clear();
}
void connect(const IOPortBus &inputBus, const IOPortBus &outputBus, std::shared_ptr<SignalMesh> signalMesh);
bool __eval__() {
internalInputPort.serialize(inputPort.deserialize());
simulate();
return outputPort.serialize(internalOutputPort.deserialize());
}
template<typename t>
void insertGate(const IOPortBus &inputBus, const IOPortBus &outputBus) {
auto gate = std::make_shared<t>();
gate->connect(inputBus, outputBus, internalSignalMesh);
gates.push_back(gate);
}
void insertComponent(const Component &cp, const IOPortBus &input, const IOPortBus &output) {
auto component = std::make_shared<Component>(cp);
component->connect(input, output, internalSignalMesh);
gates.push_back(component);
}
void simulate() {
while (iterate());
}
bool iterate();
virtual shared_ptr<BasicGate> copy(){
return make_shared<Component>(*this);
}
};
class LogicBoard {
std::shared_ptr<SignalMesh> sm;
Component dut;
vector<string> inputPorts;
vector<string> outputPorts;
public:
LogicBoard() {
sm = std::make_shared<SignalMesh>();
}
void loadDUT(const Component &cp) {
dut = Component(cp);
mapDUTSignals();
dut.connect(inputPorts,outputPorts,sm);
}
void mapDUTSignals();
void simulate() {
while (iterate());
}
bool iterate() {
bool sigChange = false;
sigChange = dut.__eval__();
return sigChange;
}
IOPort getPort(const IOPortBus &bus) {
IOPort pp;
pp.signalMesh = sm;
pp.ioPortBus = bus;
return pp;
}
};
#endif //BISIM_LOGICBOARD_H