slang-netlist  0.9.0
Loading...
Searching...
No Matches
ReportVariables.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include "slang/ast/ASTVisitor.h"
6#include "slang/text/FormatBuffer.h"
7
8namespace slang::report {
9
12 : public ast::ASTVisitor<ReportVariables, ast::VisitFlags::Expressions |
13 ast::VisitFlags::Canonical> {
14 struct VariableInfo {
15 std::string name;
16 SourceLocation location;
17 };
18
19 ast::Compilation &compilation;
20 std::vector<VariableInfo> variables;
21
22public:
23 explicit ReportVariables(ast::Compilation &compilation)
24 : compilation(compilation) {}
25
27 void report(FormatBuffer &buffer) {
28 auto header = netlist::Utilities::Row{"Name", "Location"};
29 auto table = netlist::Utilities::Table{};
30
31 for (auto var : variables) {
32 auto loc = netlist::Utilities::locationStr(compilation, var.location);
33 table.push_back(netlist::Utilities::Row{var.name, loc});
34 }
35
36 netlist::Utilities::formatTable(buffer, header, table);
37 }
38
39 void handle(const ast::VariableSymbol &symbol) {
40 auto variable = VariableInfo{.name = symbol.getHierarchicalPath(),
41 .location = symbol.location};
42 variables.push_back(variable);
43 }
44};
45
46} // namespace slang::report
void handle(const ast::VariableSymbol &symbol)
Definition ReportVariables.hpp:39
void report(FormatBuffer &buffer)
Renders the collected variable information to the given format buffer.
Definition ReportVariables.hpp:27
ReportVariables(ast::Compilation &compilation)
Definition ReportVariables.hpp:23
Definition ReportDrivers.hpp:13
std::vector< Row > Table
Definition Utilities.hpp:33
static auto locationStr(ast::Compilation const &compilation, SourceLocation location)
Return a string representation of a slang SourceLocation.
Definition Utilities.hpp:21
static auto formatTable(FormatBuffer &buffer, const Row &header, const Table &rows, TableFormatConfig cfg={})
Format a table of data into the given format buffer.
Definition Utilities.hpp:44
std::vector< std::string > Row
Definition Utilities.hpp:32