diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76e9c1aa018493c192d0d0db79e3fc77c4a95006..d20075431c70af17d829d54718d2f0b10fc6919c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ add_library (libsystemc-clang SystemCClang.cpp FindNetlist.cpp FindArgument.cpp + FindTemplateParameters.cpp Automata.cpp SuspensionAutomata.cpp SCuitable/GlobalSuspensionAutomata.cpp @@ -36,7 +37,7 @@ add_library (libsystemc-clang InterfaceDecl.cpp Model.cpp WaitCalls.cpp - NotifyCalls.cpp + NotifyCalls.cpp EventContainer.cpp - + ) diff --git a/src/FindModule.cpp b/src/FindModule.cpp index 21e71b64eef0cd19a84b01ad3573d3c554970b70..9985420e05e568d7557d27622d53c1e065a7617c 100644 --- a/src/FindModule.cpp +++ b/src/FindModule.cpp @@ -9,13 +9,12 @@ using namespace scpar; string FindModule::getModuleName() const { return module_name_; } FindModule::FindModule(CXXRecordDecl *declaration, llvm::raw_ostream &os) - : declaration_{declaration}, os_{os}, is_systemc_module_{false}, template_parameters_{nullptr} { + : declaration_{declaration}, os_{os}, is_systemc_module_{false} { if (declaration->hasDefinition() == true) { TraverseDecl(declaration); } } - bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { if (declaration_->getNumBases() <= 0) { return true; @@ -36,15 +35,16 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { if (IdentifierInfo *info = declaration_->getIdentifier()) { 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(); +// // 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(); + +// } - } } } } @@ -56,19 +56,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { return false; } -vector FindModule::getTemplateParameters() const { - vector 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; -} +// vector FindModule::getTemplateParameters() const { +// vector 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; } diff --git a/src/FindModule.h b/src/FindModule.h index a6eacf2acc22196b29657de1243cac927de4d03d..b7dd7a54591b5fc64e0b51be2db1db1bb7cfa42b 100644 --- a/src/FindModule.h +++ b/src/FindModule.h @@ -20,14 +20,14 @@ public: void dump(); string getModuleName() const; bool isSystemCModule() const; - vector getTemplateParameters() const; + // vector getTemplateParameters() const; private: CXXRecordDecl *declaration_; llvm::raw_ostream &os_; bool is_systemc_module_; string module_name_; - TemplateParameterList *template_parameters_; +// TemplateParameterList *template_parameters_; }; } // namespace scpar #endif diff --git a/src/FindSCModules.cpp b/src/FindSCModules.cpp index 6ad988789a46ddf5adc45eca37c2187f970b7a4d..edcfbc82d3e2877a2209d5cf05f6e5e0bd781b22 100644 --- a/src/FindSCModules.cpp +++ b/src/FindSCModules.cpp @@ -19,7 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) { } string modName = mod.getModuleName(); _moduleMap.insert(modulePairType(modName, cxxDecl)); - template_parameters_ = mod.getTemplateParameters(); + return true; } diff --git a/src/FindSCModules.h b/src/FindSCModules.h index cbfbb467e298997492e5a0499e4c5fbca14f3d22..155bd94b9fe98b5df3a5a309a53ad2c5750bb28e 100644 --- a/src/FindSCModules.h +++ b/src/FindSCModules.h @@ -25,7 +25,6 @@ public: private: llvm::raw_ostream &_os; moduleMapType _moduleMap; - vector template_parameters_; }; } // namespace scpar #endif diff --git a/src/ModuleDecl.cpp b/src/ModuleDecl.cpp index 33c8ec85433359a5b9af34944e309a04591fa6c3..89e8f5cf58608cd3081c4528cee988946d694e89 100644 --- a/src/ModuleDecl.cpp +++ b/src/ModuleDecl.cpp @@ -37,6 +37,13 @@ ModuleDecl::~ModuleDecl() { _ioports.clear(); } +void ModuleDecl::setTemplateParameters(const vector & parm_list) { + template_parameters_ = parm_list; +} + +vector ModuleDecl::getTemplateParameters() const { + return template_parameters_; } + void ModuleDecl::setModuleName(const string &name) { module_name_ = name; } void ModuleDecl::addInstances(const vector & instanceList) { @@ -330,6 +337,11 @@ json ModuleDecl::dump_json() { json module_j; module_j["module_name"] = module_name_; + // Template parameters. + std::cout << "\nTEMPPARM: " << template_parameters_.size() << std::endl; + for (const auto & parm: template_parameters_) { + module_j["template_parameters"].push_back( parm ); + } std::cout << module_j.dump(4); diff --git a/src/ModuleDecl.h b/src/ModuleDecl.h index 5013c76f33cfab862664dac53525836a0244623e..9ed25cd0ccb7fb847339d3403a73a2b342d4f18b 100644 --- a/src/ModuleDecl.h +++ b/src/ModuleDecl.h @@ -64,6 +64,8 @@ public: void addInstances(const vector & ); void addSignalBinding(map); void setModuleName(const string &); + void setTemplateParameters(const vector &); + vector getTemplateParameters() const; void addConstructor(Stmt *); string getName(); CXXRecordDecl *getModuleClassDecl(); diff --git a/src/SystemCClang.cpp b/src/SystemCClang.cpp index 576d0aa5a2f83cf1a20642f4f015a50f543cd2d9..5fcc900f4c414b04c5deb5680a7f0795e663ecfe 100644 --- a/src/SystemCClang.cpp +++ b/src/SystemCClang.cpp @@ -24,12 +24,13 @@ bool SystemCConsumer::fire() { // Find the sc_modules FindSCModules scmod{tu, _os}; - FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()}; for (FindSCModules::moduleMapType::iterator mit = scmodules.begin(), mitend = scmodules.end(); mit != mitend; ++mit) { ModuleDecl *md = new ModuleDecl{mit->first, mit->second}; + //md->setTemplateParameters( scmod.getTemplateParameters() ); +// _os << "SIZE: " << scmod.getTemplateParameters().size() << "\n"; _systemcModel->addModuleDecl(md); } @@ -70,6 +71,15 @@ bool SystemCConsumer::fire() { for (unsigned int num{0}; num < numInstances; ++num) { ModuleDecl *md = new ModuleDecl{}; + + // Find the template arguments for the class. + FindTemplateParameters tparms{ mainmd->getModuleClassDecl(), _os}; + + md->setTemplateParameters( tparms.getTemplateParameters() ); + _os << "@@# " << mainmd->getTemplateParameters().size() << "\n"; + md->dump_json(); + + vector _entryFunctionContainerVector; FindConstructor constructor{mainmd->getModuleClassDecl(), _os}; md->addConstructor(constructor.returnConstructorStmt()); diff --git a/src/SystemCClang.h b/src/SystemCClang.h index 73f807f0520c32f806502a104117165e86a2a508..e6dcab75b5e4068d4483d7c0e43997e944ba2545 100644 --- a/src/SystemCClang.h +++ b/src/SystemCClang.h @@ -50,6 +50,8 @@ using namespace clang::tooling; #include "SCuitable/GlobalSuspensionAutomata.h" #include "SuspensionAutomata.h" #include "Utility.h" +#include "FindTemplateParameters.h" \ + using namespace clang;