slang-netlist  0.10.0
Loading...
Searching...
No Matches
ReportDrivers.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include "slang/analysis/AnalysisManager.h"
7#include "slang/analysis/ValueDriver.h"
8#include "slang/ast/EvalContext.h"
9#include "slang/ast/ValuePath.h"
10#include "slang/ast/symbols/ValueSymbol.h"
11
12namespace slang::report {
13
14struct DriverInfo {
15 std::string prefix;
16 analysis::DriverKind kind;
18 SourceLocation location;
19};
20
21struct ValueInfo {
22 std::string path;
23 SourceLocation location;
24 std::vector<DriverInfo> drivers;
25};
26
28class ReportDrivers : public ReportVisitorBase<ReportDrivers, ValueInfo> {
29 analysis::AnalysisManager &analysisManager;
30
32 static auto driverPathToString(const ast::ValueSymbol &symbol,
33 const analysis::ValueDriver &driver) {
34 ast::EvalContext evalContext(symbol);
35 return driver.path.toString(evalContext);
36 }
37
38 static auto driverKindStr(analysis::DriverKind kind) -> std::string_view {
39 return kind == analysis::DriverKind::Procedural ? "proc" : "cont";
40 }
41
42public:
43 explicit ReportDrivers(ast::Compilation &compilation,
44 analysis::AnalysisManager &analysisManager)
45 : ReportVisitorBase(compilation), analysisManager(analysisManager) {}
46
47 auto tableHeader() const -> netlist::Utilities::Row {
48 return {"Value", "Range", "Driver", "Type", "Location"};
49 }
50
52 ValueInfo const &value) const {
53 table.push_back(netlist::Utilities::Row{value.path, "", "", "",
54 locationStr(value.location)});
55 for (auto const &driver : value.drivers) {
56 table.push_back(
57 netlist::Utilities::Row{"↳", toString(driver.bounds), driver.prefix,
58 std::string(driverKindStr(driver.kind)),
59 locationStr(driver.location)});
60 }
61 }
62
63 void emitJsonItem(JsonWriter &writer, ValueInfo const &value) const {
64 writer.startObject();
65 writer.writeProperty("value");
66 writer.writeValue(value.path);
67 writer.writeProperty("location");
68 writer.writeValue(locationStr(value.location));
69 writer.writeProperty("drivers");
70 writer.startArray();
71 for (auto const &driver : value.drivers) {
72 writer.startObject();
73 writer.writeProperty("range");
74 writer.writeValue(toString(driver.bounds));
75 writer.writeProperty("driver");
76 writer.writeValue(driver.prefix);
77 writer.writeProperty("kind");
78 writer.writeValue(driverKindStr(driver.kind));
79 writer.writeProperty("location");
80 writer.writeValue(locationStr(driver.location));
81 writer.endObject();
82 }
83 writer.endArray();
84 writer.endObject();
85 }
86
90 void handle(ast::ValueSymbol const &symbol) {
91 auto path = symbol.getHierarchicalPath();
92 if (!nameMatches(path)) {
93 return;
94 }
95 auto value = ValueInfo{
96 .path = std::move(path), .location = symbol.location, .drivers = {}};
97
98 auto drivers = analysisManager.getDrivers(symbol);
99 for (auto const *driver : drivers) {
100 value.drivers.emplace_back(driverPathToString(symbol, *driver),
101 driver->kind,
102 netlist::DriverBitRange(driver->getBounds()),
103 driver->getSourceRange().start());
104 }
105
106 items.emplace_back(std::move(value));
107 }
108};
109
110} // namespace slang::report
auto tableHeader() const -> netlist::Utilities::Row
Definition ReportDrivers.hpp:47
void appendItemRows(netlist::Utilities::Table &table, ValueInfo const &value) const
Definition ReportDrivers.hpp:51
ReportDrivers(ast::Compilation &compilation, analysis::AnalysisManager &analysisManager)
Definition ReportDrivers.hpp:43
void emitJsonItem(JsonWriter &writer, ValueInfo const &value) const
Definition ReportDrivers.hpp:63
void handle(ast::ValueSymbol const &symbol)
Definition ReportDrivers.hpp:90
ast::Compilation & compilation
Definition ReportVisitorBase.hpp:35
ReportVisitorBase(ast::Compilation &compilation)
Definition ReportVisitorBase.hpp:60
auto locationStr(SourceLocation loc) const -> std::string
Definition ReportVisitorBase.hpp:40
auto nameMatches(std::string_view name) const -> bool
Definition ReportVisitorBase.hpp:46
std::vector< ValueInfo > items
Definition ReportVisitorBase.hpp:36
Definition Utilities.hpp:16
Definition ReportDrivers.hpp:12
A range over which a symbol is driven.
Definition DriverBitRange.hpp:14
std::vector< Row > Table
Definition Utilities.hpp:33
std::vector< std::string > Row
Definition Utilities.hpp:32
Definition ReportDrivers.hpp:14
SourceLocation location
Definition ReportDrivers.hpp:18
netlist::DriverBitRange bounds
Definition ReportDrivers.hpp:17
std::string prefix
Definition ReportDrivers.hpp:15
analysis::DriverKind kind
Definition ReportDrivers.hpp:16
Definition ReportDrivers.hpp:21
std::string path
Definition ReportDrivers.hpp:22
std::vector< DriverInfo > drivers
Definition ReportDrivers.hpp:24
SourceLocation location
Definition ReportDrivers.hpp:23