systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
FindEntryFunctions.cpp
Go to the documentation of this file.
2
4
5using namespace systemc_clang;
6using namespace sc_ast_matchers;
7
8FindEntryFunctions::FindEntryFunctions(const clang::CXXRecordDecl *d,
9 llvm::raw_ostream &os,
10 clang::ASTContext &ctx)
11 : context_{ctx},
12 os_{os},
13 _d{d},
14 is_entry_function_{false},
15 proc_type_{PROCESS_TYPE::NONE},
16 entry_cxx_record_decl_{nullptr},
17 entry_method_decl_{nullptr},
18 found_entry_decl_{false},
19 constructor_stmt_{nullptr},
20 pass_{1},
21 ctor_decl_{nullptr},
22 process_me_{nullptr} {
26 // os_ << "\n>>>> PASS 1\n";
27
28 TraverseDecl(const_cast<clang::CXXRecordDecl *>(_d));
29 // os_ << "\n EntryFunctions found: " << entry_function_list_.size() << "\n";
30 pass_ = 2;
31
33
34 // os_ << "\n>>>> PASS 2\n";
37 TraverseStmt(constructor_stmt_);
38 pass_ = 3;
39
42 TraverseDecl(const_cast<clang::CXXRecordDecl *>(_d));
43 pass_ = 4;
44}
45
51
55
57 // os_ << "\tVisitMemberExpr";
58 switch (pass_) {
59 case 2: {
60 std::string memberName = e->getMemberDecl()->getNameAsString();
61
62 // os_ <<"\n member name : " <<memberName;
63
64 // os_ << "####: MemberExpr -- " << memberName << "\n";
65 if (memberName == "create_method_process") {
67 process_me_ = e;
68 } else if (memberName == "create_thread_process") {
70 process_me_ = e;
71 } else if (memberName == "create_cthread_process") {
73 process_me_ = e;
74 }
75 break;
76 }
77 default:
78 break;
79 }
80 return true;
81}
82
84 // os_ << "\t\tVisitStringLiteral\n";
85 switch (pass_) {
86 case 2: {
87 // os_ << "\nVisitStringLiteral\n";
88 entry_name_ = s->getString().str();
89
92
93 LLVM_DEBUG(llvm::dbgs() << "********** 5. RESET Matcher ***********\n";);
94 assert(constructor_stmt_ != nullptr);
95
97 //ctor_decl_->dump();
98 //constructor_stmt_->dump();
99 ResetMatcher reset_matcher{};
100 MatchFinder resetMatchRegistry{};
101 reset_matcher.registerMatchers(resetMatchRegistry, process_me_);
102 resetMatchRegistry.match(*constructor_stmt_, context_);
103 reset_matcher.dump();
104
106 // ef->setConstructorStmt (constructor_stmt_);
109 ef->addResetSignal(reset_matcher.getResetSignal());
110 ef->addResetEdge(reset_matcher.getResetEdge());
111 ef->addResetType(reset_matcher.getResetType());
112 }
113
115 entry_function_list_.push_back(ef);
116 }
117 /* ef->constructor_stmt_ = constructor_stmt_;
118 ef->entry_name_ = entry_name_;
119 ef->proc_type_ = proc_type_;
120 */
121 break;
122 }
123 case 3: {
124 break;
125 }
126 default:
127 break;
128 }
129 return true;
130}
131
133 // os_ << "\nVisitCXXMethodDecl: " << pass_ << ", " << md->getNameAsString()
134 // << "\n";
135 other_function_list_.push_back(md);
136 switch (pass_) {
137 case 1: {
138 // os_ << "\n\nPass_ 1 of VisitCXXMethodDecl\n\n";
140 if (CXXConstructorDecl * cd{dyn_cast<CXXConstructorDecl>(md)}) {
141 ctor_decl_ = cd;
142 const FunctionDecl *fd{nullptr};
143 cd->getBody(fd);
144
145 if (cd->hasBody()) {
146 constructor_stmt_ = cd->getBody();
147 }
148 }
149 break;
150 }
151 case 2: {
152 // os_ << "\n\nPass_ 2 of VisitCXXMethodDecl\n\n";
153 break;
154 }
155 case 3: {
157 // os_ <<"\n md name : " <<md->getNameAsString();
158 for (size_t i = 0; i < entry_function_list_.size(); ++i) {
159 if (md->getNameAsString() == entry_function_list_.at(i)->getName()) {
162 if (entry_method_decl_ != nullptr) {
164 // ef->entry_method_decl_ = entry_method_decl_;
165 }
166 }
167 }
168 // os_ << "\n case 3: " << md->getNameAsString() << ", " << entry_name_
169 // << "\n";
170 break;
171 }
172 }
173 return true;
174}
175//
177 assert(entry_cxx_record_decl_ != nullptr);
179}
180
182 assert(entry_method_decl_ != nullptr);
183 return entry_method_decl_;
184}
185
187 os_ << "\n ============== FindEntryFunction ===============\n";
188 os_ << "\n:> Print Entry Function informtion for : " << _d->getNameAsString()
189 << "\n";
190 for (size_t i = 0; i < entry_function_list_.size(); ++i) {
192
193 os_ << "\n:> Entry function name: " << ef->getName() << ", process type: ";
194 switch (ef->getProcessType()) {
196 os_ << " SC_THREAD\n";
197 break;
199 os_ << " SC_METHOD\n";
200 break;
202 os_ << " SC_CTHREAD\n";
203 break;
204 default:
205 os_ << " NONE\n";
206 break;
207 }
208 os_ << ":> CXXMethodDecl addr: " << ef->getEntryMethod() << "\n";
209 // ef->entry_method_decl_->dump();
210 }
211 os_ << "\n ============== END FindEntryFunction ===============\n";
212 os_ << "\n";
213}
214
219
220vector<CXXMethodDecl *> FindEntryFunctions::getOtherFunctions() {
222}
223
void registerMatchers(MatchFinder &finder, clang::MemberExpr *process_expr)
void addResetEdge(std::pair< std::string, const clang::Expr * > reset_edge)
void addResetSignal(std::pair< std::string, const clang::Expr * > reset_signal)
virtual bool VisitCXXMethodDecl(CXXMethodDecl *d)
virtual bool VisitStringLiteral(StringLiteral *l)
Virtual methods from RecursiveASTVisitor.
vector< CXXMethodDecl * > other_function_list_
entryFunctionVectorType entry_function_list_
vector< CXXMethodDecl * > getOtherFunctions()
std::vector< EntryFunctionContainer * > entryFunctionVectorType
Typedefs.
FindEntryFunctions(const clang::CXXRecordDecl *d, llvm::raw_ostream &os, clang::ASTContext &ctx)
virtual bool VisitMemberExpr(MemberExpr *e)
clang::CXXConstructorDecl * ctor_decl_
entryFunctionVectorType * getEntryFunctions()