8b834694 by Twiga

Signal and SignalContainer needs updates

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