47b50188 by rmrf

Module declaration json printing is working

1 parent ae33ed08
......@@ -39,7 +39,7 @@ ModuleDecl::~ModuleDecl() {
void ModuleDecl::setModuleName(const string &name) { module_name_ = name; }
void ModuleDecl::addInstances(vector<string> instanceList) {
void ModuleDecl::addInstances(const vector<string> & instanceList) {
_instanceList = instanceList;
}
......@@ -216,16 +216,16 @@ void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) {
}
void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) {
if ( process_map_.empty() ) {
os << "none \n";
} else {
for (auto pit : process_map_) {
ProcessDecl *pd = pit.second;
pd->dump( os );
os << "\n";
json process_j;
process_j["number_of_processes"] = process_map_.size();
for (auto pit : process_map_) {
ProcessDecl *pd { pit.second };
process_j[pit.first] = pd->dump_json( os );
}
}
os << "\n";
os << "Processes\n";
os << process_j.dump(4) << "\n";
}
void ModuleDecl::dumpInterfaces(raw_ostream &os, int tabn) {
......@@ -266,76 +266,61 @@ void ModuleDecl::dumpInterfaces(raw_ostream &os, int tabn) {
}
void ModuleDecl::dumpPorts(raw_ostream &os, int tabn) {
os << "Input ports: " << _iports.size();
// os << "\nInput ports: " << _iports.size() << "\n";
json iport_j, oport_j, ioport_j;
iport_j["number_of_in_ports"] = _iports.size();
if (_iports.size() == 0) {
os << "\n none \n";
} else {
os << "\n ";
for (auto mit : _iports) {
mit.second->dump(os);
os << "\n ";
iport_j[mit.first] = mit.second->dump_json(os);
}
os << "\n";
}
os << "Output ports: " << _oports.size();
if (_oports.size() == 0) {
os << "\n none \n";
} else {
os << "\n ";
// os << "\nOutput ports: " << _oports.size() << "\n";
oport_j["number_of_output_ports"] = _oports.size();
for (auto mit : _oports) {
mit.second->dump(os, tabn);
os << "\n";
oport_j[mit.first] = mit.second->dump_json(os);
}
}
os << "Inout ports: " << _ioports.size();
if (_ioports.size() == 0) {
os << "\n none \n";
} else {
os << "\n ";
for (auto mit : _oports) {
mit.second->dump(os, tabn);
os << "\n ";
// os << "\nInout ports: " << _ioports.size() << "\n";
ioport_j["number_of_inout_ports"] = _ioports.size();
for (auto mit : _ioports) {
ioport_j[mit.first] = mit.second->dump_json(os);
}
}
os << "\n";
os << "Ports\n";
os << iport_j.dump(4) << "\n" << oport_j.dump(4) << "\n"
<< ioport_j.dump(4)<< "\n";
}
void ModuleDecl::dumpSignals(raw_ostream &os, int tabn) {
if (_signals.size() == 0) {
os << "none \n";
} else {
for (auto sit : _signals) {
Signal *s = sit.second;
s->dump(os, tabn);
os << "\n";
}
json signal_j;
signal_j["number_of_signals"] = _signals.size();
for (auto sit : _signals) {
Signal *s = sit.second;
signal_j[sit.first] = s->dump_json(os);
}
os << "\n";
os << "Signals\n";
os << signal_j.dump(4) << "\n";
}
void ModuleDecl::dump(raw_ostream &os) {
// os << "ModuleDecl " << this << " " << module_name_
// << " CXXRecordDecl " << class_decl_ << "\n";
os << "\n";
os << "\n# Instances:\n";
dumpInstances(os, 4);
os << "# Port Declaration:\n";
dumpPorts(os, 4);
os << "# Signal Declaration:\n";
os << "\n# Signal Declaration:\n";
dumpSignals(os, 4);
os << "# Processes:\n";
os << "\n# Processes:\n";
dumpProcesses(os, 4);
os << "# Instances:\n";
dumpInstances(os, 4);
os << "# Signal binding:\n";
dumpSignalBinding(os, 4);
dump_json();
os << "\n=======================================================\n";
}
json ModuleDecl::dump_json() {
......
......@@ -61,7 +61,7 @@ public:
void addOutputInterfaces(FindTLMInterfaces::interfaceType);
void addInputOutputInterfaces(FindTLMInterfaces::interfaceType);
void addProcess(FindEntryFunctions::entryFunctionVectorType *);
void addInstances(vector<string>);
void addInstances(const vector<string> & );
void addSignalBinding(map<string, string>);
void setModuleName(const string &);
void addConstructor(Stmt *);
......
......@@ -32,10 +32,10 @@ void PortDecl::dump(llvm::raw_ostream &os, int tabn) {
//os << "Port name: " << port_name_ << " ";
//template_type_->printTemplateArguments(os);
dump_json();
//dump_json();
}
json PortDecl::dump_json() {
json PortDecl::dump_json(raw_ostream & os) {
json port_j;
port_j["port_name"] = getName();
......@@ -49,6 +49,6 @@ json PortDecl::dump_json() {
port_j["port_arguments"].push_back( ait->getTypeName() );
}
std::cout << port_j.dump(4);
//os << port_j.dump(4);
return port_j;
}
......
......@@ -33,7 +33,7 @@ public:
// Print
void dump(raw_ostream &, int tabn = 0);
json dump_json();
json dump_json(raw_ostream &);
private:
// Name of the port
......
......@@ -38,10 +38,10 @@ void ProcessDecl::dump(raw_ostream &os) {
os << "\nEntry function:\n";
entry_function_ptr_->dump(os, 1);
dump_json();
//dump_json();
}
json ProcessDecl::dump_json() const {
json ProcessDecl::dump_json(raw_ostream & os ) const {
// These are the three fields that we need to extract from entry_function_ptr.
json process_j;
......@@ -49,6 +49,6 @@ json ProcessDecl::dump_json() const {
process_j["procesS_type"] = getType();
process_j["entry_method_declaration"] = to_string( getEntryMethodDecl() );
std::cout << process_j.dump(4);
// os << process_j.dump(4);
return process_j;
}
......
......@@ -31,7 +31,7 @@ public:
// Dump.
void dump(raw_ostream &);
json dump_json() const;
json dump_json(raw_ostream &) const;
protected:
// Process information
......
......@@ -27,10 +27,32 @@ FieldDecl *Signal::getASTNode() {
void Signal::dump(raw_ostream &os, int tabn = 0) {
check();
for (int i = 0; i < tabn; i++) {
os << " ";
}
os << "Signal " << this << " '" << signal_name_ << "' FindTemplateTypes "
<< signal_container_->getTemplateTypes() << "' FieldDecl' " << signal_container_->getASTNode();
signal_container_->getTemplateTypes()->printTemplateArguments(os);
// for (int i = 0; i < tabn; i++) {
// os << " ";
// }
// os << "Signal " << this << " '" << signal_name_ << "' FindTemplateTypes "
// << signal_container_->getTemplateTypes() << "' FieldDecl' " << signal_container_->getASTNode();
// signal_container_->getTemplateTypes()->printTemplateArguments(os);
//dump_json();
}
json Signal::dump_json( raw_ostream & os ) {
json signal_j;
signal_j["signal_name"] = getName();
// Container
auto template_args{ signal_container_->getTemplateTypes()->getTemplateArgumentsType() };
signal_j["signal_type"] = template_args[0].getTypeName();
template_args.erase( begin(template_args) );
for ( auto ait = begin(template_args); ait != end(template_args); ++ait ) {
signal_j["signal_arguments"].push_back( ait->getTypeName() );
}
//os << signal_j.dump(4);
return signal_j;
}
......
......@@ -5,12 +5,16 @@
#include <map>
#include <string>
#include "systemc-clang.h"
#include "json.hpp"
#include "FindSignals.h"
#include "FindTemplateTypes.h"
namespace scpar {
using namespace clang;
using namespace std;
using json = nlohmann::json;
class Signal {
public:
......@@ -28,6 +32,8 @@ public:
// Print
void dump(raw_ostream &, int tabn);
json dump_json(raw_ostream &);
private:
void check();
......
......@@ -26,8 +26,7 @@ bool SystemCConsumer::fire() {
FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()};
for (FindSCModules::moduleMapType::iterator mit = scmodules.begin(),
mitend = scmodules.end();
mit != mitend; ++mit) {
mitend = scmodules.end(); mit != mitend; ++mit) {
ModuleDecl *md = new ModuleDecl{mit->first, mit->second};
_systemcModel->addModuleDecl(md);
}
......@@ -59,8 +58,7 @@ bool SystemCConsumer::fire() {
Model::moduleMapType moduleMap{_systemcModel->getModuleDecl()};
for (Model::moduleMapType::iterator mit = moduleMap.begin(),
mitend = moduleMap.end();
mit != mitend; mit++) {
mitend = moduleMap.end(); mit != mitend; mit++) {
ModuleDecl *mainmd{mit->second};
int numInstances{mainmd->getNumInstances()};
vector<ModuleDecl *> moduleDeclVec;
......@@ -95,8 +93,7 @@ bool SystemCConsumer::fire() {
for (size_t i = 0; i < entryFunctions->size(); i++) {
EntryFunctionContainer *ef{(*entryFunctions)[i]};
FindSensitivity findSensitivity{constructor.returnConstructorStmt(),
_os};
FindSensitivity findSensitivity{constructor.returnConstructorStmt(), _os};
ef->addSensitivityInfo(findSensitivity);
if (ef->getEntryMethod() == nullptr) {
......