FindWait.cpp 3.36 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
#include "FindWait.h"
#include "clang/AST/DeclTemplate.h"
rmrf's avatar
rmrf committed
3
#include "clang/AST/PrettyPrinter.h"
Anirudh Kaushik's avatar
Anirudh Kaushik committed
4
5
6
7
8
9
#include "clang/AST/Type.h"
#include "clang/Basic/SourceManager.h"

using namespace scpar;
using namespace std;

rmrf's avatar
rmrf committed
10
FindWait::FindWait(CXXMethodDecl *d, llvm::raw_ostream &os)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    : entry_method_decl_{d}, os_{os}, wait_call_{nullptr},
      found_wait_{false} {
          TraverseDecl(d);

          // If there was a wait that was found.  Then go through and dump them all out?
          if (found_wait_) {
              for (auto wait  : wait_calls_list_) {
                  wait->dump(os_,2);
              }
          }
      }

FindWait::~FindWait() {
    // Delete all the pointers.
    for (auto wait : wait_calls_list_ ) {
        delete wait;
    }
    wait_calls_list_.clear();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
29
30
}

31
32
33
34
35
36
37
38
39
40
41
42
43

bool FindWait::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *e) {

    // This is for the templated wait calls.
    // e should not be null if it gets here.
    if (e->getMemberNameInfo().getAsString() == string("wait") ) {

        wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, wait_call_));
        found_wait_ = true;
    }

    return true;
}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
44

rmrf's avatar
rmrf committed
45
bool FindWait::VisitCallExpr(CallExpr *e) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    clang::LangOptions LangOpts;
    LangOpts.CPlusPlus = true;
    clang::PrintingPolicy Policy(LangOpts);

    // This allows templated wait calls to refer to the CallExpr as well.
    wait_call_ = e;
    // Check if the non-templated wait has a "wait" in it.
    auto direct_callee{ e->getDirectCallee() };
    if ( (direct_callee != nullptr) ) {
        if ( (direct_callee->getNameInfo().getAsString() == string("wait") ) ) {

            // Insert the information to parse the wait arguments.
            wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, wait_call_));
            found_wait_ = true;
        }
    }

    return true;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
65
66
}

rmrf's avatar
rmrf committed
67
FindWait::waitListType FindWait::getWaitCalls() { return wait_calls_list_; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
68

rmrf's avatar
rmrf committed
69
CXXMethodDecl *FindWait::getEntryMethod() const { return entry_method_decl_; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
70

71
void FindWait::dump() {
72
73
74
75
76
77
78
    /*
      os_ << "\n ============== FindWait ===============";
      os_ << "\n:> Print 'wait' statement informtion\n";
      for (unsigned int i = 0; i < wait_calls_list_.size(); i++) {
      if(wait_calls_list_.size() > 2) {
      os_ << ":> wait pointer: " <<  wait_calls_list_[i] << "num. of args: " <<
      wait_calls_list_[i]->getNumArgs()-1 << "\n";
rmrf's avatar
rmrf committed
79

80
81
82
83
84
85
86
87
      for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs()-1; j++) {
      os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
      << "\n";
      }
      }
      else {
      os_ << ":> wait pointer: " <<  wait_calls_list_[i] << "num. of args: " <<
      wait_calls_list_[i]->getNumArgs() << "\n";
rmrf's avatar
rmrf committed
88

89
90
91
92
93
94
      for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs(); j++) {
      os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
      << "\n";
      }
      }
      }
rmrf's avatar
rmrf committed
95

96
      os_ << "\n ============== END FindWait ===============";
rmrf's avatar
rmrf committed
97

98
99
100
101
102
103
104
105
106
107
108
109
      os_ <<"\n Process and waiting on events ";
      for (processWaitEventMapType::iterator it = _processWaitEventMap.begin(), eit =
      _processWaitEventMap.end(); it != eit; it++) { os_ <<"\n Process :"
      <<it->first->getDeclName().getAsString();

      os_ <<"\n Waiting on event(s) : ";
      vector<string> tmp = it->second;
      for (int i = 0; i<tmp.size(); i++) {
      os_ <<tmp.at(i)<<" ";
      }
      }
    */
Anirudh Kaushik's avatar
Anirudh Kaushik committed
110
}