Commit 7e25e8e5 authored by rmrf's avatar rmrf

ProcessDecl: JSON print

parent 3de49875
...@@ -221,7 +221,7 @@ void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) { ...@@ -221,7 +221,7 @@ void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) {
} else { } else {
for (auto pit : _processes) { for (auto pit : _processes) {
ProcessDecl *pd = pit.second; ProcessDecl *pd = pit.second;
pd->dump(os, tabn); pd->dump( os );
os << "\n"; os << "\n";
} }
} }
......
#include "ProcessDecl.h" #include "ProcessDecl.h"
using namespace scpar; using namespace scpar;
//using namespace nlohmann::json;
ProcessDecl::ProcessDecl(string t, string n, CXXMethodDecl *entryMethodDecl, ProcessDecl::ProcessDecl(string t, string n, CXXMethodDecl *entryMethodDecl,
EntryFunctionContainer *e) EntryFunctionContainer *e) :
: _type(t), _entryName(n), _entryMethodDecl(entryMethodDecl), _ef(e) {} process_type_(t), entry_name_(n), entry_method_decl_(entryMethodDecl), entry_function_ptr_(e) {}
ProcessDecl::~ProcessDecl() { ProcessDecl::~ProcessDecl() {
// The following points do NOT need to be deleted:_entryMethodDecl, // The following points do NOT need to be deleted:entry_method_decl_,
// _constructorStmt. This is because they are pointers to the clang AST, which // _constructorStmt. This is because they are pointers to the clang AST, which
// are going to be freed by clang itself. // are going to be freed by clang itself.
entry_method_decl_ = nullptr;
entry_function_ptr_ = nullptr;
} }
ProcessDecl::ProcessDecl(const ProcessDecl &from) { ProcessDecl::ProcessDecl(const ProcessDecl &from) {
_type = from._type; process_type_ = from.process_type_;
_entryName = from._entryName; entry_name_ = from.entry_name_;
_entryMethodDecl = from._entryMethodDecl; entry_method_decl_ = from.entry_method_decl_;
_ef = from._ef; entry_function_ptr_ = from.entry_function_ptr_;
} }
string ProcessDecl::getType() { return _type; } string ProcessDecl::getType() const { return process_type_; }
string ProcessDecl::getName() const { return entry_name_; }
CXXMethodDecl *ProcessDecl::getEntryMethodDecl() const { return entry_method_decl_; }
void ProcessDecl::dump(raw_ostream &os) {
os << "ProcessDecl " << this << " '" << entry_name_ << "' " << entry_method_decl_
<< " " << process_type_;
// TODO: Remove this tabn
os << "\nEntry function:\n";
entry_function_ptr_->dump(os, 1);
dump_json();
}
string ProcessDecl::getName() { return _entryName; } json ProcessDecl::dump_json() const {
CXXMethodDecl *ProcessDecl::getEntryMethodDecl() { return _entryMethodDecl; } // These are the three fields that we need to extract from entry_function_ptr.
json process_j;
process_j["entry_name"] = getName();
process_j["procesS_type"] = getType();
process_j["entry_method_declaration"] = to_string( getEntryMethodDecl() );
void ProcessDecl::dump(raw_ostream &os, int tabn) { std::cout << process_j.dump(4);
for (int i = 0; i < tabn; i++) { return process_j;
os << " ";
}
os << "ProcessDecl " << this << " '" << _entryName << "' " << _entryMethodDecl
<< " " << _type;
_ef->dump(os, ++tabn);
} }
#ifndef _PROCESSDECL_H_ #ifndef _PROCESSDECL_H_
#define _PROCESSDECL_H_ #define _PROCESSDECL_H_
#include "systemc-clang.h"
#include "json.hpp"
#include "EntryFunctionContainer.h" #include "EntryFunctionContainer.h"
#include "FindEntryFunctions.h" #include "FindEntryFunctions.h"
#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclCXX.h"
...@@ -11,6 +13,7 @@ namespace scpar { ...@@ -11,6 +13,7 @@ namespace scpar {
using namespace std; using namespace std;
using namespace clang; using namespace clang;
using json = nlohmann::json;
class ProcessDecl { class ProcessDecl {
public: public:
...@@ -22,21 +25,22 @@ public: ...@@ -22,21 +25,22 @@ public:
~ProcessDecl(); ~ProcessDecl();
/// Accessor methods. /// Accessor methods.
string getType(); string getType() const;
string getName(); string getName() const;
CXXMethodDecl *getEntryMethodDecl(); CXXMethodDecl *getEntryMethodDecl() const;
// Dump. // Dump.
void dump(raw_ostream &, int); void dump(raw_ostream &);
json dump_json() const;
protected: protected:
// Process information // Process information
string _type; string process_type_;
string _entryName; string entry_name_;
// Each process can have 1 entry function. // Each process can have 1 entry function.
CXXMethodDecl *_entryMethodDecl; CXXMethodDecl *entry_method_decl_;
EntryFunctionContainer *_ef; EntryFunctionContainer *entry_function_ptr_;
}; // End class ProcessDecl }; // End class ProcessDecl
} // End namespace scpar } // End namespace scpar
......
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