EntryFunctionContainer.cpp 6.21 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
3
4
5
#include "EntryFunctionContainer.h"
#include "enums.h"

using namespace scpar;

rmrf's avatar
rmrf committed
6
7
EntryFunctionContainer::~EntryFunctionContainer() {
  // DO NOT free anything.
Anirudh Kaushik's avatar
Anirudh Kaushik committed
8
9
}

rmrf's avatar
rmrf committed
10
11
12
EntryFunctionContainer::EntryFunctionContainer()
    : _entryName("NONE"), _procType(PROCESS_TYPE::NONE),
      _entryMethodDecl(nullptr) {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
13

rmrf's avatar
rmrf committed
14
15
16
EntryFunctionContainer::EntryFunctionContainer(string n, PROCESS_TYPE p,
                                               CXXMethodDecl *d, Stmt *s)
    : _entryName(n), _procType(p), _entryMethodDecl(d) {}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
17

rmrf's avatar
rmrf committed
18
19
20
21
22
EntryFunctionContainer::EntryFunctionContainer(
    const EntryFunctionContainer &from) {
  _entryName = from._entryName;
  _procType = from._procType;
  _entryMethodDecl = from._entryMethodDecl;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
23
24
25
}

///////////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
26
string EntryFunctionContainer::getName() { return _entryName; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
27
28

FindSensitivity::senseMapType EntryFunctionContainer::getSenseMap() {
rmrf's avatar
rmrf committed
29
  return _senseMap;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
30
31
}

rmrf's avatar
rmrf committed
32
33
CXXMethodDecl *EntryFunctionContainer::getEntryMethod() {
  return _entryMethodDecl;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
34
35
}

rmrf's avatar
rmrf committed
36
37
38
EntryFunctionContainer::waitContainerListType
EntryFunctionContainer::getWaitCalls() {
  return _waitCalls;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
39
40
}

rmrf's avatar
rmrf committed
41
42
43
EntryFunctionContainer::notifyContainerListType
EntryFunctionContainer::getNotifyCalls() {
  return _notifyCalls;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
44
45
}

rmrf's avatar
rmrf committed
46
PROCESS_TYPE EntryFunctionContainer::getProcessType() { return _procType; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
47

Anirudh's avatar
Anirudh committed
48
49
SuspensionAutomata::susCFGVectorType EntryFunctionContainer::getSusCFG() {
  return _susCFG;
rmrf's avatar
rmrf committed
50
  // return _instanceSusCFGMap[numInstance];
Anirudh Kaushik's avatar
Anirudh Kaushik committed
51
52
}

Anirudh's avatar
Anirudh committed
53
SuspensionAutomata::transitionVectorType EntryFunctionContainer::getSusAuto() {
rmrf's avatar
rmrf committed
54
55
  return _susAuto;
  // return _instanceSautoMap[numInstance];
Anirudh Kaushik's avatar
Anirudh Kaushik committed
56
57
}
///////////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
58
void EntryFunctionContainer::setName(string n) { _entryName = n; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
59

rmrf's avatar
rmrf committed
60
void EntryFunctionContainer::setProcessType(PROCESS_TYPE p) { _procType = p; }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
61

rmrf's avatar
rmrf committed
62
63
void EntryFunctionContainer::setEntryMethod(CXXMethodDecl *d) {
  _entryMethodDecl = d;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
64
65
66
}

void EntryFunctionContainer::addSensitivityInfo(FindSensitivity &s) {
rmrf's avatar
rmrf committed
67
  _senseMap = s.getSenseMap();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
68
69
}

rmrf's avatar
rmrf committed
70
71
72
73
74
75
76
77
78
79
void EntryFunctionContainer::addWaits(FindWait &f) {
  FindWait::waitListType wcalls = f.getWaitCalls();
  for (FindWait::waitListType::iterator it = wcalls.begin(), eit = wcalls.end();
       it != eit; it++) {
    // 'it' points to CXXMembercallExpr type.
    WaitContainer *wc{
        new WaitContainer(f.getEntryMethod(), (*it)->getASTNode())};
    _waitCalls.push_back(wc);
  }
  //_processWaitEventMap = f.getProcessWaitEventMap();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
80
81
}

Anirudh's avatar
Anirudh committed
82
void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) {
rmrf's avatar
rmrf committed
83
84
  _susCFG = s.getSusCFG();
  _susAuto = s.getSauto();
85

rmrf's avatar
rmrf committed
86
87
88
89
90
91
92
93
94
  /*
  if (_instanceSusCFGMap.find(numInstance) == _instanceSusCFGMap.end() &&
  _instanceSautoMap.find(numInstance) == _instanceSautoMap.end()) {

                 _instanceSusCFGMap.insert(instanceSusCFGPairType(numInstance,
  s.getSusCFG())); _instanceSautoMap.insert(instanceSautoPairType(numInstance,
  s.getSauto()));
  }
  */
Anirudh Kaushik's avatar
Anirudh Kaushik committed
95
96
}

rmrf's avatar
rmrf committed
97
void EntryFunctionContainer::addNotifys(FindNotify &f) {
rmrf's avatar
rmrf committed
98
  FindNotify::NotifyCallListType ncalls = f.getNotifyCallList();
rmrf's avatar
rmrf committed
99
100
101
  for (FindNotify::NotifyCallListType::iterator it = ncalls.begin(),
                                                eit = ncalls.end();
       it != eit; it++) {
Anirudh Kaushik's avatar
Anirudh Kaushik committed
102
    // 'it' points to CXXMembercallExpr type.
rmrf's avatar
rmrf committed
103
    NotifyContainer *nc = new NotifyContainer(f.getEntryMethod(), *it);
Anirudh Kaushik's avatar
Anirudh Kaushik committed
104
105
    _notifyCalls.push_back(nc);
  }
rmrf's avatar
rmrf committed
106
  //_processWaitEventMap = f.getProcessWaitEventMap();
Anirudh Kaushik's avatar
Anirudh Kaushik committed
107
108
109
}

///////////////////////////////////////////////////////////////////////////////////////////////
rmrf's avatar
rmrf committed
110
void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) {
Anirudh's avatar
Anirudh committed
111

rmrf's avatar
rmrf committed
112
  os << "\n#############################################";
Anirudh's avatar
Anirudh committed
113
114
115
  SuspensionAutomata::susCFGVectorType susCFGVector = _susCFG;

  for (unsigned int i = 0; i < susCFGVector.size(); i++) {
rmrf's avatar
rmrf committed
116
    os << "\n Block ID : " << susCFGVector.at(i)->getBlockID();
Anirudh's avatar
Anirudh committed
117
118
    os << "\n Is Wait Block : " << susCFGVector.at(i)->isWaitBlock();
    if (susCFGVector.at(i)->getParentBlockID()) {
rmrf's avatar
rmrf committed
119
120
      os << "\n Parent ID : " << susCFGVector.at(i)->getParentBlockID();
      SusCFG *parentBlock = susCFGVector.at(i)->getParentSusCFGBlock();
Anirudh's avatar
Anirudh committed
121

rmrf's avatar
rmrf committed
122
      os << "\n Parent Block ID : " << parentBlock->getBlockID();
Anirudh's avatar
Anirudh committed
123
124
      os << "\n Size of Children : " << parentBlock->getChildBlockList().size();
    }
rmrf's avatar
rmrf committed
125
126
    vector<SusCFG *> predBlocks = susCFGVector.at(i)->getPredBlocks();
    vector<SusCFG *> succBlocks = susCFGVector.at(i)->getSuccBlocks();
Anirudh's avatar
Anirudh committed
127
128
    os << "\n Predecessor Blocks : ";
    for (unsigned int j = 0; j < predBlocks.size(); j++) {
rmrf's avatar
rmrf committed
129
130
      if (predBlocks.at(j)) {
        os << predBlocks.at(j)->getBlockID() << " ";
Anirudh Kaushik's avatar
Anirudh Kaushik committed
131
      }
Anirudh's avatar
Anirudh committed
132
133
134
    }
    os << "\n Successor Blocks : ";
    for (unsigned int j = 0; j < succBlocks.size(); j++) {
rmrf's avatar
rmrf committed
135
136
      if (succBlocks.at(j)) {
        os << succBlocks.at(j)->getBlockID() << " ";
Anirudh Kaushik's avatar
Anirudh Kaushik committed
137
      }
rmrf's avatar
rmrf committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    }
  }
}

void EntryFunctionContainer::dumpSauto(raw_ostream &os) {
  vector<Transition *> transitionVector = _susAuto;
  os << "\n Size of transitionVector : " << transitionVector.size();
  for (unsigned int i = 0; i < transitionVector.size(); i++) {
    Transition *t = transitionVector.at(i);
    t->dump(os);
  }
}

void EntryFunctionContainer::dump(raw_ostream &os, int tabn) {
  os << "\n";
  for (int i = 0; i < tabn; i++) {
    os << " ";
  }

  os << "EntryFunctionContainer '" << getName() << "' processType '";
  switch (getProcessType()) {
  case PROCESS_TYPE::THREAD:
    os << "SC_THREAD' ";
    break;
  case PROCESS_TYPE::METHOD:
    os << "SC_METHOD' ";
    break;
  case PROCESS_TYPE::CTHREAD:
    os << "SC_CTHREAD' ";
    break;
  default:
    os << "NONE' ";
    break;
  }

  os << " CXXMethodDecl '" << getEntryMethod() << "\n";
  int newTabn = ++tabn;

  os << " Wait Calls \n";
  for (waitContainerListType::iterator it = _waitCalls.begin(),
                                       eit = _waitCalls.end();
       it != eit; it++) {

    (*it)->dump(os, newTabn);
  }
  os << " Notify Calls \n";
  for (notifyContainerListType::iterator it = _notifyCalls.begin(),
                                         eit = _notifyCalls.end();
       it != eit; it++) {
    (*it)->dump(os, newTabn);
  }

  os << "\n Suspension CFG";
  os << "\n ###############";
  dumpSusCFG(os);
  os << "\n ###############";
  os << "\n Suspension Automaton";
  os << "\n @@@@@@@@@@@@@@@@";
  dumpSauto(os);
  os << "\n @@@@@@@@@@@@@@@@";
Anirudh Kaushik's avatar
Anirudh Kaushik committed
198
}