slang-netlist  0.9.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 <string>
18#include <unordered_map>
19#include <vector>
20
21namespace slang {
22namespace ast {
23class Compilation;
24} // namespace ast
25namespace analysis {
26class AnalysisManager;
27} // namespace analysis
28} // namespace slang
29
30namespace slang::netlist {
31
33class NetlistGraph : public DirectedGraph<NetlistNode, NetlistEdge> {
34public:
37
44 void build(ast::Compilation &compilation,
45 analysis::AnalysisManager &analysisManager,
46 BuilderOptions options = {});
47
52 [[nodiscard]] auto lookup(std::string_view name) const -> NetlistNode *;
53
58 [[nodiscard]] auto lookup(std::string_view name, DriverBitRange bounds) const
59 -> std::vector<NetlistNode *>;
60
67 [[nodiscard]] auto getDrivers(std::string_view name,
68 DriverBitRange bounds) const
69 -> std::vector<NetlistNode *>;
70
73 [[nodiscard]] auto getCombFanOut(NetlistNode &node) const
74 -> std::vector<NetlistNode *>;
75
78 [[nodiscard]] auto getCombFanIn(NetlistNode &node) const
79 -> std::vector<NetlistNode *>;
80
84 ast::EdgeKind edgeKind;
85
86 auto operator==(SensitivitySource const &) const -> bool = default;
87 };
88
92 [[nodiscard]] auto getSensitivity(NetlistNode &node) const
93 -> std::vector<SensitivitySource>;
94
97 [[nodiscard]] auto findNodes(std::string_view pattern) const
98 -> std::vector<NetlistNode *>;
99
101 [[nodiscard]] auto findNodesRegex(std::string_view pattern) const
102 -> std::vector<NetlistNode *>;
103
108 [[nodiscard]]
109 auto filterNodes(NodeKind kind) const {
110 return nodes |
111 std::views::filter([kind](std::unique_ptr<NetlistNode> const &p) {
112 return p->kind == kind;
113 });
114 }
115
117 auto addEdge(NetlistNode &sourceNode, NetlistNode &targetNode)
118 -> NetlistEdge & {
119 return sourceNode.addEdge(targetNode);
120 }
121
123 [[nodiscard]] auto getBuildProfile() const -> BuildProfile const & {
124 return buildProfile;
125 }
126
128 void setBuildProfile(BuildProfile const &profile) { buildProfile = profile; }
129
130private:
131 BuildProfile buildProfile;
132 mutable bool indexBuilt = false;
133 mutable std::unordered_map<std::string, std::vector<NetlistNode *>> nodeIndex;
134 void buildIndex() const;
135};
136
137} // 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:33
void setBuildProfile(BuildProfile const &profile)
Set the profiling data (called internally by NetlistBuilder).
Definition NetlistGraph.hpp:128
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 * >
FileTable fileTable
Definition NetlistGraph.hpp:35
auto addEdge(NetlistNode &sourceNode, NetlistNode &targetNode) -> NetlistEdge &
Add an edge between two nodes.
Definition NetlistGraph.hpp:117
SymbolTable symbolTable
Definition NetlistGraph.hpp:36
auto getBuildProfile() const -> BuildProfile const &
Return the profiling data from the last build() call.
Definition NetlistGraph.hpp:123
auto getCombFanIn(NetlistNode &node) const -> std::vector< NetlistNode * >
auto lookup(std::string_view name) const -> NetlistNode *
auto findNodes(std::string_view pattern) const -> std::vector< NetlistNode * >
auto filterNodes(NodeKind kind) const
Definition NetlistGraph.hpp:109
void build(ast::Compilation &compilation, analysis::AnalysisManager &analysisManager, BuilderOptions options={})
Definition NetlistNode.hpp:33
Definition SymbolReference.hpp:34
Definition NetlistGraph.hpp:25
Definition NetlistGraph.hpp:22
Definition Utilities.hpp:16
NodeKind
Definition NetlistNode.hpp:19
Definition Utilities.hpp:16
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
A clock/reset signal driving a State node, paired with its edge kind.
Definition NetlistGraph.hpp:82
NetlistNode * source
Definition NetlistGraph.hpp:83
auto operator==(SensitivitySource const &) const -> bool=default
ast::EdgeKind edgeKind
Definition NetlistGraph.hpp:84