Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hierarchical paths inside generate arrays #1031

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion source/ast/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ static void getHierarchicalPathImpl(const Symbol& symbol, FormatBuffer& buffer)
if (!current->name.empty())
addName(current->name);

if (current->kind == SymbolKind::GenerateBlock) {
if (current->kind == SymbolKind::GenerateBlockArray) {
auto& array = current->as<GenerateBlockArraySymbol>();
if (current->name.empty())
addName(array.getExternalName());
}
else if (current->kind == SymbolKind::GenerateBlock) {
auto& block = current->as<GenerateBlockSymbol>();
if (auto index = block.arrayIndex) {
buffer.append("[");
Expand Down
21 changes: 21 additions & 0 deletions tests/unittests/ast/MemberTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Test.h"

#include "slang/ast/ASTSerializer.h"
#include "slang/ast/ASTVisitor.h"
#include "slang/ast/Statements.h"
#include "slang/ast/expressions/AssignmentExpressions.h"
#include "slang/ast/expressions/CallExpression.h"
Expand Down Expand Up @@ -1358,6 +1359,26 @@ endmodule
CHECK(path == "top.m1[2][1][3].asdf[1].genblk1.foo");
}

TEST_CASE("Hierarchical paths with unnamed generate arrays") {
auto tree = SyntaxTree::fromText(R"(
module top;
genvar i;
for (i = 0; i < 1; i = i + 1) begin
logic a;
end
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;

std::string path;
compilation.getRoot().visit(
makeVisitor([&](auto& v, const VariableSymbol& sym) { sym.getHierarchicalPath(path); }));
CHECK(path == "top.genblk1[0].a");
}

TEST_CASE("$static_assert elab task") {
auto tree = SyntaxTree::fromText(R"(
module top;
Expand Down