Commit e58cbf53 authored by rmrf's avatar rmrf

Globals should have json dump too

parent 47623cf0
#include "FindGlobalEvents.h"
using namespace scpar;
FindGlobalEvents::FindGlobalEvents(TranslationUnitDecl *d,
llvm::raw_ostream &os)
: _os(os) {
TraverseDecl(d);
FindGlobalEvents::FindGlobalEvents(TranslationUnitDecl * declaration, llvm::raw_ostream &os)
: _os(os) {
TraverseDecl(declaration);
}
FindGlobalEvents::~FindGlobalEvents() {}
bool FindGlobalEvents::VisitVarDecl(VarDecl *vd) {
QualType q = vd->getType();
bool FindGlobalEvents::VisitVarDecl(VarDecl * variable_declaration) {
QualType variable_type { variable_declaration->getType() };
if (q.getAsString() == "class sc_core::sc_event") {
if (IdentifierInfo *info = vd->getIdentifier()) {
if (variable_type.getAsString() == "class sc_core::sc_event") {
if (IdentifierInfo *info = variable_declaration->getIdentifier()) {
_globalEvents.insert(kvType(info->getNameStart(), vd));
_globalEvents.insert( kvType(info->getNameStart(), variable_declaration) );
}
}
return true;
......@@ -34,3 +34,15 @@ void FindGlobalEvents::dump() {
}
_os << "\n ============== END FindGlobalEvents ===============";
}
json FindGlobalEvents::dump_json() {
json globals_j{};
for ( auto const & event : _globalEvents ) {
globals_j["global_declarations"].emplace_back( event.first ) ;
}
std::cout << globals_j.dump(4) << endl;
return globals_j;
}
#ifndef _FIND_GLOBAL_EVENTS_H_
#define _FIND_GLOBAL_EVENTS_H_
#include "systemc-clang.h"
#include "json.hpp"
#include "clang/AST/Decl.h"
#include "clang/AST/RecursiveASTVisitor.h"
......@@ -11,7 +13,8 @@
namespace scpar {
using namespace clang;
using namespace std;
using json = nlohmann::json;
class FindGlobalEvents : public RecursiveASTVisitor<FindGlobalEvents> {
public:
typedef map<string, VarDecl *> globalEventMapType;
......@@ -26,6 +29,8 @@ public:
vector<string> getEventNames();
void dump();
json dump_json();
private:
llvm::raw_ostream &_os;
......
......@@ -15,13 +15,15 @@ bool SystemCConsumer::fire() {
// Reflection database.
_systemcModel = new Model{} ;
// ANI : Do we need FindGlobalEvents?
FindGlobalEvents globals{tu, _os};
FindGlobalEvents::globalEventMapType eventMap{globals.getEventMap()};
globals.dump_json();
_systemcModel->addGlobalEvents(eventMap);
// Find the sc_modules
FindSCModules scmod{tu, _os};
// ANI : Do we need FindGlobalEvents?
FindGlobalEvents fglobals{tu, _os};
FindGlobalEvents::globalEventMapType eventMap{fglobals.getEventMap()};
_systemcModel->addGlobalEvents(eventMap);
FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()};
......
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