FindGlobalEvents.cpp 1.33 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
3
#include "FindGlobalEvents.h"
using namespace scpar;

rmrf's avatar
rmrf committed
4
5
6
7
FindGlobalEvents::FindGlobalEvents(TranslationUnitDecl * declaration, llvm::raw_ostream &os)
  : _os(os) {

  TraverseDecl(declaration);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
8
9
}

rmrf's avatar
rmrf committed
10
FindGlobalEvents::~FindGlobalEvents() {}
11

rmrf's avatar
rmrf committed
12
13
bool FindGlobalEvents::VisitVarDecl(VarDecl * variable_declaration) {
  QualType variable_type { variable_declaration->getType() };
rmrf's avatar
rmrf committed
14

rmrf's avatar
rmrf committed
15
16
  if (variable_type.getAsString() == "class sc_core::sc_event") {
    if (IdentifierInfo *info = variable_declaration->getIdentifier()) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
17

rmrf's avatar
rmrf committed
18
      _globalEvents.insert( kvType(info->getNameStart(), variable_declaration) );
Anirudh Kaushik's avatar
Anirudh Kaushik committed
19
20
21
22
23
    }
  }
  return true;
}

rmrf's avatar
rmrf committed
24
FindGlobalEvents::globalEventMapType FindGlobalEvents::getEventMap() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
25
26
27
  return _globalEvents;
}

rmrf's avatar
rmrf committed
28
void FindGlobalEvents::dump() {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
29
30
31
32
33
34
35
36
  _os << "\n ==============  FindGlobalEvents ===============";
  _os << "\n:> Print global sc_event variables";
  for (globalEventMapType::iterator vit = _globalEvents.begin();
       vit != _globalEvents.end(); vit++) {
    _os << "\n Name: " << vit->first << ", VarDecl*: " << vit->second;
  }
  _os << "\n ============== END FindGlobalEvents ===============";
}
rmrf's avatar
rmrf committed
37
38
39
40
41

json FindGlobalEvents::dump_json() {
  json globals_j{};


rmrf's avatar
rmrf committed
42
  for ( auto const & event : _globalEvents ) {
rmrf's avatar
rmrf committed
43
44
45
46
47
48
    globals_j["global_declarations"].emplace_back( event.first ) ;
  }
  std::cout << globals_j.dump(4) << endl;
  return globals_j;
}