FindModule.cpp 2.4 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1 2 3 4 5 6 7 8
#include "FindModule.h"
#include "FindTemplateTypes.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceManager.h"

using namespace scpar;

rmrf's avatar
rmrf committed
9
string FindModule::getModuleName() const { return module_name_; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
10

rmrf's avatar
rmrf committed
11
FindModule::FindModule(CXXRecordDecl *declaration, llvm::raw_ostream &os)
12
    : declaration_{declaration}, os_{os}, is_systemc_module_{false} {
rmrf's avatar
rmrf committed
13 14
  if (declaration->hasDefinition() == true) {
    TraverseDecl(declaration);
rmrf's avatar
rmrf committed
15
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
16 17
}

rmrf's avatar
rmrf committed
18 19
bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
  if (declaration_->getNumBases() <= 0) {
rmrf's avatar
rmrf committed
20 21
    return true;
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
22

rmrf's avatar
rmrf committed
23
  // CXXRecordDecl::base_class_iterator
rmrf's avatar
rmrf committed
24 25
  for (auto bi = begin(declaration_->bases()), be = end(declaration_->bases());
       bi != be; ++bi) {
rmrf's avatar
rmrf committed
26
    string base_name = bi->getType().getAsString();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
27

rmrf's avatar
rmrf committed
28 29 30
    if (base_name == "::sc_core::sc_module" ||
        base_name == "sc_core::sc_module" ||
        base_name == "class sc_core::sc_module") {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
31

rmrf's avatar
rmrf committed
32
      is_systemc_module_ = true;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
33

rmrf's avatar
rmrf committed
34

rmrf's avatar
rmrf committed
35
      if (IdentifierInfo *info = declaration_->getIdentifier()) {
rmrf's avatar
rmrf committed
36
        module_name_ = info->getNameStart();
rmrf's avatar
rmrf committed
37

38 39 40 41 42 43 44 45 46
//         // Check if the class is a templated module class.
//       auto template_args{ declaration->getDescribedClassTemplate() };
//       if (template_args != nullptr) {
//           os_ << module_name_ << ": TEMPLATE ARGS YES \n";
//           template_parameters_ = template_args->getTemplateParameters();
//           //parms->getParam(0)->dump();
// //          parms->getParam(1)->dump();

//       }
rmrf's avatar
rmrf committed
47

rmrf's avatar
rmrf committed
48 49 50
      }
    }
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
51

rmrf's avatar
rmrf committed
52
  if (is_systemc_module_ == false) {
rmrf's avatar
rmrf committed
53 54
    return true;
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
55

rmrf's avatar
rmrf committed
56
  return false;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
57 58
}

59 60 61 62 63 64 65 66 67 68 69 70 71
// vector<string> FindModule::getTemplateParameters() const {
//     vector<string> parm_list;
//     if ( (template_parameters_ == nullptr)
//         || (template_parameters_->size() <= 0) ) {
//         return parm_list;
//     }

//     for (auto parm : template_parameters_->asArray() ) {
//         parm_list.push_back( parm->getName() );
//         os_ << "Parm: " << parm->getName() << "\n";
//     }
//     return parm_list;
// }
rmrf's avatar
rmrf committed
72

rmrf's avatar
rmrf committed
73
FindModule::~FindModule() { declaration_ = nullptr; }
74

rmrf's avatar
rmrf committed
75
bool FindModule::isSystemCModule() const { return is_systemc_module_; }
rmrf's avatar
rmrf committed
76

rmrf's avatar
rmrf committed
77
void FindModule::dump() {
rmrf's avatar
rmrf committed
78 79 80 81 82
  os_ << "\n ============== FindModule ===============";
  os_ << "\n:> module name: " << module_name_
      << ", CXXRecordDecl*: " << declaration_
      << ", isSCModule: " << is_systemc_module_;
  os_ << "\n ============== END FindModule ===============";
Anirudh Kaushik's avatar
Anirudh Kaushik committed
83
}