Commit 505643f7 authored by rmrf's avatar rmrf

Stage 2: The json dump has the feature to print the template parameters

now.
parent bcd25d3b
...@@ -18,6 +18,7 @@ add_library (libsystemc-clang ...@@ -18,6 +18,7 @@ add_library (libsystemc-clang
SystemCClang.cpp SystemCClang.cpp
FindNetlist.cpp FindNetlist.cpp
FindArgument.cpp FindArgument.cpp
FindTemplateParameters.cpp
Automata.cpp Automata.cpp
SuspensionAutomata.cpp SuspensionAutomata.cpp
SCuitable/GlobalSuspensionAutomata.cpp SCuitable/GlobalSuspensionAutomata.cpp
...@@ -36,7 +37,7 @@ add_library (libsystemc-clang ...@@ -36,7 +37,7 @@ add_library (libsystemc-clang
InterfaceDecl.cpp InterfaceDecl.cpp
Model.cpp Model.cpp
WaitCalls.cpp WaitCalls.cpp
NotifyCalls.cpp NotifyCalls.cpp
EventContainer.cpp EventContainer.cpp
) )
...@@ -9,13 +9,12 @@ using namespace scpar; ...@@ -9,13 +9,12 @@ 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}, template_parameters_{nullptr} { : declaration_{declaration}, os_{os}, is_systemc_module_{false} {
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;
...@@ -36,15 +35,16 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { ...@@ -36,15 +35,16 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
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. // // Check if the class is a templated module class.
auto template_args{ declaration->getDescribedClassTemplate() }; // auto template_args{ declaration->getDescribedClassTemplate() };
if (template_args != nullptr) { // if (template_args != nullptr) {
os_ << module_name_ << ": TEMPLATE ARGS YES \n"; // os_ << module_name_ << ": TEMPLATE ARGS YES \n";
template_parameters_ = template_args->getTemplateParameters(); // template_parameters_ = template_args->getTemplateParameters();
//parms->getParam(0)->dump(); // //parms->getParam(0)->dump();
// parms->getParam(1)->dump(); // // parms->getParam(1)->dump();
// }
}
} }
} }
} }
...@@ -56,19 +56,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) { ...@@ -56,19 +56,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
return false; return false;
} }
vector<string> FindModule::getTemplateParameters() const { // vector<string> FindModule::getTemplateParameters() const {
vector<string> parm_list; // vector<string> parm_list;
if ( (template_parameters_ == nullptr) // if ( (template_parameters_ == nullptr)
|| (template_parameters_->size() <= 0) ) { // || (template_parameters_->size() <= 0) ) {
return parm_list; // return parm_list;
} // }
for (auto parm : template_parameters_->asArray() ) { // for (auto parm : template_parameters_->asArray() ) {
parm_list.push_back( parm->getName() ); // parm_list.push_back( parm->getName() );
os_ << "Parm: " << parm->getName() << "\n"; // os_ << "Parm: " << parm->getName() << "\n";
} // }
return parm_list; // return parm_list;
} // }
FindModule::~FindModule() { declaration_ = nullptr; } FindModule::~FindModule() { declaration_ = nullptr; }
......
...@@ -20,14 +20,14 @@ public: ...@@ -20,14 +20,14 @@ public:
void dump(); void dump();
string getModuleName() const; string getModuleName() const;
bool isSystemCModule() const; bool isSystemCModule() const;
vector<string> getTemplateParameters() 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_; // TemplateParameterList *template_parameters_;
}; };
} // namespace scpar } // namespace scpar
#endif #endif
...@@ -19,7 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) { ...@@ -19,7 +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,7 +25,6 @@ public: ...@@ -25,7 +25,6 @@ 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
...@@ -37,6 +37,13 @@ ModuleDecl::~ModuleDecl() { ...@@ -37,6 +37,13 @@ ModuleDecl::~ModuleDecl() {
_ioports.clear(); _ioports.clear();
} }
void ModuleDecl::setTemplateParameters(const vector<string> & parm_list) {
template_parameters_ = parm_list;
}
vector<string> ModuleDecl::getTemplateParameters() const {
return template_parameters_; }
void ModuleDecl::setModuleName(const string &name) { module_name_ = name; } void ModuleDecl::setModuleName(const string &name) { module_name_ = name; }
void ModuleDecl::addInstances(const vector<string> & instanceList) { void ModuleDecl::addInstances(const vector<string> & instanceList) {
...@@ -330,6 +337,11 @@ json ModuleDecl::dump_json() { ...@@ -330,6 +337,11 @@ json ModuleDecl::dump_json() {
json module_j; json module_j;
module_j["module_name"] = module_name_; 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); std::cout << module_j.dump(4);
......
...@@ -64,6 +64,8 @@ public: ...@@ -64,6 +64,8 @@ public:
void addInstances(const vector<string> & ); void addInstances(const vector<string> & );
void addSignalBinding(map<string, string>); void addSignalBinding(map<string, string>);
void setModuleName(const string &); void setModuleName(const string &);
void setTemplateParameters(const vector<string> &);
vector<string> getTemplateParameters() const;
void addConstructor(Stmt *); void addConstructor(Stmt *);
string getName(); string getName();
CXXRecordDecl *getModuleClassDecl(); CXXRecordDecl *getModuleClassDecl();
......
...@@ -24,12 +24,13 @@ bool SystemCConsumer::fire() { ...@@ -24,12 +24,13 @@ bool SystemCConsumer::fire() {
// Find the sc_modules // Find the sc_modules
FindSCModules scmod{tu, _os}; FindSCModules scmod{tu, _os};
FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()}; FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()};
for (FindSCModules::moduleMapType::iterator mit = scmodules.begin(), for (FindSCModules::moduleMapType::iterator mit = scmodules.begin(),
mitend = scmodules.end(); mit != mitend; ++mit) { mitend = scmodules.end(); mit != mitend; ++mit) {
ModuleDecl *md = new ModuleDecl{mit->first, mit->second}; ModuleDecl *md = new ModuleDecl{mit->first, mit->second};
//md->setTemplateParameters( scmod.getTemplateParameters() );
// _os << "SIZE: " << scmod.getTemplateParameters().size() << "\n";
_systemcModel->addModuleDecl(md); _systemcModel->addModuleDecl(md);
} }
...@@ -70,6 +71,15 @@ bool SystemCConsumer::fire() { ...@@ -70,6 +71,15 @@ bool SystemCConsumer::fire() {
for (unsigned int num{0}; num < numInstances; ++num) { for (unsigned int num{0}; num < numInstances; ++num) {
ModuleDecl *md = new ModuleDecl{}; 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<EntryFunctionContainer *> _entryFunctionContainerVector; vector<EntryFunctionContainer *> _entryFunctionContainerVector;
FindConstructor constructor{mainmd->getModuleClassDecl(), _os}; FindConstructor constructor{mainmd->getModuleClassDecl(), _os};
md->addConstructor(constructor.returnConstructorStmt()); md->addConstructor(constructor.returnConstructorStmt());
......
...@@ -50,6 +50,8 @@ using namespace clang::tooling; ...@@ -50,6 +50,8 @@ using namespace clang::tooling;
#include "SCuitable/GlobalSuspensionAutomata.h" #include "SCuitable/GlobalSuspensionAutomata.h"
#include "SuspensionAutomata.h" #include "SuspensionAutomata.h"
#include "Utility.h" #include "Utility.h"
#include "FindTemplateParameters.h" \
using namespace clang; using namespace clang;
......
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