Skip to content

Commit eba0a1e

Browse files
committed
[#83775] Add a pass that removes labels
Signed-off-by: Artur Bieniek <abieniek@internships.antmicro.com>
1 parent aeb4098 commit eba0a1e

13 files changed

Lines changed: 39 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FetchContent_Declare(
1111
)
1212
FetchContent_MakeAvailable(slang)
1313

14-
add_executable(sv-bugpoint source/SvBugpoint.cpp source/Utils.cpp source/PairRemovers.cpp source/BodyRemover.cpp
14+
add_executable(sv-bugpoint source/SvBugpoint.cpp source/Utils.cpp source/PairRemovers.cpp source/BodyRemover.cpp source/LabelRemover.cpp
1515
source/BodyPartsRemover.cpp source/DeclRemover.cpp source/InstantationRemover.cpp source/BindRemover.cpp source/ModportRemover.cpp source/ContAssignRemover.cpp source/ParamAssignRemover.cpp source/ModuleRemover.cpp
1616
source/StatementsRemover.cpp source/MemberRemover.cpp source/ImportsRemover.cpp source/TypeSimplifier.cpp)
1717

source/LabelRemover.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
#include "OneTimeRewriter.hpp"
3+
4+
class LabelRemover : public OneTimeRewriter<LabelRemover> {
5+
public:
6+
ShouldVisitChildren handle(const NamedBlockClauseSyntax& node, bool isNodeRemovable) {
7+
removeNode(node, isNodeRemovable);
8+
return DONT_VISIT_CHILDREN;
9+
}
10+
};
11+
12+
template bool rewriteLoop<LabelRemover>(std::shared_ptr<SyntaxTree>& tree,
13+
std::string stageName,
14+
std::string passIdx,
15+
SvBugpoint* svBugpoint);

source/OneTimeRewritersFwd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace slang::syntax;
77
// forward declarations of simple code removers that try to remove nodes one-by-one
88
class BodyPartsRemover;
99
class BodyRemover;
10+
class LabelRemover;
1011
class DeclRemover;
1112
class StatementsRemover;
1213
class ImportsRemover;

source/SvBugpoint.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ bool SvBugpoint::pass(const std::string& passIdx) {
226226
commited |= rewriteLoop(makeStructFieldRemover(tree), tree, "structRemover", passIdx, this);
227227
commited |= rewriteLoop<ModuleRemover>(tree, "moduleRemover", passIdx, this);
228228
commited |= rewriteLoop<TypeSimplifier>(tree, "typeSimplifier", passIdx, this);
229+
commited |= rewriteLoop<LabelRemover>(tree, "LabelRemover", passIdx, this);
229230
}
230231

231232
return commited;

tests/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ test_empty:
5252

5353
.PHONY: test_comment_dir
5454
test_comment_dir:
55-
@./run_test comment_dir checkverilator_run.sh ${INPUT_DIR}/comment_dir_in.sv
55+
@./run_test comment_dir checkverilator_run_finish.sh ${INPUT_DIR}/comment_dir_in.sv
56+
57+
.PHONY: test_labels
58+
test_labels:
59+
@./run_test labels checkverilator_run_finish.sh ${INPUT_DIR}/labels.sv
5660

5761
.PHONY: test_caliptra
5862
test_caliptra: test_caliptra_exit0 test_caliptra_grep

tests/checkverilator_lint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
verilator --lint-only "$1" || exit 1

tests/checkverilator_run.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/checkverilator_run_finish.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
filename=$(basename "$1")
3+
name="${filename%.*}"
4+
verilator --binary "$1" > /dev/null 2> /dev/null && timeout 15s "obj_dir/V$name" | grep "Verilog \$finish"

tests/golden/empty/debug/trace

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/golden/empty/minimized/empty.sv

Whitespace-only changes.

0 commit comments

Comments
 (0)