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;
string FindModule::getModuleName() const { return module_name_; }
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) {
TraverseDecl(declaration);
}
}
bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
if (declaration_->getNumBases() <= 0) {
return true;
......@@ -31,8 +32,19 @@ bool FindModule::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
is_systemc_module_ = true;
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();
}
}
}
}
......@@ -44,6 +56,20 @@ 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;
}
FindModule::~FindModule() { declaration_ = nullptr; }
bool FindModule::isSystemCModule() const { return is_systemc_module_; }
......
......@@ -14,17 +14,20 @@ class FindModule : public RecursiveASTVisitor<FindModule> {
public:
FindModule(CXXRecordDecl *, llvm::raw_ostream &);
virtual bool VisitCXXRecordDecl(CXXRecordDecl *decl);
virtual ~FindModule();
void dump();
string getModuleName() const;
bool isSystemCModule() const;
vector<string> getTemplateParameters() const;
private:
CXXRecordDecl *declaration_;
llvm::raw_ostream &os_;
bool is_systemc_module_;
string module_name_;
TemplateParameterList *template_parameters_;
};
} // namespace scpar
#endif
......@@ -19,6 +19,7 @@ bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) {
}
string modName = mod.getModuleName();
_moduleMap.insert(modulePairType(modName, cxxDecl));
template_parameters_ = mod.getTemplateParameters();
return true;
}
......
......@@ -25,6 +25,7 @@ public:
private:
llvm::raw_ostream &_os;
moduleMapType _moduleMap;
vector<string> template_parameters_;
};
} // namespace scpar
#endif
......@@ -24,6 +24,14 @@ bool FindWait::VisitCallExpr(CallExpr *e) {
LangOpts.CPlusPlus = true;
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")) {
wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, e));
}
......
......@@ -10,7 +10,7 @@ ModuleDecl::ModuleDecl() : module_name_{"NONE"},
constructor_stmt_{nullptr} {}
ModuleDecl::ModuleDecl(const string &name, CXXRecordDecl *decl)
: module_name_{name}, class_decl_{decl} {}
: module_name_{name}, class_decl_{decl} {}
ModuleDecl::~ModuleDecl() {
......@@ -218,7 +218,7 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) {
}
void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) {
json process_j;
process_j["number_of_processes"] = process_map_.size();
for (auto pit : process_map_) {
......
......@@ -104,10 +104,13 @@ private:
interfaceMapType _ointerfaces;
interfaceMapType _iointerfaces;
signalMapType _signals;
vector<string> _instanceList;
portSignalMapType _portSignalMap;
vector<EntryFunctionContainer *> _vef;
// Class template parameters.
vector<string> template_parameters_;
};
} // namespace scpar
#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