Skip to content

Commit

Permalink
Netlist: add support in the driver for searching alias start/end poin…
Browse files Browse the repository at this point in the history
…ts (#1092)
  • Loading branch information
jameshanlon committed Aug 14, 2024
1 parent d3e77f3 commit fd44678
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
10 changes: 10 additions & 0 deletions tools/netlist/include/Netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@

using namespace slang;

template<>
class fmt::formatter<ConstantRange> {
public:
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template<typename Context>
constexpr auto format(ConstantRange const& range, Context& ctx) const {
return format_to(ctx.out(), "[{}:{}]", range.upper(), range.lower());
}
};

namespace netlist {

class NetlistNode;
Expand Down
68 changes: 61 additions & 7 deletions tools/netlist/netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ using namespace slang::ast;
using namespace slang::driver;
using namespace netlist;

template<>
class fmt::formatter<NetlistNode> {
public:
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template<typename Context>
constexpr auto format(NetlistNode const& node, Context& ctx) const {
if (node.kind == NodeKind::VariableAlias) {
auto& aliasNode = node.as<NetlistVariableAlias>();
return format_to(ctx.out(), "{}{}", aliasNode.hierarchicalPath, aliasNode.overlap);
}
else if (node.kind == NodeKind::VariableDeclaration) {
auto& declNode = node.as<NetlistVariableDeclaration>();
return format_to(ctx.out(), "{}", declNode.hierarchicalPath);
}
else {
return format_to(ctx.out(), "{}", node.getName());
}
}
};

namespace slang::diag {

inline constexpr DiagCode VariableReference(DiagSubsystem::Netlist, 0);
Expand Down Expand Up @@ -166,6 +186,21 @@ void dumpCyclesList(Compilation& compilation, Netlist& netlist,
}
}

/// Exand a variable declaration node into a set of aliases if any are defined.
/// These are used for searching for paths.
auto expandVarDecl(NetlistVariableDeclaration* node) {
std::vector<NetlistNode*> result;
if (node->aliases.empty()) {
result.push_back(node);
}
else {
for (auto* alias : node->aliases) {
result.push_back(alias);
}
}
return result;
}

int main(int argc, char** argv) {
OS::setupConsole();

Expand Down Expand Up @@ -288,14 +323,33 @@ int main(int argc, char** argv) {
SLANG_THROW(std::runtime_error(
fmt::format("could not find finish point: {}", *toPointName)));
}
PathFinder pathFinder(netlist);
auto path = pathFinder.find(*fromPoint, *toPoint);
if (path.empty()) {
SLANG_THROW(std::runtime_error(
fmt::format("no path between {} and {}", *fromPointName, *toPointName)));

// Expand the start and end points over aliases of the variable declaration nodes.
auto startPoints = expandVarDecl(fromPoint);
auto endPoints = expandVarDecl(toPoint);

// Search through all combinations of start and end points. Report
// the first path found and stop searching.
for (auto* src : startPoints) {
for (auto* dst : endPoints) {

DEBUG_PRINT("Searching for path between:\n {}\n {}\n", *src, *dst);

// Search for the path.
PathFinder pathFinder(netlist);
auto path = pathFinder.find(*src, *dst);

if (!path.empty()) {
// Report the path and exit.
reportPath(*compilation, path);
return 0;
}
}
}
// Report the path.
reportPath(*compilation, path);

// No path found.
SLANG_THROW(std::runtime_error(
fmt::format("no path between {} and {}", *fromPointName, *toPointName)));
}

// No action performed.
Expand Down

0 comments on commit fd44678

Please sign in to comment.