From e825e31e0b0c25f5e7b5c82fd4438241ce4add71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Sat, 15 Jun 2024 12:05:40 +0200 Subject: [PATCH 1/3] Fix hierarchical paths inside generate arrays Take some input with an unnamed generate array, e.g. module top; genvar i; for (i = 0; i < 1; i = i + 1) begin logic a; end endmodule make a fix so that the hierpath of the wire is `top.genblk1[0].a` not `top[0].a`. --- source/ast/Symbol.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/ast/Symbol.cpp b/source/ast/Symbol.cpp index 8bbf80235..9c2dc1184 100644 --- a/source/ast/Symbol.cpp +++ b/source/ast/Symbol.cpp @@ -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(); + if (current->name.empty()) + addName(array.getExternalName()); + } + else if (current->kind == SymbolKind::GenerateBlock) { auto& block = current->as(); if (auto index = block.arrayIndex) { buffer.append("["); From 56e1ed45892b591475a4e5992926111f6f0dacb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Sat, 15 Jun 2024 21:59:53 +0200 Subject: [PATCH 2/3] Add a test --- tests/unittests/ast/MemberTests.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unittests/ast/MemberTests.cpp b/tests/unittests/ast/MemberTests.cpp index d559ad3d3..49c7b3063 100644 --- a/tests/unittests/ast/MemberTests.cpp +++ b/tests/unittests/ast/MemberTests.cpp @@ -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" @@ -1358,6 +1359,27 @@ 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; From f43ddd50ba4674a6aad2ab6c8dc169acf6674dfa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:00:52 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- tests/unittests/ast/MemberTests.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unittests/ast/MemberTests.cpp b/tests/unittests/ast/MemberTests.cpp index 49c7b3063..37021e971 100644 --- a/tests/unittests/ast/MemberTests.cpp +++ b/tests/unittests/ast/MemberTests.cpp @@ -1374,9 +1374,8 @@ endmodule NO_COMPILATION_ERRORS; std::string path; - compilation.getRoot().visit(makeVisitor([&](auto& v, const VariableSymbol &sym) { - sym.getHierarchicalPath(path); - })); + compilation.getRoot().visit( + makeVisitor([&](auto& v, const VariableSymbol& sym) { sym.getHierarchicalPath(path); })); CHECK(path == "top.genblk1[0].a"); }