-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRtlVisualizer.cpp
49 lines (42 loc) · 1.65 KB
/
RtlVisualizer.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
//
// Created by unknown on 2024/11/4.
//
#include "RtlVisualizer.h"
#include "CircuitSymbol.h"
#include <cstdlib>
#include <memory>
#include <stdexcept>
#include <string>
#include <fstream>
#include <vector>
void RtlVisualizer::visualize(const RtlModule &hardwareModel, const std::string &filename) {
std::ofstream outputStream(filename + ".txt");
if (!outputStream) {
throw std::runtime_error("Unable to open " + filename + ".txt");
}
outputStream << "digraph RtlView {\n"
<< " fontname=\"Helvetica,Arial,sans-serif\"\n"
<< " node [fontname=\"Helvetica,Arial,sans-serif\"]\n"
<< " edge [fontname=\"Helvetica,Arial,sans-serif\"]\n";
std::vector<std::shared_ptr<CircuitSymbol>> symbols;
for (auto &symbol: hardwareModel.ioPorts) {
symbols.push_back(symbol);
}
for (auto &symbol: hardwareModel.circuitSymbols) {
symbols.push_back(symbol);
if (symbol->getIdentifier().starts_with("__comb_")) {
outputStream << " " << symbol->getIdentifier() << " [shape=invtriangle, label=\""
<< symbol->getIdentifier().substr(7) << "\"]\n";
}
}
for (const auto &circuitSymbol: symbols) {
for (const auto &[which, nextTarget, _]: circuitSymbol->getPropagateTargets()) {
outputStream << " " << circuitSymbol->getIdentifier() << " -> " << nextTarget->getIdentifier()
<< std::endl;
}
}
outputStream << "}" << std::endl;
outputStream.close();
system(("dot -Tpng " + filename + ".txt -o " + filename + ".png").c_str());
std::remove((filename + ".txt").c_str());
}