Skip to content

Commit

Permalink
Dot output WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Hanlon committed Mar 14, 2023
1 parent 8fc4e32 commit 13e91a5
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 11 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion source/ast/Bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//------------------------------------------------------------------------------
#include "slang/ast/Bitstream.h"

#include "../text/FormatBuffer.h"
#include <numeric>

#include "slang/ast/Compilation.h"
Expand All @@ -18,6 +17,7 @@
#include "slang/diagnostics/ConstEvalDiags.h"
#include "slang/diagnostics/ExpressionsDiags.h"
#include "slang/diagnostics/NumericDiags.h"
#include "slang/text/FormatBuffer.h"

namespace slang::ast {

Expand Down
3 changes: 1 addition & 2 deletions source/ast/EvalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
//------------------------------------------------------------------------------
#include "slang/ast/EvalContext.h"

#include "../text/FormatBuffer.h"

#include "slang/ast/ASTContext.h"
#include "slang/ast/Compilation.h"
#include "slang/ast/symbols/SubroutineSymbols.h"
#include "slang/ast/symbols/VariableSymbols.h"
#include "slang/ast/types/Type.h"
#include "slang/diagnostics/ConstEvalDiags.h"
#include "slang/text/FormatBuffer.h"

namespace slang::ast {

Expand Down
3 changes: 1 addition & 2 deletions source/ast/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
//------------------------------------------------------------------------------
#include "slang/ast/Symbol.h"

#include "../text/FormatBuffer.h"

#include "slang/ast/ASTVisitor.h"
#include "slang/ast/Compilation.h"
#include "slang/ast/Definition.h"
#include "slang/ast/symbols/CompilationUnitSymbols.h"
#include "slang/ast/symbols/MemberSymbols.h"
#include "slang/ast/types/Type.h"
#include "slang/syntax/AllSyntax.h"
#include "slang/text/FormatBuffer.h"
#include "slang/text/SourceManager.h"
#include "slang/util/StackContainer.h"

Expand Down
3 changes: 1 addition & 2 deletions source/ast/types/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
//------------------------------------------------------------------------------
#include "slang/ast/types/TypePrinter.h"

#include "../../text/FormatBuffer.h"

#include "slang/ast/ASTVisitor.h"
#include "slang/text/FormatBuffer.h"

namespace slang::ast {

Expand Down
3 changes: 1 addition & 2 deletions source/diagnostics/TextDiagnosticClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
//------------------------------------------------------------------------------
#include "slang/diagnostics/TextDiagnosticClient.h"

#include "../text/FormatBuffer.h"

#include "slang/text/CharInfo.h"
#include "slang/text/SourceManager.h"
#include "slang/text/FormatBuffer.h"

namespace slang {

Expand Down
2 changes: 1 addition & 1 deletion source/numeric/ConstantValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//------------------------------------------------------------------------------
#include "slang/numeric/ConstantValue.h"

#include "../text/FormatBuffer.h"
#include <ostream>

#include "slang/util/Hash.h"
#include "slang/text/FormatBuffer.h"

namespace slang {

Expand Down
2 changes: 1 addition & 1 deletion source/text/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//------------------------------------------------------------------------------
#include "slang/text/Json.h"

#include "FormatBuffer.h"
#include <climits>

#include "slang/text/FormatBuffer.h"
#include "slang/util/SmallVector.h"
#include "slang/util/String.h"

Expand Down
5 changes: 5 additions & 0 deletions tools/netlist/include/DirectedGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class DirectedGraph {

DirectedGraph() = default;

const_iterator begin() const { return nodes.begin(); }
const_iterator end() const { return nodes.end(); }
iterator begin() { return nodes.begin(); }
iterator end() { return nodes.end(); }

node_descriptor findNode(const NodeType &nodeToFind) const {
auto it = std::find_if(nodes.begin(), nodes.end(),
[&nodeToFind](const std::unique_ptr<NodeType> &node) {
Expand Down
19 changes: 19 additions & 0 deletions tools/netlist/netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "slang/util/TimeTrace.h"
#include "slang/util/Version.h"
#include "slang/util/Util.h"
#include "slang/text/FormatBuffer.h"

#include "DirectedGraph.h"

Expand Down Expand Up @@ -93,6 +94,7 @@ class NetlistNode : public Node<NetlistNode, NetlistEdge> {
selectors.emplace_back(std::make_unique<VariableMemberAccess>(name));
}
void setName(string_view name) { name = name; }
string_view getName() { return name; }
private:
string_view name;
std::vector<std::unique_ptr<VariableSelectorBase>> selectors;
Expand Down Expand Up @@ -337,6 +339,18 @@ void printJson(Compilation& compilation, const std::string& fileName,
writeToFile(fileName, writer.view());
}

void printDOT(const Netlist &netlist, const std::string &fileName) {
slang::FormatBuffer buffer;
buffer.append("digraph {\n");
for (auto &node : netlist) {
for (auto &edge : node->getEdges()) {
buffer.format(" {} -> {}", node->getName(), edge->getTargetNode());
}
}
buffer.append("}\n");
writeToFile(fileName, buffer.str());
}

template<typename Stream, typename String>
void writeToFile(Stream& os, string_view fileName, String contents) {
os.write(contents.data(), contents.size());
Expand Down Expand Up @@ -378,6 +392,11 @@ int main(int argc, char** argv) {
"given hierarchical paths",
"<path>");

std::optional<std::string> netlistDotFile;
driver.cmdLine.add("--netlist-dot", netlistDotFile,
"Dump the netlist in DOT format to the specified file, or '-' for stdout", "<file>",
/* isFileName */ true);

if (!driver.parseCommandLine(argc, argv)) {
return 1;
}
Expand Down

0 comments on commit 13e91a5

Please sign in to comment.