23#include "clang/ASTMatchers/ASTMatchers.h"
30#define DEBUG_TYPE "Matchers"
46 typedef std::multimap<clang::CXXRecordDecl *, ModuleInstance *>
ModuleMapType;
66 virtual void run(
const MatchFinder::MatchResult &result) {}
72 MatchFinder port_registry{};
75 port_registry.match(*decl, context);
77 LLVM_DEBUG(llvm::dbgs() <<
"========== Port Matcher =============\n";
83 add_module->
addPorts(port_matcher.getInputPorts(),
"sc_in");
85 add_module->
addPorts(port_matcher.getClockPorts(),
"sc_in");
86 add_module->
addPorts(port_matcher.getOutputPorts(),
"sc_out");
87 add_module->
addPorts(port_matcher.getInOutPorts(),
"sc_inout");
88 add_module->
addPorts(port_matcher.getOtherVars(),
"others");
89 add_module->
addPorts(port_matcher.getSignals(),
"sc_signal");
90 add_module->
addPorts(port_matcher.getInputStreamPorts(),
"sc_stream_in");
91 add_module->
addPorts(port_matcher.getOutputStreamPorts(),
"sc_stream_out");
92 add_module->
addPorts(port_matcher.getSubmodules(),
"submodules");
96 clang::CXXRecordDecl *cxx_decl,
107 LLVM_DEBUG(llvm::dbgs() <<
"4. Set the constructor.\n";);
108 std::vector<EntryFunctionContainer *> _entryFunctionContainerVector;
118 LLVM_DEBUG(llvm::dbgs() <<
"5. Set the entry functions\n";);
120 llvm::dbgs(), context};
123 findEntries.getEntryFunctions()};
125 LLVM_DEBUG(llvm::dbgs() <<
"6. Set the process\n";);
129 MatchFinder matchRegistry{};
131 if (constructor.getConstructorDecl()) {
132 matchRegistry.match(*constructor.getConstructorDecl(), context);
135 for (
size_t i{0}; i < entryFunctions->size(); i++) {
140 sens_matcher.getSensitivityMap()};
143 if (ef->getEntryMethod() ==
nullptr) {
144 LLVM_DEBUG(llvm::dbgs() <<
"ERROR";);
148 FindWait findWaits{ef->getEntryMethod(), llvm::dbgs()};
149 ef->addWaits(findWaits);
151 FindNotify findNotify{ef->getEntryMethod(), llvm::dbgs()};
152 ef->addNotifys(findNotify);
154 _entryFunctionContainerVector.push_back(ef);
160 for (
const auto &inst : instance_map) {
162 clang::CXXRecordDecl *decl{
163 dyn_cast<clang::CXXRecordDecl>(inst.second.getInstanceTypeDecl())};
164 clang::ValueDecl *vd{
165 dyn_cast<clang::ValueDecl>(inst.second.getInstanceDecl())};
168 for (
const auto &base_decl : base_decls) {
169 LLVM_DEBUG(llvm::dbgs() <<
"=============================== BASES "
170 << decl->getNameAsString()
171 <<
" =======================\n";
172 llvm::dbgs() <<
"Run base instance matcher: "
173 << base_decl->getNameAsString() <<
" \n";);
176 MatchFinder base_instance_reg{};
179 base_instance_reg.match(*base_decl, context);
180 LLVM_DEBUG(llvm::dbgs() <<
"+ Dump base instance matcher\n";
181 base_instance_matcher.
dump();
182 llvm::dbgs() <<
"+ End dump base instance matcher\n";);
196 llvm::dbgs() <<
"###### DUMP Instance Matches \n";
213 for (
const auto &inst : instance_map) {
214 clang::CXXRecordDecl *decl{
215 dyn_cast<clang::CXXRecordDecl>(inst.second.getInstanceTypeDecl())};
216 auto name{decl->getNameAsString()};
217 LLVM_DEBUG(llvm::dbgs() <<
"class: " << name <<
"\n";);
224 for (
const auto &inst : instance_map) {
227 clang::CXXRecordDecl *decl{
228 dyn_cast<clang::CXXRecordDecl>(inst.second.getInstanceTypeDecl())};
229 auto name{decl->getNameAsString()};
230 LLVM_DEBUG(llvm::dbgs() <<
"############### ====> INST: " << inst.first
231 <<
", name: " << name <<
", instance_name: "
232 << inst.second.instance_name <<
"\n";);
235 add_module->setInstanceInfo(instance);
239 modules_.insert(std::pair<clang::CXXRecordDecl *, ModuleInstance *>(
242 LLVM_DEBUG(llvm::dbgs() <<
"[Running module declaration matchers]\n";);
244 LLVM_DEBUG(llvm::dbgs() <<
"[Running port matcher]\n";);
247 LLVM_DEBUG(llvm::dbgs() <<
"[Running Base class logic]\n";);
252 for (
const auto &base_decl : base_decls) {
253 auto name{base_decl->getNameAsString()};
256 LLVM_DEBUG(base_decl->dump();
258 <<
"Base class: " << base_decl->getNameAsString() <<
"\n";);
261 context,
const_cast<clang::CXXRecordDecl *
>(base_decl),
262 base_module_instance);
264 add_module->addBaseInstance(base_module_instance);
265 LLVM_DEBUG(llvm::dbgs() <<
"End base logic loop\n";);
271 llvm::outs() <<
"[DBG] Module instances: " <<
modules_.size() <<
"\n";
273 auto cxx_decl{i.first};
275 auto module_decl{i.second};
276 auto decl_name{module_decl->getName()};
278 LLVM_DEBUG(llvm::outs() <<
"CXXRecordDecl* " << cxx_decl
279 <<
", module name: " << decl_name <<
"\n";);
void setParentFieldDecl(clang::ValueDecl *parent_fd)
void registerMatchers(MatchFinder &finder)
const InstanceDeclarations & getInstanceMap()
Class ModuleDeclarationMatcher.
InstanceMatcher instance_matcher_
const ModuleMapType & getFoundModuleDeclarations() const
void registerMatchers(MatchFinder &finder)
Register the matchers.
void processInstanceCXXDecls(ASTContext &context)
const InstanceMatcher & getInstanceMatcher()
void runPortMatcher(ASTContext &context, const clang::CXXRecordDecl *decl, ModuleInstance *add_module)
void matchInstancesInBaseClasses(ASTContext &context)
virtual void run(const MatchFinder::MatchResult &result)
void runModuleDeclarationMatchers(ASTContext &context, clang::CXXRecordDecl *cxx_decl, ModuleInstance *add_module_decl)
std::pair< clang::CXXRecordDecl *, ModuleInstance * > ModulePairType
This will store all the modules as ModuleDecl.
std::multimap< clang::CXXRecordDecl *, ModuleInstance * > ModuleMapType
std::vector< InstanceMatcher::InstanceDeclType > InstanceListType
void registerMatchers(MatchFinder &finder)
Class SensitivityMatcher.
void registerMatchers(MatchFinder &finder)
Defines the matcher, and setup the matcher.
std::map< std::string, std::vector< SensitivityTupleType > > SenseMapType
void addSensitivityInfo(SenseMapType &)
std::vector< EntryFunctionContainer * > entryFunctionVectorType
Typedefs.
void addConstructor(FindConstructor *)
const clang::CXXRecordDecl * getModuleClassDecl()
void setTemplateArgs(const vector< std::string > &)
void setTemplateParameters(const vector< std::string > &)
void addProcess(FindEntryFunctions::entryFunctionVectorType *)
void addPorts(const PortType &found_ports, const std::string &port_type)
std::vector< const clang::CXXRecordDecl * > getAllBaseClasses(const clang::CXXRecordDecl *decl)