slang-netlist  0.9.0
Loading...
Searching...
No Matches
NetlistDot.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include "slang/text/FormatBuffer.h"
7
8namespace slang::netlist {
9
11struct NetlistDot {
12
13 static auto render(NetlistGraph const &netlist, FormatBuffer &buffer) {
14 buffer.append("digraph {\n");
15 buffer.append(" node [shape=record];\n");
16 for (auto &node : netlist) {
17 switch (node->kind) {
18 case NodeKind::Port: {
19 auto &portNode = node->as<Port>();
20 buffer.format(" N{} [label=\"{} port {}\"]\n", node->ID,
21 toString(portNode.direction), portNode.name);
22 break;
23 }
24 case NodeKind::Variable: {
25 auto &varNode = node->as<Variable>();
26 buffer.format(" N{} [label=\"Variable {}\"]\n", node->ID,
27 varNode.name);
28 break;
29 }
31 buffer.format(" N{} [label=\"Assignment\"]\n", node->ID);
32 break;
33 }
34 case NodeKind::Case: {
35 buffer.format(" N{} [label=\"Case\"]\n", node->ID);
36 break;
37 }
39 buffer.format(" N{} [label=\"Conditional\"]\n", node->ID);
40 break;
41 }
42 case NodeKind::Merge: {
43 buffer.format(" N{} [label=\"Merge\"]\n", node->ID);
44 break;
45 }
46 case NodeKind::State: {
47 auto &state = node->as<State>();
48 buffer.format(" N{} [label=\"{} {}\"]\n", node->ID, state.name,
49 toString(state.bounds));
50 break;
51 }
52 case NodeKind::Constant: {
53 auto &constNode = node->as<Constant>();
54 buffer.format(" N{} [label=\"Const {}\"]\n", node->ID,
55 constNode.value.toString());
56 break;
57 }
58 default:
59 SLANG_UNREACHABLE;
60 }
61 }
62 for (auto const &node : netlist) {
63 for (auto const &edge : node->getOutEdges()) {
64 if (edge->disabled) {
65 continue;
66 }
67 if (edge->symbol != nullptr && !edge->symbol->empty()) {
68 buffer.format(" N{} -> N{} [label=\"{}{}\"]\n", node->ID,
69 edge->getTargetNode().ID, edge->symbol->name,
70 toString(edge->bounds));
71 } else {
72 buffer.format(" N{} -> N{}\n", node->ID, edge->getTargetNode().ID);
73 }
74 }
75 }
76 buffer.append("}\n");
77 }
78};
79
80} // namespace slang::netlist
Definition NetlistNode.hpp:227
Represent the netlist connectivity of an elaborated design.
Definition NetlistGraph.hpp:33
Definition NetlistNode.hpp:71
Definition NetlistNode.hpp:138
Definition NetlistNode.hpp:108
Definition Utilities.hpp:16
@ Case
Definition NetlistNode.hpp:25
@ State
Definition NetlistNode.hpp:27
@ Variable
Definition NetlistNode.hpp:22
@ Port
Definition NetlistNode.hpp:21
@ Merge
Definition NetlistNode.hpp:26
@ Conditional
Definition NetlistNode.hpp:24
@ Constant
Definition NetlistNode.hpp:28
@ Assignment
Definition NetlistNode.hpp:23
A utility class for rendering a netlist graph in DOT format.
Definition NetlistDot.hpp:11
static auto render(NetlistGraph const &netlist, FormatBuffer &buffer)
Definition NetlistDot.hpp:13