forked from mit-plv/koika
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cosimulation.cpp
43 lines (34 loc) · 982 Bytes
/
cosimulation.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
/*! Custom Cuttlesim driver that implements a Kôika extfun using a Verilator model !*/
#include "cosimulation.hpp"
#include "blackbox.obj_dir.opt/Vblackbox.h"
#include <verilated.h>
using Dut = Vblackbox;
class BlackboxWrapper {
public:
Dut dut;
void cycle() {
dut.CLK = 1;
dut.eval();
dut.CLK = 0;
dut.eval();
}
BlackboxWrapper() : dut{} {}
};
struct extfuns {
BlackboxWrapper blackbox_driver;
bits<32> blackbox(bits<32> input) {
blackbox_driver.dut.in = input.v;
blackbox_driver.cycle();
return bits<32>{blackbox_driver.dut.out};
}
};
class simulator final : public module_cosimulation<extfuns> {
void strobe() const {
std::cout << "# Cycle: " << meta.cycle_id << std::endl;
snapshot().report();
}
};
int main(int argc, char **argv) { return cuttlesim::main<simulator>(argc, argv); }
// Local Variables:
// flycheck-clang-include-path: ("/usr/share/verilator/include" "/usr/local/share/verilator/include/")
// End: