35 auto found_inst_it = std::find_if(
36 instances.begin(), instances.end(), [decl](
const auto &instance) {
37 const clang::Decl *i{instance->getInstanceDecl()};
38 return (instance->getInstanceDecl() == decl);
41 if (found_inst_it != instances.end()) {
42 return *found_inst_it;
51 module_matcher_ = module_matcher;
56 auto match_sc_main_callexpr = functionDecl(
61 hasDeclaration(varDecl().bind(
"bound_variable")),
62 hasParent(implicitCastExpr())
66 hasDescendant(memberExpr(
67 forEach(declRefExpr().bind(
"declrefexpr_in_memberexpr"))
72 ).bind(
"functiondecl");
76 const auto not_sc_sensitive = unless(hasType(cxxRecordDecl(isDerivedFrom(
"sc_core::sc_sensitive"))));
77 const auto not_sc_event_finder = unless(hasType(cxxRecordDecl(isDerivedFrom(
"sc_core::sc_event_finder"))));
79 const auto has_allowed_types =
81 hasType(cxxRecordDecl(isDerivedFrom(hasName(
"sc_core::sc_module")))),
82 hasType(cxxRecordDecl(isDerivedFrom(hasName(
"sc_core::sc_port")))),
83 hasType(cxxRecordDecl(isDerivedFrom(hasName(
"sc_core::sc_signal"))))
86 const auto caller_array_subscript =
90 memberExpr().bind(
"caller_port_me_expr")
92 ).bind(
"caller_expr") ;
96 const auto match_callers =
98 hasDescendant(caller_array_subscript)
109 memberExpr(has_allowed_types).bind(
"caller_expr")
113 hasAncestor(arraySubscriptExpr().bind(
"caller_array_port_expr"))
114 ).bind(
"caller_port_me_expr"))
120 memberExpr(has_allowed_types).bind(
"caller_expr")
125 ).bind(
"caller_port_me_expr"))
128 const auto callee_array_subscript =
132 memberExpr().bind(
"callee_port_me_expr")
134 ).bind(
"callee_expr") ;
139 const auto match_callees =
141 ignoringImplicit(has(callee_array_subscript))
143 ignoringImplicit(expr().bind(
"callee_expr") )
147 auto not_operator_less_than = unless(callee(cxxMethodDecl(hasName(
"operator<<"))));
149 auto test_match_ctor_decl =
154 not_operator_less_than,
164 .bind(
"compoundstmt"))
165 ).bind(
"named_decl");
172 finder.addMatcher(test_match_ctor_decl,
this);
183 virtual void run(
const MatchFinder::MatchResult &result) {
186 <<
"#### ============ NETLIST HAD A MATCH ============ ####\n";);
190 auto named_decl{
const_cast<clang::NamedDecl *
>(
191 result.Nodes.getNodeAs<clang::NamedDecl>(
"named_decl"))};
192 auto opcall{
const_cast<clang::CXXOperatorCallExpr *
>(
193 result.Nodes.getNodeAs<clang::CXXOperatorCallExpr>(
"opcall"))};
195 auto caller_expr{
const_cast<clang::Expr *
>(
196 result.Nodes.getNodeAs<clang::Expr>(
"caller_expr"))};
197 auto callee_expr{
const_cast<clang::Expr *
>(
198 result.Nodes.getNodeAs<clang::Expr>(
"callee_expr"))};
200 auto caller_array_expr{
const_cast<clang::ArraySubscriptExpr *
>(
201 result.Nodes.getNodeAs<clang::ArraySubscriptExpr>(
"caller_expr"))};
202 auto callee_array_expr{
const_cast<clang::ArraySubscriptExpr *
>(
203 result.Nodes.getNodeAs<clang::ArraySubscriptExpr>(
"callee_expr"))};
205 auto caller_array_port_expr{
const_cast<clang::ArraySubscriptExpr *
>(
206 result.Nodes.getNodeAs<clang::ArraySubscriptExpr>(
207 "caller_array_port_expr"))};
210 auto caller_port_me_expr{
const_cast<clang::MemberExpr *
>(
211 result.Nodes.getNodeAs<clang::MemberExpr>(
"caller_port_me_expr"))};
212 auto callee_port_me_expr{
const_cast<clang::MemberExpr *
>(
213 result.Nodes.getNodeAs<clang::MemberExpr>(
"callee_port_me_expr"))};
238 if (caller_expr && callee_expr) {
240 caller_port_me_expr, callee_expr,
241 callee_port_me_expr)};
245 llvm::dbgs() <<
"Try to add it into the module\n";
252 const clang::MemberExpr *caller_me_expr{
nullptr};
253 if (caller_array_expr) {
255 }
else if (caller_expr) {
256 caller_me_expr = clang::dyn_cast<clang::MemberExpr>(caller_expr);
259 if (caller_me_expr) {
260 auto caller_instance_decl{caller_me_expr->getMemberDecl()};
261 auto caller_instance_type{caller_instance_decl->getType().getTypePtr()};
263 findModuleDeclInstance(caller_instance_decl)};
264 if (instance_module_decl) {
266 llvm::dbgs() <<
"INSTANCE MODULE :"
267 << instance_module_decl->getInstanceName() <<
"\n";
268 llvm::dbgs() <<
" port name : " << pb->getCallerPortName() <<
"\n";
269 llvm::dbgs() <<
" PARENT@@@@ : "
270 << instance_module_decl->getInstanceInfo()
278 instance_module_decl->getInstanceInfo().getParentDecl())};
279 LLVM_DEBUG(llvm::dbgs() <<
" PARENT@@@@ INST NAME: "
280 << parent_decl->getInstanceName() <<
"\n";
285 std::string binding_name{pb->getCallerInstanceName() +
286 pb->getCallerPortName()};
287 parent_decl->addPortBinding(binding_name, pb);
288 pb->setInstanceConstructorName(instance_module_decl->getInstanceName());