slang-netlist  0.9.0
Loading...
Searching...
No Matches
ReportPorts.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<ReportPorts, ast::VisitFlags::Expressions |
13 ast::VisitFlags::Canonical> {
14 struct PortInfo {
15 std::string name;
16 ast::ArgumentDirection direction;
17 SourceLocation location;
18 };
19
20 ast::Compilation &compilation;
21 std::vector<PortInfo> ports;
22
23public:
24 explicit ReportPorts(ast::Compilation &compilation)
25 : compilation(compilation) {}
26
28 void report(FormatBuffer &buffer) {
29 auto header = netlist::Utilities::Row{"Direction", "Name", "Location"};
30 auto table = netlist::Utilities::Table{};
31 for (auto port : ports) {
32 auto loc = netlist::Utilities::locationStr(compilation, port.location);
33 table.push_back(netlist::Utilities::Row{
34 std::string(toString(port.direction)), port.name, loc});
35 }
36 netlist::Utilities::formatTable(buffer, header, table);
37 }
38
39 void handle(const ast::PortSymbol &symbol) {
40 auto port = PortInfo{
41 .name = symbol.getHierarchicalPath(),
42 .direction = symbol.direction,
43 .location = symbol.location,
44 };
45 ports.push_back(port);
46 }
47};
48
49} // namespace slang::report
ReportPorts(ast::Compilation &compilation)
Definition ReportPorts.hpp:24
void report(FormatBuffer &buffer)
Renders the collected variable information to the given format buffer.
Definition ReportPorts.hpp:28
void handle(const ast::PortSymbol &symbol)
Definition ReportPorts.hpp:39
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