Commit 731af1ee authored by rmrf's avatar rmrf

Working on PortDecl

parent 7e25e8e5
add_library (libsystemc-clang add_library (libsystemc-clang
ModuleDecl.cpp ModuleDecl.cpp
FindModule.cpp FindModule.cpp
SCModules.cpp FindSCModules.cpp
FindSCMain.cpp FindSCMain.cpp
FindPorts.cpp FindPorts.cpp
FindTLMInterfaces.cpp FindTLMInterfaces.cpp
......
#include "SCModules.h" #include "FindSCModules.h"
#include "FindModule.h" #include "FindModule.h"
#include "clang/AST/ASTContext.h" #include "clang/AST/ASTContext.h"
using namespace scpar; using namespace scpar;
SCModules::SCModules(TranslationUnitDecl *tuDecl, llvm::raw_ostream &os) FindSCModules::FindSCModules(TranslationUnitDecl *tuDecl, llvm::raw_ostream &os)
: _os(os) { : _os(os) {
assert(!(tuDecl == nullptr)); assert(!(tuDecl == nullptr));
TraverseDecl(tuDecl); TraverseDecl(tuDecl);
} }
SCModules::~SCModules() {} FindSCModules::~FindSCModules() {}
bool SCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) { bool FindSCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) {
FindModule mod(cxxDecl, _os); FindModule mod(cxxDecl, _os);
if (!mod.isSystemCModule()) { if (!mod.isSystemCModule()) {
...@@ -22,11 +22,11 @@ bool SCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) { ...@@ -22,11 +22,11 @@ bool SCModules::VisitCXXRecordDecl(CXXRecordDecl *cxxDecl) {
return true; return true;
} }
SCModules::moduleMapType SCModules::getSystemCModulesMap() { FindSCModules::moduleMapType FindSCModules::getSystemCModulesMap() {
return _moduleMap; return _moduleMap;
} }
void SCModules::dump() { void FindSCModules::dump() {
_os << "\n================= SCModules ================"; _os << "\n================= SCModules ================";
_os << "\n Print SystemC Module Map"; _os << "\n Print SystemC Module Map";
for (moduleMapType::iterator mit = _moduleMap.begin(); for (moduleMapType::iterator mit = _moduleMap.begin();
......
#ifndef _SC_MODULES_H_ #ifndef _FIND_SC_MODULES_H_
#define _SC_MODULES_H_ #define _FIND_SC_MODULES_H_
#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/RecursiveASTVisitor.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
...@@ -11,13 +11,13 @@ namespace scpar { ...@@ -11,13 +11,13 @@ namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
class SCModules : public RecursiveASTVisitor<SCModules> { class FindSCModules : public RecursiveASTVisitor<FindSCModules> {
public: public:
typedef map<string, CXXRecordDecl *> moduleMapType; typedef map<string, CXXRecordDecl *> moduleMapType;
typedef pair<string, CXXRecordDecl *> modulePairType; typedef pair<string, CXXRecordDecl *> modulePairType;
SCModules(TranslationUnitDecl *, llvm::raw_ostream &); FindSCModules(TranslationUnitDecl *, llvm::raw_ostream &);
virtual ~SCModules(); virtual ~FindSCModules();
virtual bool VisitCXXRecordDecl(CXXRecordDecl *); virtual bool VisitCXXRecordDecl(CXXRecordDecl *);
moduleMapType getSystemCModulesMap(); moduleMapType getSystemCModulesMap();
void dump(); void dump();
......
#include "Model.h" #include "Model.h"
#include "SCModules.h" //#include "FindSCModules.h"
#include <string> #include <string>
using namespace scpar; using namespace scpar;
...@@ -104,10 +104,10 @@ void Model::updateModuleDecl() { ...@@ -104,10 +104,10 @@ void Model::updateModuleDecl() {
} }
} }
void Model::addSCModules(SCModules *m) { void Model::addSCModules(FindSCModules *m) {
SCModules::moduleMapType mods = m->getSystemCModulesMap(); FindSCModules::moduleMapType mods = m->getSystemCModulesMap();
for (SCModules::moduleMapType::iterator mit = mods.begin(); mit != mods.end(); for (FindSCModules::moduleMapType::iterator mit = mods.begin(); mit != mods.end();
mit++) { mit++) {
addModuleDecl(new ModuleDecl(mit->first, mit->second)); addModuleDecl(new ModuleDecl(mit->first, mit->second));
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "FindNetlist.h" #include "FindNetlist.h"
#include "FindSimTime.h" #include "FindSimTime.h"
#include "ModuleDecl.h" #include "ModuleDecl.h"
#include "SCModules.h" #include "FindSCModules.h"
#include "SCuitable/FindGPUMacro.h" #include "SCuitable/FindGPUMacro.h"
#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclCXX.h"
#include <map> #include <map>
...@@ -37,7 +37,7 @@ public: ...@@ -37,7 +37,7 @@ public:
Model(); Model();
~Model(); ~Model();
void addSCModules(SCModules *); void addSCModules(FindSCModules *);
void addModuleDecl(ModuleDecl *); void addModuleDecl(ModuleDecl *);
void addModuleDeclInstances(ModuleDecl *, vector<ModuleDecl *>); void addModuleDeclInstances(ModuleDecl *, vector<ModuleDecl *>);
void addSimulationTime(FindSimTime::simulationTimeMapType); void addSimulationTime(FindSimTime::simulationTimeMapType);
......
...@@ -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() {
...@@ -84,7 +84,7 @@ void ModuleDecl::addOutputPorts(FindPorts::PortType p) { ...@@ -84,7 +84,7 @@ void ModuleDecl::addOutputPorts(FindPorts::PortType p) {
void ModuleDecl::addInputOutputPorts(FindPorts::PortType p) { void ModuleDecl::addInputOutputPorts(FindPorts::PortType p) {
for (auto mit : p) { for (auto mit : p) {
_ioports.insert( _ioports.insert(
portPairType(mit.first, new PortDecl(mit.first, mit.second))); portPairType(mit.first, new PortDecl(mit.first, mit.second)));
} }
} }
...@@ -113,7 +113,7 @@ void ModuleDecl::addInputOutputInterfaces(FindTLMInterfaces::interfaceType p) { ...@@ -113,7 +113,7 @@ void ModuleDecl::addInputOutputInterfaces(FindTLMInterfaces::interfaceType p) {
// p.end(); mit != mite; mit++) { // p.end(); mit != mite; mit++) {
for (auto mit : p) { for (auto mit : p) {
_iointerfaces.insert( _iointerfaces.insert(
interfacePairType(mit.first, new InterfaceDecl(mit.first, mit.second))); interfacePairType(mit.first, new InterfaceDecl(mit.first, mit.second)));
} }
} }
...@@ -150,9 +150,9 @@ void ModuleDecl::addProcess(FindEntryFunctions::entryFunctionVectorType *efv) { ...@@ -150,9 +150,9 @@ void ModuleDecl::addProcess(FindEntryFunctions::entryFunctionVectorType *efv) {
break; break;
} }
} }
_processes.insert( process_map_.insert(
processPairType(entryName, new ProcessDecl(entryType, entryName, processPairType(entryName, new ProcessDecl(entryType, entryName,
ef->_entryMethodDecl, ef))); ef->_entryMethodDecl, ef)));
} }
} }
...@@ -164,7 +164,7 @@ vector<EntryFunctionContainer *> ModuleDecl::getEntryFunctionContainer() { ...@@ -164,7 +164,7 @@ vector<EntryFunctionContainer *> ModuleDecl::getEntryFunctionContainer() {
int ModuleDecl::getNumInstances() { return _instanceList.size(); } int ModuleDecl::getNumInstances() { return _instanceList.size(); }
ModuleDecl::processMapType ModuleDecl::getProcessMap() { return _processes; } ModuleDecl::processMapType ModuleDecl::getProcessMap() { return process_map_; }
ModuleDecl::portMapType ModuleDecl::getOPorts() { return _oports; } ModuleDecl::portMapType ModuleDecl::getOPorts() { return _oports; }
...@@ -216,10 +216,10 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) { ...@@ -216,10 +216,10 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) {
} }
void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) { void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) {
if (_processes.size() == 0) { if ( process_map_.empty() ) {
os << "none \n"; os << "none \n";
} else { } else {
for (auto pit : _processes) { for (auto pit : process_map_) {
ProcessDecl *pd = pit.second; ProcessDecl *pd = pit.second;
pd->dump( os ); pd->dump( os );
os << "\n"; os << "\n";
......
...@@ -20,17 +20,21 @@ using namespace std; ...@@ -20,17 +20,21 @@ using namespace std;
class ModuleDecl { class ModuleDecl {
public: public:
typedef pair<string, Signal *> signalPairType; typedef pair<string, Signal* > signalPairType;
typedef map<string, Signal *> signalMapType; typedef map<string, Signal* > signalMapType;
typedef pair<string, PortDecl *> portPairType; // Maps the name of the port with a pointer to a structure that holds
typedef map<string, PortDecl *> portMapType; // information about the port.
typedef pair<string, PortDecl* > portPairType;
typedef map<string, PortDecl* > portMapType;
typedef pair<string, InterfaceDecl *> interfacePairType; typedef pair<string, InterfaceDecl* > interfacePairType;
typedef map<string, InterfaceDecl *> interfaceMapType; typedef map<string, InterfaceDecl* > interfaceMapType;
typedef pair<string, ProcessDecl *> processPairType; // Maps the name of the process with a pointer to a structure that holds
typedef map<string, ProcessDecl *> processMapType; // information about the process.
typedef pair<string, ProcessDecl* > processPairType;
typedef map<string, ProcessDecl* > processMapType;
typedef pair<string, string> moduleProcessPairType; typedef pair<string, string> moduleProcessPairType;
...@@ -86,7 +90,7 @@ private: ...@@ -86,7 +90,7 @@ private:
CXXRecordDecl *class_decl_; CXXRecordDecl *class_decl_;
Stmt *constructor_stmt_; Stmt *constructor_stmt_;
processMapType _processes; processMapType process_map_;
portMapType _iports; portMapType _iports;
portMapType _oports; portMapType _oports;
portMapType _ioports; portMapType _ioports;
......
//#include <string>
#include "PortDecl.h" #include "PortDecl.h"
#include "FindTemplateTypes.h" #include "FindTemplateTypes.h"
using namespace scpar; using namespace scpar;
using namespace std; using namespace std;
PortDecl::~PortDecl() { PortDecl::~PortDecl() {
if (template_type_ != nullptr) { if ( template_type_ != nullptr ) {
delete template_type_; delete template_type_;
template_type_ = nullptr;
} }
} }
PortDecl::PortDecl() : port_name_{"NONE"}, template_type_{nullptr} {} PortDecl::PortDecl() : port_name_{"NONE"}, template_type_{nullptr} {}
PortDecl::PortDecl(const string &name, FindTemplateTypes *tt) PortDecl::PortDecl(const string &name, FindTemplateTypes *tt)
: port_name_{name}, template_type_{tt} {} : port_name_{name}, template_type_{tt} {}
PortDecl::PortDecl(const PortDecl &from) { PortDecl::PortDecl(const PortDecl &from) {
port_name_ = from.port_name_; port_name_ = from.port_name_;
...@@ -32,4 +33,15 @@ void PortDecl::dump(llvm::raw_ostream &os, int tabn) { ...@@ -32,4 +33,15 @@ void PortDecl::dump(llvm::raw_ostream &os, int tabn) {
// << template_type_; // << template_type_;
os << "Port name: " << port_name_ << " "; os << "Port name: " << port_name_ << " ";
template_type_->printTemplateArguments(os); template_type_->printTemplateArguments(os);
dump_json();
}
json PortDecl::dump_json() {
json port_j;
port_j["module_name"] = getName();
//port_j["template_type"]
return port_j;
} }
#ifndef _PORT_DECL_H_ #ifndef _PORT_DECL_H_
#define _PORT_DECL_H_ #define _PORT_DECL_H_
#include "systemc-clang.h"
#include "json.hpp"
#include <map> #include <map>
#include <string> #include <string>
...@@ -10,6 +13,7 @@ ...@@ -10,6 +13,7 @@
namespace scpar { namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
using json = nlohmann::json;
class PortDecl { class PortDecl {
public: public:
...@@ -29,6 +33,8 @@ public: ...@@ -29,6 +33,8 @@ public:
// Print // Print
void dump(raw_ostream &, int tabn = 0); void dump(raw_ostream &, int tabn = 0);
json dump_json();
private: private:
string port_name_; string port_name_;
FindTemplateTypes *template_type_; FindTemplateTypes *template_type_;
......
...@@ -16,16 +16,16 @@ bool SystemCConsumer::fire() { ...@@ -16,16 +16,16 @@ bool SystemCConsumer::fire() {
_systemcModel = new Model{}; _systemcModel = new Model{};
// Find the sc_modules // Find the sc_modules
SCModules scmod{tu, _os}; FindSCModules scmod{tu, _os};
// ANI : Do we need FindGlobalEvents? // ANI : Do we need FindGlobalEvents?
FindGlobalEvents fglobals{tu, _os}; FindGlobalEvents fglobals{tu, _os};
FindGlobalEvents::globalEventMapType eventMap{fglobals.getEventMap()}; FindGlobalEvents::globalEventMapType eventMap{fglobals.getEventMap()};
_systemcModel->addGlobalEvents(eventMap); _systemcModel->addGlobalEvents(eventMap);
SCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()}; FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()};
for (SCModules::moduleMapType::iterator mit = scmodules.begin(), for (FindSCModules::moduleMapType::iterator mit = scmodules.begin(),
mitend = scmodules.end(); mitend = scmodules.end();
mit != mitend; ++mit) { mit != mitend; ++mit) {
ModuleDecl *md = new ModuleDecl{mit->first, mit->second}; ModuleDecl *md = new ModuleDecl{mit->first, mit->second};
......
...@@ -45,7 +45,7 @@ using namespace clang::tooling; ...@@ -45,7 +45,7 @@ using namespace clang::tooling;
#include "FindTLMInterfaces.h" #include "FindTLMInterfaces.h"
#include "FindWait.h" #include "FindWait.h"
#include "Model.h" #include "Model.h"
#include "SCModules.h" #include "FindSCModules.h"
#include "SCuitable/FindGPUMacro.h" #include "SCuitable/FindGPUMacro.h"
#include "SCuitable/GlobalSuspensionAutomata.h" #include "SCuitable/GlobalSuspensionAutomata.h"
#include "SuspensionAutomata.h" #include "SuspensionAutomata.h"
......
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