-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* slang-tidy fix NoOldAlwaysSyntax check when dealing with assertions The NoOldAlwaysSyntax check was miss triggering with the property clock, this commit checks if block is an assertion to not trigger the check. * slang-tidy add new check EnforceModuleInstantiationPrefix This new check will enforce a prefix string in module instantiation * slang-tidy minor syntax fixes * style: pre-commit fixes * slang-tidy remove unnecessary include
- Loading branch information
Showing
11 changed files
with
209 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: Michael Popoloski | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "ASTHelperVisitors.h" | ||
#include "TidyDiags.h" | ||
#include "fmt/color.h" | ||
|
||
#include "slang/syntax/AllSyntax.h" | ||
|
||
using namespace slang; | ||
using namespace slang::ast; | ||
|
||
namespace enforce_module_instantiation_prefix { | ||
struct MainVisitor : public TidyVisitor, ASTVisitor<MainVisitor, true, false> { | ||
explicit MainVisitor(Diagnostics& diagnostics) : TidyVisitor(diagnostics) {} | ||
|
||
void handle(const InstanceSymbol& instance) { | ||
NEEDS_SKIP_SYMBOL(instance) | ||
|
||
if (!instance.isModule()) | ||
return; | ||
|
||
std::string_view prefix = config.getCheckConfigs().moduleInstantiationPrefix; | ||
for (auto& member : instance.body.members()) { | ||
if (!member.name.starts_with(prefix)) { | ||
diags.add(diag::EnforcePortSuffix, member.location) << member.name << prefix; | ||
} | ||
} | ||
} | ||
}; | ||
} // namespace enforce_module_instantiation_prefix | ||
|
||
using namespace enforce_module_instantiation_prefix; | ||
class EnforceModuleInstantiationPrefix : public TidyCheck { | ||
public: | ||
[[maybe_unused]] explicit EnforceModuleInstantiationPrefix(TidyKind kind) : TidyCheck(kind) {} | ||
|
||
bool check(const ast::RootSymbol& root) override { | ||
MainVisitor visitor(diagnostics); | ||
root.visit(visitor); | ||
if (!diagnostics.empty()) | ||
return false; | ||
return true; | ||
} | ||
|
||
DiagCode diagCode() const override { return diag::EnforceModuleInstantiationPrefix; } | ||
DiagnosticSeverity diagSeverity() const override { return DiagnosticSeverity::Warning; } | ||
std::string diagString() const override { | ||
return "module instantiation '{}' is not correctly suffixed with prefix: '{}'"; | ||
} | ||
std::string name() const override { return "EnforceModuleInstantiationPrefix"; } | ||
std::string description() const override { | ||
return "Enforces that module instantiations in the design follow the code guidelines " | ||
"provided in the configuration file by the config " + | ||
fmt::format(fmt::emphasis::italic, "moduleInstantiationPrefix"); | ||
} | ||
std::string shortDescription() const override { | ||
return "Enforces that module instantiations in the design follows the code guidelines " | ||
"provided in the configuration file"; | ||
} | ||
}; | ||
|
||
REGISTER(EnforceModuleInstantiationPrefix, EnforceModuleInstantiationPrefix, TidyKind::Style) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: Michael Popoloski | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "Test.h" | ||
#include "TidyFactory.h" | ||
|
||
TEST_CASE("EnforceModuleInstantiationPrefix: Incorrect module instantiation prefix") { | ||
auto tree = SyntaxTree::fromText(R"( | ||
module test (); | ||
endmodule | ||
module top(); | ||
test test(); | ||
endmodule | ||
)"); | ||
|
||
Compilation compilation; | ||
compilation.addSyntaxTree(tree); | ||
compilation.getAllDiagnostics(); | ||
auto& root = compilation.getRoot(); | ||
|
||
TidyConfig config; | ||
Registry::setConfig(config); | ||
Registry::setSourceManager(compilation.getSourceManager()); | ||
auto visitor = Registry::create("EnforceModuleInstantiationPrefix"); | ||
bool result = visitor->check(root); | ||
CHECK_FALSE(result); | ||
} | ||
|
||
TEST_CASE("EnforceModuleInstantiationPrefix: Correct module instantiation prefix") { | ||
auto tree = SyntaxTree::fromText(R"( | ||
module test (); | ||
endmodule | ||
module top(); | ||
test i_test(); | ||
endmodule | ||
)"); | ||
|
||
Compilation compilation; | ||
compilation.addSyntaxTree(tree); | ||
compilation.getAllDiagnostics(); | ||
auto& root = compilation.getRoot(); | ||
|
||
TidyConfig config; | ||
Registry::setConfig(config); | ||
Registry::setSourceManager(compilation.getSourceManager()); | ||
auto visitor = Registry::create("EnforceModuleInstantiationPrefix"); | ||
bool result = visitor->check(root); | ||
CHECK(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters