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
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
)
......@@ -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<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;
}
// 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; }
......
......@@ -20,14 +20,14 @@ public:
void dump();
string getModuleName() const;
bool isSystemCModule() const;
vector<string> getTemplateParameters() const;
// vector<string> 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
......@@ -19,7 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) {
}
string modName = mod.getModuleName();
_moduleMap.insert(modulePairType(modName, cxxDecl));
template_parameters_ = mod.getTemplateParameters();
return true;
}
......
......@@ -25,7 +25,6 @@ public:
private:
llvm::raw_ostream &_os;
moduleMapType _moduleMap;
vector<string> template_parameters_;
};
} // namespace scpar
#endif
......@@ -37,6 +37,13 @@ ModuleDecl::~ModuleDecl() {
_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::addInstances(const vector<string> & 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);
......
......@@ -64,6 +64,8 @@ public:
void addInstances(const vector<string> & );
void addSignalBinding(map<string, string>);
void setModuleName(const string &);
void setTemplateParameters(const vector<string> &);
vector<string> getTemplateParameters() const;
void addConstructor(Stmt *);
string getName();
CXXRecordDecl *getModuleClassDecl();
......
......@@ -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<EntryFunctionContainer *> _entryFunctionContainerVector;
FindConstructor constructor{mainmd->getModuleClassDecl(), _os};
md->addConstructor(constructor.returnConstructorStmt());
......
......@@ -50,6 +50,8 @@ using namespace clang::tooling;
#include "SCuitable/GlobalSuspensionAutomata.h"
#include "SuspensionAutomata.h"
#include "Utility.h"
#include "FindTemplateParameters.h" \
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