slang-netlist  0.11.0
Loading...
Searching...
No Matches
NetlistGraph.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "netlist/Debug.hpp"
11
12#include "slang/ast/SemanticFacts.h"
13
14#include <algorithm>
15#include <ranges>
16#include <regex>
17#include <span>
18#include <string>
19#include <unordered_map>
20#include <vector>
21
22namespace slang {
23namespace ast {
24class Compilation;
25} // namespace ast
26namespace analysis {
27class AnalysisManager;
28} // namespace analysis
29} // namespace slang
30
31namespace slang::netlist {
32
42
44class NetlistGraph : public DirectedGraph<NetlistNode, NetlistEdge> {
45public:
48
55 void build(ast::Compilation &compilation,
56 analysis::AnalysisManager &analysisManager,
57 BuilderOptions options = {});
58
63 [[nodiscard]] auto lookup(std::string_view name) const -> NetlistNode *;
64
69 [[nodiscard]] auto lookup(std::string_view name, DriverBitRange bounds) const
70 -> std::vector<NetlistNode *>;
71
78 [[nodiscard]] auto getDrivers(std::string_view name,
79 DriverBitRange bounds) const
80 -> std::vector<NetlistNode *>;
81
88
96 [[nodiscard]] auto getBitDrivers(std::string_view name,
97 DriverBitRange bounds) const
98 -> std::vector<BitDriver>;
99
105 [[nodiscard]] auto getBitDrivers(std::string_view name) const
106 -> std::vector<BitDriver>;
107
110 [[nodiscard]] auto getCombFanOut(NetlistNode &node) const
111 -> std::vector<NetlistNode *>;
112
115 [[nodiscard]] auto getCombFanIn(NetlistNode &node) const
116 -> std::vector<NetlistNode *>;
117
121 ast::EdgeKind edgeKind;
122
123 auto operator==(SensitivitySource const &) const -> bool = default;
124 };
125
129 [[nodiscard]] auto getSensitivity(NetlistNode &node) const
130 -> std::vector<SensitivitySource>;
131
141 [[nodiscard]] auto getConstantDrivers(NetlistNode &node) const
142 -> std::vector<NetlistNode *>;
143
151 [[nodiscard]] auto findNodes(std::string_view pattern) const
152 -> std::vector<NetlistNode *>;
153
155 [[nodiscard]] auto findNodesRegex(std::string_view pattern) const
156 -> std::vector<NetlistNode *>;
157
162 [[nodiscard]]
163 auto filterNodes(NodeKind kind) const {
164 return nodes |
165 std::views::filter([kind](std::unique_ptr<NetlistNode> const &p) {
166 return p->kind == kind;
167 });
168 }
169
171 auto addEdge(NetlistNode &sourceNode, NetlistNode &targetNode)
172 -> NetlistEdge & {
173 return sourceNode.addEdge(targetNode);
174 }
175
177 [[nodiscard]] auto getBuildProfile() const -> BuildProfile const & {
178 return buildProfile;
179 }
180
182 void setBuildProfile(BuildProfile const &profile) { buildProfile = profile; }
183
185 void addBlackBoxPath(std::string path) {
186 blackBoxPaths.push_back(std::move(path));
187 }
188
190 [[nodiscard]] auto getBlackBoxPaths() const -> std::span<std::string const> {
191 return blackBoxPaths;
192 }
193
200 [[nodiscard]] auto getBlackBoxCoverage(NetlistNode const &node) const
202
203private:
204 BuildProfile buildProfile;
205 std::vector<std::string> blackBoxPaths;
206 mutable bool indexBuilt = false;
207 mutable std::unordered_map<std::string, std::vector<NetlistNode *>> nodeIndex;
208 void buildIndex() const;
209};
210
211} // namespace slang::netlist
NodeListType nodes
Definition DirectedGraph.hpp:481
Definition TextLocation.hpp:20
Definition NetlistEdge.hpp:18
Represent the netlist connectivity of an elaborated design.
Definition NetlistGraph.hpp:44
void setBuildProfile(BuildProfile const &profile)
Set the profiling data (called internally by NetlistBuilder).
Definition NetlistGraph.hpp:182
auto lookup(std::string_view name, DriverBitRange bounds) const -> std::vector< NetlistNode * >
auto getDrivers(std::string_view name, DriverBitRange bounds) const -> std::vector< NetlistNode * >
auto getSensitivity(NetlistNode &node) const -> std::vector< SensitivitySource >
auto findNodesRegex(std::string_view pattern) const -> std::vector< NetlistNode * >
Find named nodes whose hierarchical path matches the regex pattern.
auto getCombFanOut(NetlistNode &node) const -> std::vector< NetlistNode * >
void addBlackBoxPath(std::string path)
Record the hierarchical path of a black-boxed instance.
Definition NetlistGraph.hpp:185
auto getBlackBoxPaths() const -> std::span< std::string const >
Return the hierarchical paths of the black-boxed instances.
Definition NetlistGraph.hpp:190
FileTable fileTable
Definition NetlistGraph.hpp:46
auto addEdge(NetlistNode &sourceNode, NetlistNode &targetNode) -> NetlistEdge &
Add an edge between two nodes.
Definition NetlistGraph.hpp:171
SymbolTable symbolTable
Definition NetlistGraph.hpp:47
auto getBuildProfile() const -> BuildProfile const &
Return the profiling data from the last build() call.
Definition NetlistGraph.hpp:177
auto getCombFanIn(NetlistNode &node) const -> std::vector< NetlistNode * >
auto lookup(std::string_view name) const -> NetlistNode *
auto getBlackBoxCoverage(NetlistNode const &node) const -> BlackBoxCoverage
auto getBitDrivers(std::string_view name, DriverBitRange bounds) const -> std::vector< BitDriver >
auto getConstantDrivers(NetlistNode &node) const -> std::vector< NetlistNode * >
auto getBitDrivers(std::string_view name) const -> std::vector< BitDriver >
auto findNodes(std::string_view pattern) const -> std::vector< NetlistNode * >
auto filterNodes(NodeKind kind) const
Definition NetlistGraph.hpp:163
void build(ast::Compilation &compilation, analysis::AnalysisManager &analysisManager, BuilderOptions options={})
Definition NetlistNode.hpp:33
Definition SymbolReference.hpp:34
Definition NetlistGraph.hpp:26
Definition NetlistGraph.hpp:23
Definition FormatBuffer.hpp:9
BlackBoxCoverage
Classification of a node against a graph's black boxes.
Definition NetlistGraph.hpp:34
@ Contained
Strictly inside a black box.
Definition NetlistGraph.hpp:40
@ Outside
Not covered by any black box.
Definition NetlistGraph.hpp:36
@ Boundary
A port of a black-boxed instance.
Definition NetlistGraph.hpp:38
NodeKind
Definition NetlistNode.hpp:19
Definition FormatBuffer.hpp:9
Profiling data collected during netlist graph construction.
Definition BuildProfile.hpp:8
Caller-supplied options that tune how the netlist graph is built.
Definition BuilderOptions.hpp:10
A range over which a symbol is driven.
Definition DriverBitRange.hpp:14
Definition NetlistGraph.hpp:84
NetlistNode * driver
Definition NetlistGraph.hpp:86
DriverBitRange bounds
Definition NetlistGraph.hpp:85
A clock/reset signal driving a State node, paired with its edge kind.
Definition NetlistGraph.hpp:119
NetlistNode * source
Definition NetlistGraph.hpp:120
auto operator==(SensitivitySource const &) const -> bool=default
ast::EdgeKind edgeKind
Definition NetlistGraph.hpp:121