mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-07 09:55:20 +00:00
Improvements in "viz" command
Signed-off-by: Claire Xenia Wolf <claire@clairexen.net>
This commit is contained in:
parent
aeba966475
commit
068031d2aa
|
@ -670,27 +670,58 @@ struct VizWorker
|
||||||
fprintf(f, "digraph \"%s\" {\n", log_id(module));
|
fprintf(f, "digraph \"%s\" {\n", log_id(module));
|
||||||
fprintf(f, " rankdir = LR;\n");
|
fprintf(f, " rankdir = LR;\n");
|
||||||
|
|
||||||
dict<GraphNode*, std::vector<std::string>, hash_ptr_ops> extra_lines;
|
dict<GraphNode*, std::vector<std::vector<std::string>>, hash_ptr_ops> extra_lines;
|
||||||
dict<GraphNode*, GraphNode*, hash_ptr_ops> bypass_nodes;
|
dict<GraphNode*, GraphNode*, hash_ptr_ops> bypass_nodes;
|
||||||
|
|
||||||
for (auto g : graph.term_nodes) {
|
auto bypass = [&](GraphNode *g, GraphNode *n) {
|
||||||
if (g->nomerge || GetSize(g->upstream()) != 1) continue;
|
log_assert(g->terminal);
|
||||||
|
log_assert(!n->terminal);
|
||||||
|
bypass_nodes[g] = n;
|
||||||
|
|
||||||
|
auto &buffer = extra_lines[n];
|
||||||
|
buffer.emplace_back();
|
||||||
|
|
||||||
|
for (auto name : g->names())
|
||||||
|
buffer.back().push_back(log_id(name));
|
||||||
|
|
||||||
|
std::sort(buffer.back().begin(), buffer.back().end());
|
||||||
|
std::sort(buffer.begin(), buffer.end());
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto g : graph.term_nodes)
|
||||||
|
{
|
||||||
|
if (bypass_nodes.count(g)) continue;
|
||||||
|
if (GetSize(g->upstream()) != 1) continue;
|
||||||
if (!g->downstream().empty() && g->downstream() != g->upstream()) continue;
|
if (!g->downstream().empty() && g->downstream() != g->upstream()) continue;
|
||||||
|
|
||||||
auto n = *(g->upstream().begin());
|
auto n = *(g->upstream().begin());
|
||||||
if (n->terminal) continue;
|
if (n->terminal) continue;
|
||||||
for (auto name : g->names())
|
|
||||||
extra_lines[n].push_back(log_id(name));
|
bypass(g, n);
|
||||||
bypass_nodes[g] = n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < GetSize(graph.nodes); i++) {
|
for (auto g : graph.term_nodes)
|
||||||
auto g = graph.nodes[i];
|
{
|
||||||
|
if (bypass_nodes.count(g)) continue;
|
||||||
|
if (GetSize(g->upstream()) != 1) continue;
|
||||||
|
|
||||||
|
auto n = *(g->upstream().begin());
|
||||||
|
if (n->terminal) continue;
|
||||||
|
|
||||||
|
if (GetSize(n->downstream()) != 1) continue;
|
||||||
|
if (extra_lines.count(n)) continue;
|
||||||
|
|
||||||
|
bypass(g, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto g : graph.nodes) {
|
||||||
if (g->downstream().empty() && g->upstream().empty())
|
if (g->downstream().empty() && g->upstream().empty())
|
||||||
continue;
|
continue;
|
||||||
if (bypass_nodes.count(g))
|
if (bypass_nodes.count(g))
|
||||||
continue;
|
continue;
|
||||||
if (g->terminal) {
|
if (g->terminal) {
|
||||||
std::string label; // = stringf("[%d]\\n", g->index);
|
g->names().sort();
|
||||||
|
std::string label; // = stringf("vg=%d\\n", g->index);
|
||||||
for (auto n : g->names())
|
for (auto n : g->names())
|
||||||
label = label + (label.empty() ? "" : "\\n") + log_id(n);
|
label = label + (label.empty() ? "" : "\\n") + log_id(n);
|
||||||
fprintf(f, "\tn%d [shape=rectangle,label=\"%s\"];\n", g->index, label.c_str());
|
fprintf(f, "\tn%d [shape=rectangle,label=\"%s\"];\n", g->index, label.c_str());
|
||||||
|
@ -698,24 +729,27 @@ struct VizWorker
|
||||||
std::string label = stringf("vg=%d | %d cells", g->index, GetSize(g->names()));
|
std::string label = stringf("vg=%d | %d cells", g->index, GetSize(g->names()));
|
||||||
std::string shape = "oval";
|
std::string shape = "oval";
|
||||||
if (extra_lines.count(g)) {
|
if (extra_lines.count(g)) {
|
||||||
|
for (auto &block : extra_lines.at(g)) {
|
||||||
label += label.empty() ? "" : "\\n";
|
label += label.empty() ? "" : "\\n";
|
||||||
for (auto line : extra_lines.at(g))
|
for (auto &line : block)
|
||||||
label = label + (label.empty() ? "" : "\\n") + line;
|
label = label + (label.empty() ? "" : "\\n") + line;
|
||||||
shape = "octagon";
|
shape = "octagon";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fprintf(f, "\tn%d [shape=%s,label=\"%s\"];\n", g->index, shape.c_str(), label.c_str());
|
fprintf(f, "\tn%d [shape=%s,label=\"%s\"];\n", g->index, shape.c_str(), label.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pool<std::string> edges;
|
pool<std::string> edges;
|
||||||
for (auto g : graph.nodes) {
|
for (auto g : graph.nodes) {
|
||||||
g = bypass_nodes.at(g, g);
|
auto p = bypass_nodes.at(g, g);
|
||||||
for (auto n : g->downstream()) {
|
for (auto n : g->downstream()) {
|
||||||
n = bypass_nodes.at(n, n);
|
auto q = bypass_nodes.at(n, n);
|
||||||
if (g == n) continue;
|
if (p == q) continue;
|
||||||
edges.insert(stringf("n%d -> n%d", g->index, n->index));
|
edges.insert(stringf("n%d -> n%d", p->index, q->index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
edges.sort();
|
||||||
for (auto e : edges)
|
for (auto e : edges)
|
||||||
fprintf(f, "\t%s;\n", e.c_str());
|
fprintf(f, "\t%s;\n", e.c_str());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue