systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
ResetMatcher.h
Go to the documentation of this file.
1#ifndef _RESET_MATCHER_H_
2#define _RESET_MATCHER_H_
3
4#include "clang/ASTMatchers/ASTMatchers.h"
5#include "llvm/Support/Debug.h"
6
8#undef DEBUG_TYPE
9#define DEBUG_TYPE "ResetMatcher"
10
11using namespace clang::ast_matchers;
12
13namespace sc_ast_matchers {
14using namespace clang;
15
16class ResetMatcher : public MatchFinder::MatchCallback {
17 private:
18 std::pair<std::string, const clang::Expr*> reset_signal_;
19 std::pair<std::string, const clang::Expr*> edge_;
21
22 public:
23 std::pair<std::string, const clang::Expr*> getResetSignal() const {
24 return reset_signal_;
25 }
26 std::pair<std::string, const clang::Expr*> getResetEdge() const {
27 return edge_;
28 }
29 bool getResetType() const { return reset_async_; }
30
31 public:
32 void registerMatchers(MatchFinder& finder, clang::MemberExpr* process_expr) {
34 std::string member_name{process_expr->getMemberDecl()->getNameAsString()};
35
36 // clang-format off
37 auto reset_matcher = stmt(
38 anyOf(
39 allOf(
40 hasDescendant(
41 memberExpr(hasDeclaration(cxxMethodDecl(hasName(member_name)))).bind("cxx_me_proc")
42 )
43 ,
44 hasDescendant(
45 cxxMemberCallExpr(callee(cxxMethodDecl(hasName("async_reset_signal_is")))).bind("cxx_me_async")
46 ) // hasDescendant
47 ) //allOf
48 ,
49
50 allOf(
51 hasDescendant(
52 memberExpr(hasDeclaration(cxxMethodDecl(hasName(member_name)))).bind("cxx_me_proc")
53 )
54 ,
55 hasDescendant(
56 cxxMemberCallExpr(callee(cxxMethodDecl(hasName("reset_signal_is")))).bind("cxx_me_sync")
57 ) // hasDescendant
58 ) //allOf
59 ) //anyOf
60 ).bind("reset_expr");
61 // clang-format on
62
63 finder.addMatcher(reset_matcher, this);
64 }
65
66 virtual void run(const MatchFinder::MatchResult& result) {
67 llvm::dbgs() << "RESET MATCHER FOUND\n";
68 // auto ctor_decl{
69 // result.Nodes.getNodeAs<clang::CXXConstructorDecl>("reset_expr")};
70 auto cxx_me_proc{result.Nodes.getNodeAs<clang::MemberExpr>("cxx_me_proc")};
71 auto cxx_me_async{
72 result.Nodes.getNodeAs<clang::CXXMemberCallExpr>("cxx_me_async")};
73 auto cxx_me_sync{
74 result.Nodes.getNodeAs<clang::CXXMemberCallExpr>("cxx_me_sync")};
75 const clang::CXXMemberCallExpr* cxx_me{nullptr};
76
77 // if (cxx_me_proc) {
78 // llvm::dbgs() << " PROC MATCH\n";
79 // cxx_me_proc->dump();
80 // }
81//
82 cxx_me = cxx_me_sync;
83
84 reset_async_ = false;
85 if (cxx_me_async) {
86 reset_async_ = true;
87 llvm::dbgs() << "SETTING RESET TO TRUE\n";
88 cxx_me = cxx_me_async;
89 }
90
91 if (cxx_me) {
92 cxx_me->dump();
94 const clang::Expr* rsig{cxx_me->getArg(0)->IgnoreImplicit()};
95 const clang::Expr* high_low{cxx_me->getArg(1)->IgnoreImplicit()};
96
97 if (rsig && high_low) {
98 const clang::MemberExpr* rsig_name =
99 clang::dyn_cast<clang::MemberExpr>(rsig);
100
101 llvm::dbgs() << "high low \n";
102 high_low->dump();
103
104 const clang::CXXBoolLiteralExpr* edge_name =
105 clang::dyn_cast<clang::CXXBoolLiteralExpr>(high_low);
106
107 if (rsig_name && edge_name) {
108 reset_signal_.first = rsig_name->getMemberDecl()->getNameAsString();
109 reset_signal_.second = rsig;
110
111 edge_.first = "false";
112 if (edge_name->getValue()) {
113 edge_.first = "true";
114 }
115 edge_.second = high_low;
116 }
117 }
118 }
119 }
120
121 void dump() {
122 llvm::dbgs() << "reset_signal " << reset_signal_.first << "\n";
123 llvm::dbgs() << "active_edge " << edge_.first << "\n";
124 llvm::dbgs() << "reset_async " << reset_async_ << "\n";
125 }
126};
127}; // namespace sc_ast_matchers
128
129#endif
std::pair< std::string, const clang::Expr * > getResetSignal() const
std::pair< std::string, const clang::Expr * > reset_signal_
std::pair< std::string, const clang::Expr * > getResetEdge() const
std::pair< std::string, const clang::Expr * > edge_
virtual void run(const MatchFinder::MatchResult &result)
void registerMatchers(MatchFinder &finder, clang::MemberExpr *process_expr)
Clang forward declarations.
Definition FindArgument.h:6