diff --git a/src/ModuleDecl.cpp b/src/ModuleDecl.cpp index 64814a163e705bd8c3e68a6c8a5da0b0d103de77..75dbe25185016d5fc06aea150665febb9e876cc7 100644 --- a/src/ModuleDecl.cpp +++ b/src/ModuleDecl.cpp @@ -221,7 +221,7 @@ void ModuleDecl::dumpProcesses(raw_ostream &os, int tabn) { } else { for (auto pit : _processes) { ProcessDecl *pd = pit.second; - pd->dump(os, tabn); + pd->dump( os ); os << "\n"; } } diff --git a/src/ProcessDecl.cpp b/src/ProcessDecl.cpp index 4d66084908402335d082bc1f2ece739afb65b1fb..1c02f1caaa6ec43eef58d27a8dd20d7594a75a56 100644 --- a/src/ProcessDecl.cpp +++ b/src/ProcessDecl.cpp @@ -1,35 +1,54 @@ #include "ProcessDecl.h" using namespace scpar; +//using namespace nlohmann::json; ProcessDecl::ProcessDecl(string t, string n, CXXMethodDecl *entryMethodDecl, - EntryFunctionContainer *e) - : _type(t), _entryName(n), _entryMethodDecl(entryMethodDecl), _ef(e) {} + EntryFunctionContainer *e) : + process_type_(t), entry_name_(n), entry_method_decl_(entryMethodDecl), entry_function_ptr_(e) {} 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 // are going to be freed by clang itself. + + entry_method_decl_ = nullptr; + entry_function_ptr_ = nullptr; } ProcessDecl::ProcessDecl(const ProcessDecl &from) { - _type = from._type; - _entryName = from._entryName; - _entryMethodDecl = from._entryMethodDecl; - _ef = from._ef; + process_type_ = from.process_type_; + entry_name_ = from.entry_name_; + entry_method_decl_ = from.entry_method_decl_; + 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) { - for (int i = 0; i < tabn; i++) { - os << " "; - } - os << "ProcessDecl " << this << " '" << _entryName << "' " << _entryMethodDecl - << " " << _type; - _ef->dump(os, ++tabn); + std::cout << process_j.dump(4); + return process_j; } diff --git a/src/ProcessDecl.h b/src/ProcessDecl.h index e70213c90ff6778f8a05bc25d4160ea32ec1f845..97dd90c0487ddbc989b1e7d31d113c58ea1ecd53 100644 --- a/src/ProcessDecl.h +++ b/src/ProcessDecl.h @@ -1,6 +1,8 @@ #ifndef _PROCESSDECL_H_ #define _PROCESSDECL_H_ +#include "systemc-clang.h" +#include "json.hpp" #include "EntryFunctionContainer.h" #include "FindEntryFunctions.h" #include "clang/AST/DeclCXX.h" @@ -11,6 +13,7 @@ namespace scpar { using namespace std; using namespace clang; +using json = nlohmann::json; class ProcessDecl { public: @@ -22,21 +25,22 @@ public: ~ProcessDecl(); /// Accessor methods. - string getType(); - string getName(); - CXXMethodDecl *getEntryMethodDecl(); + string getType() const; + string getName() const; + CXXMethodDecl *getEntryMethodDecl() const; // Dump. - void dump(raw_ostream &, int); + void dump(raw_ostream &); + json dump_json() const; protected: // Process information - string _type; - string _entryName; + string process_type_; + string entry_name_; // Each process can have 1 entry function. - CXXMethodDecl *_entryMethodDecl; + CXXMethodDecl *entry_method_decl_; - EntryFunctionContainer *_ef; + EntryFunctionContainer *entry_function_ptr_; }; // End class ProcessDecl } // End namespace scpar