Commit bcd25d3b authored by rmrf's avatar rmrf

Stage 1: Template sc_module classes

This is the first commit to detect templated SystemC classes.  This will
recognize the template parameters for the class declaration. The next
step will be in determining wait() statements that take as arguments the
template parameters.
parent 49519da8
...@@ -9,12 +9,13 @@ using namespace scpar; ...@@ -9,12 +9,13 @@ using namespace scpar;
string FindModule::getModuleName() const { return module_name_; } string FindModule::getModuleName() const { return module_name_; }
FindModule::FindModule(CXXRecordDecl *declaration, llvm::raw_ostream &os) FindModule::FindModule(CXXRecordDecl *declaration, llvm::raw_ostream &os)
: declaration_{declaration}, os_{os}, is_systemc_module_{false} { : declaration_{declaration}, os_{os}, is_systemc_module_{false}, template_parameters_{nullptr} {
if (declaration->hasDefinition() == true) { if (declaration->hasDefinition() == true) {
TraverseDecl(declaration); TraverseDecl(declaration);
} }
} }
bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
if (declaration_->getNumBases() <= 0) { if (declaration_->getNumBases() <= 0) {
return true; return true;
...@@ -31,8 +32,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { ...@@ -31,8 +32,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
is_systemc_module_ = true; is_systemc_module_ = true;
if (IdentifierInfo *info = declaration_->getIdentifier()) { if (IdentifierInfo *info = declaration_->getIdentifier()) {
module_name_ = info->getNameStart(); module_name_ = info->getNameStart();
// 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();
}
} }
} }
} }
...@@ -44,6 +56,20 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { ...@@ -44,6 +56,20 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
return false; return false;
} }
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;
}
FindModule::~FindModule() { declaration_ = nullptr; } FindModule::~FindModule() { declaration_ = nullptr; }
bool FindModule::isSystemCModule() const { return is_systemc_module_; } bool FindModule::isSystemCModule() const { return is_systemc_module_; }
......
...@@ -14,17 +14,20 @@ class FindModule : public RecursiveASTVisitor<FindModule> { ...@@ -14,17 +14,20 @@ class FindModule : public RecursiveASTVisitor<FindModule> {
public: public:
FindModule(CXXRecordDecl *, llvm::raw_ostream &); FindModule(CXXRecordDecl *, llvm::raw_ostream &);
virtual bool VisitCXXRecordDecl(CXXRecordDecl *decl); virtual bool VisitCXXRecordDecl(CXXRecordDecl *decl);
virtual ~FindModule(); virtual ~FindModule();
void dump(); void dump();
string getModuleName() const; string getModuleName() const;
bool isSystemCModule() const; bool isSystemCModule() const;
vector<string> getTemplateParameters() const;
private: private:
CXXRecordDecl *declaration_; CXXRecordDecl *declaration_;
llvm::raw_ostream &os_; llvm::raw_ostream &os_;
bool is_systemc_module_; bool is_systemc_module_;
string module_name_; string module_name_;
TemplateParameterList *template_parameters_;
}; };
} // namespace scpar } // namespace scpar
#endif #endif
...@@ -19,6 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) { ...@@ -19,6 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) {
} }
string modName = mod.getModuleName(); string modName = mod.getModuleName();
_moduleMap.insert(modulePairType(modName, cxxDecl)); _moduleMap.insert(modulePairType(modName, cxxDecl));
template_parameters_ = mod.getTemplateParameters();
return true; return true;
} }
......
...@@ -25,6 +25,7 @@ public: ...@@ -25,6 +25,7 @@ public:
private: private:
llvm::raw_ostream &_os; llvm::raw_ostream &_os;
moduleMapType _moduleMap; moduleMapType _moduleMap;
vector<string> template_parameters_;
}; };
} // namespace scpar } // namespace scpar
#endif #endif
...@@ -24,6 +24,14 @@ bool FindWait::VisitCallExpr(CallExpr *e) { ...@@ -24,6 +24,14 @@ bool FindWait::VisitCallExpr(CallExpr *e) {
LangOpts.CPlusPlus = true; LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy(LangOpts); clang::PrintingPolicy Policy(LangOpts);
os_ << "===============\n"; //
e->dump();
os_ << e->getNumArgs();
Expr * arge{ e->getArg(0) };
os_ << "\n argument dump\n";
arge->dump();
// e->getDirectCallee()->dump();
os_ << "END===============\n"; //
if (e->getDirectCallee()->getNameInfo().getAsString() == string("wait")) { if (e->getDirectCallee()->getNameInfo().getAsString() == string("wait")) {
wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, e)); wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, e));
} }
......
...@@ -10,7 +10,7 @@ ModuleDecl::ModuleDecl() : module_name_{"NONE"}, ...@@ -10,7 +10,7 @@ ModuleDecl::ModuleDecl() : module_name_{"NONE"},
constructor_stmt_{nullptr} {} constructor_stmt_{nullptr} {}
ModuleDecl::ModuleDecl(const string &name, CXXRecordDecl *decl) ModuleDecl::ModuleDecl(const string &name, CXXRecordDecl *decl)
: module_name_{name}, class_decl_{decl} {} : module_name_{name}, class_decl_{decl} {}
ModuleDecl::~ModuleDecl() { ModuleDecl::~ModuleDecl() {
...@@ -218,7 +218,7 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) { ...@@ -218,7 +218,7 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) {
} }
void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) { void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) {
json process_j; json process_j;
process_j["number_of_processes"] = process_map_.size(); process_j["number_of_processes"] = process_map_.size();
for (auto pit : process_map_) { for (auto pit : process_map_) {
......
...@@ -104,10 +104,13 @@ private: ...@@ -104,10 +104,13 @@ private:
interfaceMapType _ointerfaces; interfaceMapType _ointerfaces;
interfaceMapType _iointerfaces; interfaceMapType _iointerfaces;
signalMapType _signals; signalMapType _signals;
vector<string> _instanceList; vector<string> _instanceList;
portSignalMapType _portSignalMap; portSignalMapType _portSignalMap;
vector<EntryFunctionContainer *> _vef; vector<EntryFunctionContainer *> _vef;
// Class template parameters.
vector<string> template_parameters_;
}; };
} // namespace scpar } // namespace scpar
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment