Commit 8b834694 authored by Twiga's avatar Twiga
Browse files

Signal and SignalContainer needs updates

parent 0202174c
...@@ -5,17 +5,18 @@ using namespace scpar; ...@@ -5,17 +5,18 @@ using namespace scpar;
FindSignals::~FindSignals() { FindSignals::~FindSignals() {
// _os << "[[ Destructor FindSignals ]]\n"; // _os << "[[ Destructor FindSignals ]]\n";
for (FindSignals::signalMapType::iterator sit = _signals->begin(); //for (FindSignals::signalMapType::iterator sit = signalcontainer_map_->begin();
sit != _signals->end(); sit++) { //sit != signalcontainer_map_->end(); sit++) {
delete sit->second; for ( auto const & sit : signalcontainer_map_ ) {
delete sit.second;
} }
_signals->clear();
delete _signals; signalcontainer_map_.clear();
//delete signalcontainer_map_;
} }
FindSignals::FindSignals(CXXRecordDecl *d, llvm::raw_ostream &os) : _os(os) { FindSignals::FindSignals(CXXRecordDecl *d, llvm::raw_ostream &os) : _os(os) {
_signals = new FindSignals::signalMapType(); //signalcontainer_map_ = new FindSignals::signalMapType();
state = 0;
TraverseDecl(d); TraverseDecl(d);
} }
...@@ -44,20 +45,21 @@ bool FindSignals::VisitFieldDecl(FieldDecl *fd) { ...@@ -44,20 +45,21 @@ bool FindSignals::VisitFieldDecl(FieldDecl *fd) {
} }
SignalContainer *sc = new SignalContainer(fd->getNameAsString(), te, fd); SignalContainer *sc = new SignalContainer(fd->getNameAsString(), te, fd);
_signals->insert(FindSignals::signalPairType(fd->getNameAsString(), sc)); signalcontainer_map_.insert(FindSignals::signalPairType(fd->getNameAsString(), sc));
} }
return true; return true;
} }
FindSignals::signalMapType *FindSignals::getSignals() { return _signals; } FindSignals::signalMapType FindSignals::getSignals() const { return signalcontainer_map_; }
void FindSignals::dump() { void FindSignals::dump() {
_os << "\n================= Find Signals ================\n"; _os << "\n================= Find Signals ================\n";
for (FindSignals::signalMapType::iterator sit = _signals->begin(); //for (FindSignals::signalMapType::iterator sit = signalcontainer_map_->begin();
sit != _signals->end(); sit++) { //sit != signalcontainer_map_->end(); sit++) {
_os << sit->second; for (auto const & sit : signalcontainer_map_ ) {
sit->second->dump(_os); _os << sit.second;
sit.second->dump(_os);
} }
_os << "\n================= END Find Ports ================\n\n"; _os << "\n================= END Find Ports ================\n\n";
} }
...@@ -11,45 +11,46 @@ namespace scpar { ...@@ -11,45 +11,46 @@ namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
struct SignalContainer { struct SignalContainer {
SignalContainer(string n, FindTemplateTypes *tt, FieldDecl *fd) SignalContainer(string n, FindTemplateTypes *tt, FieldDecl *fd)
: _name{n}, _template{tt}, _astNode{fd} {} : signal_name_{n}, template_types_{tt}, ast_node_{fd} {}
~SignalContainer() { ~SignalContainer() {
// Only thing I create is FindTemplateType. Rest should be deleted by clang. // Only thing I create is FindTemplateType. Rest should be deleted by clang.
// llvm::errs () << "[[ Destructor SignalContainer ]]\n"; // llvm::errs () << "[[ Destructor SignalContainer ]]\n";
delete _template; delete template_types_;
} }
SignalContainer(const SignalContainer &from) { SignalContainer(const SignalContainer &from) {
_name = from._name; signal_name_ = from.signal_name_;
_template = new FindTemplateTypes(*(from._template)); template_types_ = new FindTemplateTypes(*(from.template_types_));
_astNode = from._astNode; ast_node_ = from.ast_node_;
} }
void dump(llvm::raw_ostream &os) { void dump(llvm::raw_ostream &os) {
os << "[SignalContainer " << _name << " FindTemplateType " << _template os << "[SignalContainer " << signal_name_ << " FindTemplateType " << template_types_
<< " FieldDecl " << _astNode << "\n"; << " FieldDecl " << ast_node_ << "\n";
_template->printTemplateArguments(os); template_types_->printTemplateArguments(os);
os << "]\n"; os << "]\n";
} }
FindTemplateTypes *getTemplateTypes() { FindTemplateTypes *getTemplateTypes() {
assert(!(_template == nullptr)); assert(!(template_types_ == nullptr));
return _template; return template_types_;
} }
FieldDecl *getASTNode() { FieldDecl *getASTNode() {
assert(!(_astNode == nullptr)); assert(!(ast_node_ == nullptr));
return _astNode; return ast_node_;
} }
string getName() { return _name; } string getName() { return signal_name_; }
// FIXME: Make these protected.
string _name; private:
FindTemplateTypes *_template; string signal_name_;
FieldDecl *_astNode; FindTemplateTypes *template_types_;
FieldDecl *ast_node_;
}; };
class FindSignals : public RecursiveASTVisitor<FindSignals> { class FindSignals : public RecursiveASTVisitor<FindSignals> {
...@@ -63,13 +64,13 @@ public: ...@@ -63,13 +64,13 @@ public:
virtual bool VisitFieldDecl(FieldDecl *); virtual bool VisitFieldDecl(FieldDecl *);
signalMapType *getSignals(); signalMapType getSignals() const ;
void dump(); void dump();
private: private:
llvm::raw_ostream &_os; llvm::raw_ostream &_os;
int state; //int state_;
signalMapType *_signals; signalMapType signalcontainer_map_;
}; };
} // namespace scpar } // namespace scpar
......
...@@ -42,7 +42,6 @@ FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes *rhs) { ...@@ -42,7 +42,6 @@ FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes *rhs) {
// Destructor // Destructor
FindTemplateTypes::~FindTemplateTypes() { FindTemplateTypes::~FindTemplateTypes() {
// TODO: We should convert these into objects.
template_types_.clear(); template_types_.clear();
} }
......
...@@ -16,7 +16,7 @@ namespace scpar { ...@@ -16,7 +16,7 @@ namespace scpar {
using namespace std; using namespace std;
// This class holds the name of the type, and a pointer to the // This class holds the name of the type, and a pointer to the
// type object. // type object.
class TemplateType { class TemplateType {
public: public:
TemplateType( string, const Type* ); TemplateType( string, const Type* );
......
...@@ -47,8 +47,8 @@ void ModuleDecl::addSignalBinding(map<string, string> portSignalMap) { ...@@ -47,8 +47,8 @@ void ModuleDecl::addSignalBinding(map<string, string> portSignalMap) {
_portSignalMap.insert(portSignalMap.begin(), portSignalMap.end()); _portSignalMap.insert(portSignalMap.begin(), portSignalMap.end());
} }
void ModuleDecl::addSignals(FindSignals::signalMapType *signal_map) { void ModuleDecl::addSignals(const FindSignals::signalMapType & signal_map) {
for (auto sit : *signal_map) { for (auto sit : signal_map) {
string name = sit.first; string name = sit.first;
// It is important to create new objects. // It is important to create new objects.
...@@ -57,7 +57,7 @@ void ModuleDecl::addSignals(FindSignals::signalMapType *signal_map) { ...@@ -57,7 +57,7 @@ void ModuleDecl::addSignals(FindSignals::signalMapType *signal_map) {
SignalContainer *sc = new SignalContainer(*sit.second); SignalContainer *sc = new SignalContainer(*sit.second);
Signal *sig = new Signal(name, sc); Signal *sig = new Signal(name, sc);
_signals.insert(ModuleDecl::signalPairType(name, sig)); _signals.insert( ModuleDecl::signalPairType(name, sig) );
} }
} }
...@@ -331,5 +331,20 @@ void ModuleDecl::dump(raw_ostream &os) { ...@@ -331,5 +331,20 @@ void ModuleDecl::dump(raw_ostream &os) {
dumpInstances(os, 4); dumpInstances(os, 4);
os << "# Signal binding:\n"; os << "# Signal binding:\n";
dumpSignalBinding(os, 4); dumpSignalBinding(os, 4);
dump_json();
os << "\n=======================================================\n"; os << "\n=======================================================\n";
}
json ModuleDecl::dump_json() {
json module_j;
module_j["module_name"] = module_name_;
std::cout << module_j.dump(4);
return module_j;
} }
#ifndef _MODULE_DECL_H_ #ifndef _MODULE_DECL_H_
#define _MODULE_DECL_H_ #define _MODULE_DECL_H_
#include "systemc-clang.h"
#include "json.hpp"
#include "FindConstructor.h" #include "FindConstructor.h"
#include "FindEntryFunctions.h" #include "FindEntryFunctions.h"
...@@ -15,8 +17,9 @@ ...@@ -15,8 +17,9 @@
#include <string> #include <string>
namespace scpar { namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
using json = nlohmann::json;
class ModuleDecl { class ModuleDecl {
public: public:
...@@ -50,7 +53,7 @@ public: ...@@ -50,7 +53,7 @@ public:
~ModuleDecl(); ~ModuleDecl();
void addSignals(FindSignals::signalMapType *); void addSignals(const FindSignals::signalMapType & );
void addInputPorts(FindPorts::PortType); void addInputPorts(FindPorts::PortType);
void addOutputPorts(FindPorts::PortType); void addOutputPorts(FindPorts::PortType);
void addInputOutputPorts(FindPorts::PortType); void addInputOutputPorts(FindPorts::PortType);
...@@ -85,6 +88,8 @@ public: ...@@ -85,6 +88,8 @@ public:
void dumpInstances(raw_ostream &, int); void dumpInstances(raw_ostream &, int);
void dumpSignalBinding(raw_ostream &, int); void dumpSignalBinding(raw_ostream &, int);
json dump_json();
private: private:
string module_name_; string module_name_;
CXXRecordDecl *class_decl_; CXXRecordDecl *class_decl_;
......
...@@ -5,24 +5,24 @@ ...@@ -5,24 +5,24 @@
using namespace scpar; using namespace scpar;
using namespace std; using namespace std;
void Signal::check() { assert(!(_sig == NULL)); } void Signal::check() { assert(!(signal_container_ == nullptr)); }
Signal::Signal() : _name("NONE"), _sig(NULL) {} Signal::Signal() : signal_name_("NONE"), signal_container_(nullptr) {}
Signal::Signal(const string &name, SignalContainer *s) : _name(name), _sig(s) {} Signal::Signal(const string &name, SignalContainer *s) : signal_name_(name), signal_container_(s) {}
void Signal::setModuleName(const string &name) { _name = name; } void Signal::setModuleName(const string &name) { signal_name_ = name; }
string Signal::getName() { return _name; } string Signal::getName() { return signal_name_; }
FindTemplateTypes *Signal::getTemplateTypes() { FindTemplateTypes *Signal::getTemplateTypes() {
check(); check();
return _sig->getTemplateTypes(); return signal_container_->getTemplateTypes();
} }
FieldDecl *Signal::getASTNode() { FieldDecl *Signal::getASTNode() {
check(); check();
return _sig->getASTNode(); return signal_container_->getASTNode();
} }
void Signal::dump(raw_ostream &os, int tabn = 0) { void Signal::dump(raw_ostream &os, int tabn = 0) {
...@@ -30,7 +30,7 @@ void Signal::dump(raw_ostream &os, int tabn = 0) { ...@@ -30,7 +30,7 @@ void Signal::dump(raw_ostream &os, int tabn = 0) {
for (int i = 0; i < tabn; i++) { for (int i = 0; i < tabn; i++) {
os << " "; os << " ";
} }
os << "Signal " << this << " '" << _name << "' FindTemplateTypes " os << "Signal " << this << " '" << signal_name_ << "' FindTemplateTypes "
<< _sig->getTemplateTypes() << "' FieldDecl' " << _sig->getASTNode(); << signal_container_->getTemplateTypes() << "' FieldDecl' " << signal_container_->getASTNode();
_sig->getTemplateTypes()->printTemplateArguments(os); signal_container_->getTemplateTypes()->printTemplateArguments(os);
} }
...@@ -32,8 +32,8 @@ private: ...@@ -32,8 +32,8 @@ private:
void check(); void check();
private: private:
string _name; string signal_name_;
SignalContainer *_sig; SignalContainer * signal_container_;
}; };
} // namespace scpar } // namespace scpar
#endif #endif
Supports Markdown
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