Skip to content

Commit a20c1e3

Browse files
committed
Apply review suggestions
1 parent ec40803 commit a20c1e3

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,30 @@ FetchContent_Declare(
1111
)
1212
FetchContent_MakeAvailable(slang)
1313

14-
add_executable(sv-bugpoint source/SvBugpoint.cpp source/Utils.cpp source/SetRemovers.cpp source/BodyRemover.cpp source/LabelRemover.cpp
15-
source/BodyPartsRemover.cpp source/DeclRemover.cpp source/InstantationRemover.cpp source/BindRemover.cpp source/ModportRemover.cpp source/ContAssignRemover.cpp source/ParamAssignRemover.cpp source/ModuleRemover.cpp
16-
source/StatementsRemover.cpp source/MemberRemover.cpp source/ImportsRemover.cpp source/TypeSimplifier.cpp)
14+
add_executable(sv-bugpoint
15+
source/SvBugpoint.cpp
16+
source/Utils.cpp
17+
source/SetRemovers.cpp
18+
source/BodyRemover.cpp
19+
source/LabelRemover.cpp
20+
source/BodyPartsRemover.cpp
21+
source/DeclRemover.cpp
22+
source/InstantationRemover.cpp
23+
source/BindRemover.cpp
24+
source/ModportRemover.cpp
25+
source/ContAssignRemover.cpp
26+
source/ParamAssignRemover.cpp
27+
source/ModuleRemover.cpp
28+
source/StatementsRemover.cpp
29+
source/MemberRemover.cpp
30+
source/ImportsRemover.cpp
31+
source/TypeSimplifier.cpp
32+
)
1733

1834
target_link_libraries(sv-bugpoint PRIVATE slang::slang)
1935
target_precompile_headers(sv-bugpoint PUBLIC
2036
<string>
37+
<filesystem>
2138
<fstream>
2239
<chrono>
2340
<iostream>

source/SetRemovers.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <slang/ast/ASTVisitor.h>
44
#include <unordered_map>
55

6-
class FunctionArgMapper : public ASTVisitor<FunctionArgMapper, true, true, true> {
6+
class FunctionArgMapper final : public ASTVisitor<FunctionArgMapper, true, true, true> {
77
// Builds vector that maps the argument in definition to all calls
88
public:
99
std::vector<SetRemover::RemovalSet> removals;
@@ -135,11 +135,10 @@ SetRemover makeFunctionArgRemover(std::shared_ptr<SyntaxTree> tree) {
135135
return SetRemover(std::move(mapper.removals));
136136
}
137137

138-
class PortMapper : public ASTVisitor<PortMapper, true, true, true> {
138+
class PortMapper final : public ASTVisitor<PortMapper, true, true, true> {
139139
// Builds vector that maps the definitions and usages of ports
140140
public:
141141
class FindConnectionSyntax : public SyntaxVisitor<FindConnectionSyntax> {
142-
public:
143142
// PortConnection symbol does not have getSyntax() or sourceRange() methods.
144143
// This visitor finds sourceRange by locating PortConnectionSyntax that contains the same
145144
// expression as symbol
@@ -150,6 +149,8 @@ class PortMapper : public ASTVisitor<PortMapper, true, true, true> {
150149
} state;
151150

152151
SourceRange exprLoc;
152+
153+
public:
153154
SourceRange connLoc;
154155
FindConnectionSyntax(const PortConnection* symbol)
155156
: connLoc(SourceRange::NoLocation), state(WAIT_FOR_EXPR) {
@@ -227,7 +228,7 @@ SetRemover makePortsRemover(std::shared_ptr<SyntaxTree> tree) {
227228
return SetRemover(std::move(mapper.removals));
228229
}
229230

230-
class ExternMapper : public ASTVisitor<ExternMapper, true, true, true> {
231+
class ExternMapper final : public ASTVisitor<ExternMapper, true, true, true> {
231232
// Builds vector that maps the declarations (prototypes) and definitions (implementations) of
232233
// extern methods
233234
public:
@@ -245,11 +246,8 @@ class ExternMapper : public ASTVisitor<ExternMapper, true, true, true> {
245246
void handle(const MethodPrototypeSymbol& proto) {
246247
SourceRange protoLocation = SourceRange::NoLocation;
247248
SourceRange implLocation = SourceRange::NoLocation;
248-
if (proto.getSyntax()) {
249-
protoLocation = proto.getSyntax()->sourceRange();
250-
} else {
251-
exit(1);
252-
}
249+
ASSERT(proto.getSyntax(), "MethodPrototypeSymbol should have syntax node");
250+
protoLocation = proto.getSyntax()->sourceRange();
253251

254252
auto impl = proto.getSubroutine();
255253
if (impl && impl->getSyntax()) {
@@ -272,7 +270,7 @@ SetRemover makeExternRemover(std::shared_ptr<SyntaxTree> tree) {
272270
return SetRemover(std::move(mapper.removals));
273271
}
274272

275-
class StructFieldMapper : public ASTVisitor<StructFieldMapper, true, true, true> {
273+
class StructFieldMapper final : public ASTVisitor<StructFieldMapper, true, true, true> {
276274
// Builds vector that maps the definitions and initializations of struct fields
277275
public:
278276
std::vector<SetRemover::RemovalSet> removals;

source/SetRemovers.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class SetRemover : public SyntaxRewriter<SetRemover> {
2525
removals.pop_back();
2626
pendingNodes.clear();
2727
removedTypeInfo = "";
28-
for (const auto node : removal) {
28+
for (const auto& node : removal) {
2929
if (node != SourceRange::NoLocation) {
30-
pendingNodes.insert(node);
30+
pendingNodes.insert(std::move(node));
3131
}
3232
}
3333
if (pendingNodes.empty()) {
@@ -65,12 +65,10 @@ class SetRemover : public SyntaxRewriter<SetRemover> {
6565

6666
template <typename T>
6767
void visit(T&& node, bool isNodeRemovable = true) {
68-
auto it = pendingNodes.find(node.sourceRange());
69-
if (it != pendingNodes.end() && isNodeRemovable) {
68+
if (isNodeRemovable && pendingNodes.erase(node.sourceRange()) == 1) {
7069
logType<T>();
7170
std::cerr << prefixLines(node.toString(), "-") << "\n";
7271
remove(node);
73-
pendingNodes.erase(it);
7472
return;
7573
}
7674
visitDefault(node);

0 commit comments

Comments
 (0)