-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using AST matchers with templates identifies each template expansion.
This needs to reviewed. When modules use template parameters, the parsing of modules identifies multiple declarations since that is what the compiler generates for the parameter variants provided to the template arguments.
- Loading branch information
rmrf
committed
Dec 10, 2019
1 parent
8b8c82d
commit 79e822b
Showing
2 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "systemc.h" | ||
|
||
SC_MODULE( non_template ) { | ||
SC_CTOR(non_template) { | ||
}; | ||
}; | ||
|
||
template <typename S, typename T> | ||
SC_MODULE( test ){ | ||
sc_in_clk clk; | ||
sc_in<S> inS; | ||
sc_out<S> outS; | ||
sc_signal<S> test_signal; | ||
|
||
sc_in<T> inT; | ||
sc_in<T> outT; | ||
void entry_function_1() { | ||
while(true) { | ||
// do nothing | ||
} | ||
} | ||
|
||
SC_CTOR( test ) { | ||
SC_METHOD(entry_function_1); | ||
sensitive << clk.pos(); | ||
} | ||
}; | ||
|
||
int sc_main(int argc, char *argv[]) { | ||
sc_clock clk; | ||
sc_signal<int> sig1; | ||
test<int,double> test_instance("testing"); | ||
test_instance.clk(clk); | ||
test_instance.inS(sig1); | ||
test_instance.outS(sig1); | ||
|
||
return 0; | ||
} |
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,53 @@ | ||
#include "PluginAction.h" | ||
#include "SystemCClang.h" | ||
#include "catch.hpp" | ||
#include "clang/AST/ASTImporter.h" | ||
#include "clang/ASTMatchers/ASTMatchFinder.h" | ||
#include "clang/ASTMatchers/ASTMatchers.h" | ||
#include "clang/Parse/ParseAST.h" | ||
#include "clang/Tooling/Tooling.h" | ||
|
||
#include "Matchers.h" | ||
|
||
// This is automatically generated from cmake. | ||
#include "ClangArgs.h" | ||
#include "Testing.h" | ||
|
||
using namespace clang; | ||
using namespace clang::tooling; | ||
using namespace clang::ast_matchers; | ||
using namespace scpar; | ||
using namespace sc_ast_matchers; | ||
|
||
TEST_CASE("Read SystemC model from file for testing", "[parsing]") { | ||
std::string code{systemc_clang::read_systemc_file( | ||
systemc_clang::test_data_dir, "templated-module.cpp")}; | ||
|
||
ASTUnit *from_ast = | ||
tooling::buildASTFromCodeWithArgs(code, systemc_clang::catch_test_args) | ||
.release(); | ||
|
||
llvm::outs() << "================ TESTMATCHER =============== \n"; | ||
ModuleDeclarationMatcher module_declaration_handler{}; | ||
MatchFinder matchRegistry{}; | ||
module_declaration_handler.registerMatchers(matchRegistry); | ||
// Run all the matchers | ||
matchRegistry.matchAST(from_ast->getASTContext()); | ||
module_declaration_handler.dump(); | ||
llvm::outs() << "================ END =============== \n"; | ||
|
||
|
||
|
||
|
||
/* | ||
SystemCConsumer sc{from_ast}; | ||
sc.HandleTranslationUnit(from_ast->getASTContext()); | ||
auto model{sc.getSystemCModel()}; | ||
auto module_decl{model->getModuleDecl()}; | ||
*/ | ||
|
||
SECTION("Test systemc-clang AST matchers ", "[matchers]") { | ||
// The module instances have all the information. | ||
REQUIRE( true ); | ||
} | ||
} |