Commit 45775cd8 authored by rmrf's avatar rmrf

Formatting should be consistent

parent 97dfc63f
This diff is collapsed.
#ifndef _AUTOMATA_H_
#define _AUTOMATA_H_
#include <vector>
#include <deque>
#include <map>
#include "clang/AST/DeclCXX.h"
#include "llvm/Support/raw_ostream.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/Expr.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "llvm/Support/raw_ostream.h"
#include <deque>
#include <map>
#include <stdio.h>
#include <vector>
namespace scpar {
using namespace clang;
using namespace std;
class Node {
public:
typedef pair < int, Node * >connectPairType;
typedef map < int, Node * >connectMapType;
using namespace clang;
using namespace std;
Node ( );
Node (int );
class Node {
public:
typedef pair<int, Node *> connectPairType;
typedef map<int, Node *> connectMapType;
void addSuccessor (Node * );
void addPredecessor (Node * );
Node();
Node(int);
vector < int >getSuccessors (int );
vector < int >getPredecessors (int );
int getId( );
void dump (raw_ostream &, int );
protected:
int _id;
connectMapType _preds;
connectMapType _succs;
};
class Edge {
public:
typedef pair < unsigned int, unsigned int >timePairType;
typedef vector < timePairType > timeAdvanceVectorType;
Edge (Node *, Node * );
Edge (Node *, Node *, int );
void updateSuspensionTime(timePairType );
int getId();
int getToId();
int getFromId();
timeAdvanceVectorType getTimeAdvanceVector();
void dump (raw_ostream &, int);
protected:
int _id;
timeAdvanceVectorType _timeAdvanceVector;
Node *_from;
Node *_to;
};
class Graph {
public:
typedef vector < int >nodeIDVector;
typedef vector < int >edgeIDVector;
typedef vector < Node * >nodeVector;
typedef vector < Edge * >edgeVector;
typedef map < int, Node * >nodeMapType;
typedef pair < int, Node * >nodePairType;
typedef map < int, Edge * >edgeMapType;
typedef pair < int, Edge * >edgePairType;
typedef pair < int, int >twoNodePairType;
typedef pair < twoNodePairType, Edge * >adjPairType;
typedef map < twoNodePairType, Edge * >adjMapType;
typedef pair < int, vector < Edge * > >adjEdgesPairType;
typedef map < int, vector < Edge * > >adjEdgesMapType;
Graph();
~Graph();
Node *addNode();
Node *addNode(int );
Edge *addEdge(Node *, Node * );
Edge *addEdge(int, int );
int getEdgeID(Edge * );
int getEdgeID (Node *, Node * );
int getEdgeID (int, int );
int getNodeID (Node * );
Edge *getEdge (Node *, Node * );
Edge *getEdge (int, int );
Node *getNode (int );
vector < Edge * >getEdgesFromSource (int );
vector < Edge * >getEdgesFromSource (Node * );
vector < Edge * >getEdgesFromDest (int );
vector < Edge * >getEdgesFromDest (Node * );
adjMapType returnAdjList();
nodeIDVector returnNodeIDs();
edgeIDVector returnEdgeIDs();
nodeVector returnNodes();
edgeVector returnEdges();
edgeVector returnEdgeVector();
nodeVector returnNodeVector();
void dump (raw_ostream &, int tabn = 0);
void dumpSauto (raw_ostream &, int tabn = 0);
protected:
adjMapType _adjList;
nodeMapType _nodeMap;
edgeMapType _edgeMap;
adjEdgesMapType _adjEdges;
int _nNodes;
int _nEdges;
nodeIDVector _nodeIDVector;
edgeIDVector _edgeIDVector;
nodeVector _nodeVector;
edgeVector _edgeVector;
};
}
void addSuccessor(Node *);
void addPredecessor(Node *);
vector<int> getSuccessors(int);
vector<int> getPredecessors(int);
int getId();
void dump(raw_ostream &, int);
protected:
int _id;
connectMapType _preds;
connectMapType _succs;
};
class Edge {
public:
typedef pair<unsigned int, unsigned int> timePairType;
typedef vector<timePairType> timeAdvanceVectorType;
Edge(Node *, Node *);
Edge(Node *, Node *, int);
void updateSuspensionTime(timePairType);
int getId();
int getToId();
int getFromId();
timeAdvanceVectorType getTimeAdvanceVector();
void dump(raw_ostream &, int);
protected:
int _id;
timeAdvanceVectorType _timeAdvanceVector;
Node *_from;
Node *_to;
};
class Graph {
public:
typedef vector<int> nodeIDVector;
typedef vector<int> edgeIDVector;
typedef vector<Node *> nodeVector;
typedef vector<Edge *> edgeVector;
typedef map<int, Node *> nodeMapType;
typedef pair<int, Node *> nodePairType;
typedef map<int, Edge *> edgeMapType;
typedef pair<int, Edge *> edgePairType;
typedef pair<int, int> twoNodePairType;
typedef pair<twoNodePairType, Edge *> adjPairType;
typedef map<twoNodePairType, Edge *> adjMapType;
typedef pair<int, vector<Edge *>> adjEdgesPairType;
typedef map<int, vector<Edge *>> adjEdgesMapType;
Graph();
~Graph();
Node *addNode();
Node *addNode(int);
Edge *addEdge(Node *, Node *);
Edge *addEdge(int, int);
int getEdgeID(Edge *);
int getEdgeID(Node *, Node *);
int getEdgeID(int, int);
int getNodeID(Node *);
Edge *getEdge(Node *, Node *);
Edge *getEdge(int, int);
Node *getNode(int);
vector<Edge *> getEdgesFromSource(int);
vector<Edge *> getEdgesFromSource(Node *);
vector<Edge *> getEdgesFromDest(int);
vector<Edge *> getEdgesFromDest(Node *);
adjMapType returnAdjList();
nodeIDVector returnNodeIDs();
edgeIDVector returnEdgeIDs();
nodeVector returnNodes();
edgeVector returnEdges();
edgeVector returnEdgeVector();
nodeVector returnNodeVector();
void dump(raw_ostream &, int tabn = 0);
void dumpSauto(raw_ostream &, int tabn = 0);
protected:
adjMapType _adjList;
nodeMapType _nodeMap;
edgeMapType _edgeMap;
adjEdgesMapType _adjEdges;
int _nNodes;
int _nEdges;
nodeIDVector _nodeIDVector;
edgeIDVector _edgeIDVector;
nodeVector _nodeVector;
edgeVector _edgeVector;
};
} // namespace scpar
#endif
......@@ -3,223 +3,196 @@
using namespace scpar;
EntryFunctionContainer::~EntryFunctionContainer ()
{
// DO NOT free anything.
EntryFunctionContainer::~EntryFunctionContainer() {
// DO NOT free anything.
}
EntryFunctionContainer::EntryFunctionContainer () :
_entryName ("NONE"),
_procType (PROCESS_TYPE::NONE),
_entryMethodDecl (nullptr) {
EntryFunctionContainer::EntryFunctionContainer()
: _entryName("NONE"), _procType(PROCESS_TYPE::NONE),
_entryMethodDecl(nullptr) {}
}
EntryFunctionContainer::EntryFunctionContainer (string n, PROCESS_TYPE p, CXXMethodDecl * d, Stmt * s)
:_entryName (n), _procType (p), _entryMethodDecl (d) {
}
EntryFunctionContainer::EntryFunctionContainer(string n, PROCESS_TYPE p,
CXXMethodDecl *d, Stmt *s)
: _entryName(n), _procType(p), _entryMethodDecl(d) {}
EntryFunctionContainer::EntryFunctionContainer (const EntryFunctionContainer & from) {
_entryName = from._entryName;
_procType = from._procType;
_entryMethodDecl = from._entryMethodDecl;
EntryFunctionContainer::EntryFunctionContainer(
const EntryFunctionContainer &from) {
_entryName = from._entryName;
_procType = from._procType;
_entryMethodDecl = from._entryMethodDecl;
}
///////////////////////////////////////////////////////////////////////////////////////////////
string EntryFunctionContainer::getName ()
{
return _entryName;
}
string EntryFunctionContainer::getName() { return _entryName; }
FindSensitivity::senseMapType EntryFunctionContainer::getSenseMap() {
return _senseMap;
return _senseMap;
}
CXXMethodDecl* EntryFunctionContainer::getEntryMethod ()
{
return _entryMethodDecl;
CXXMethodDecl *EntryFunctionContainer::getEntryMethod() {
return _entryMethodDecl;
}
EntryFunctionContainer::waitContainerListType EntryFunctionContainer::getWaitCalls ()
{
return _waitCalls;
EntryFunctionContainer::waitContainerListType
EntryFunctionContainer::getWaitCalls() {
return _waitCalls;
}
EntryFunctionContainer::notifyContainerListType EntryFunctionContainer::getNotifyCalls() {
return _notifyCalls;
EntryFunctionContainer::notifyContainerListType
EntryFunctionContainer::getNotifyCalls() {
return _notifyCalls;
}
PROCESS_TYPE EntryFunctionContainer::getProcessType ()
{
return _procType;
}
PROCESS_TYPE EntryFunctionContainer::getProcessType() { return _procType; }
SuspensionAutomata::susCFGVectorType EntryFunctionContainer::getSusCFG() {
return _susCFG;
//return _instanceSusCFGMap[numInstance];
// return _instanceSusCFGMap[numInstance];
}
SuspensionAutomata::transitionVectorType EntryFunctionContainer::getSusAuto() {
return _susAuto;
//return _instanceSautoMap[numInstance];
return _susAuto;
// return _instanceSautoMap[numInstance];
}
///////////////////////////////////////////////////////////////////////////////////////////////
void EntryFunctionContainer::setName (string n)
{
_entryName = n;
}
void EntryFunctionContainer::setName(string n) { _entryName = n; }
void EntryFunctionContainer::setProcessType (PROCESS_TYPE p)
{
_procType = p;
}
void EntryFunctionContainer::setProcessType(PROCESS_TYPE p) { _procType = p; }
void EntryFunctionContainer::setEntryMethod (CXXMethodDecl * d)
{
_entryMethodDecl = d;
void EntryFunctionContainer::setEntryMethod(CXXMethodDecl *d) {
_entryMethodDecl = d;
}
void EntryFunctionContainer::addSensitivityInfo(FindSensitivity &s) {
_senseMap = s.getSenseMap();
_senseMap = s.getSenseMap();
}
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();
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();
}
void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) {
_susCFG = s.getSusCFG();
_susAuto = s.getSauto();
_susCFG = s.getSusCFG();
_susAuto = s.getSauto();
/*
if (_instanceSusCFGMap.find(numInstance) == _instanceSusCFGMap.end() && _instanceSautoMap.find(numInstance) == _instanceSautoMap.end()) {
_instanceSusCFGMap.insert(instanceSusCFGPairType(numInstance, s.getSusCFG()));
_instanceSautoMap.insert(instanceSautoPairType(numInstance, s.getSauto()));
}
*/
/*
if (_instanceSusCFGMap.find(numInstance) == _instanceSusCFGMap.end() &&
_instanceSautoMap.find(numInstance) == _instanceSautoMap.end()) {
_instanceSusCFGMap.insert(instanceSusCFGPairType(numInstance,
s.getSusCFG())); _instanceSautoMap.insert(instanceSautoPairType(numInstance,
s.getSauto()));
}
*/
}
void EntryFunctionContainer::addNotifys( FindNotify& f) {
void EntryFunctionContainer::addNotifys(FindNotify &f) {
FindNotify::NotifyCallListType ncalls = f.getNotifyCallList();
for (FindNotify::NotifyCallListType::iterator it = ncalls.begin(), eit = ncalls.end();
it != eit;
it++) {
for (FindNotify::NotifyCallListType::iterator it = ncalls.begin(),
eit = ncalls.end();
it != eit; it++) {
// 'it' points to CXXMembercallExpr type.
NotifyContainer* nc = new NotifyContainer(f.getEntryMethod(), *it);
NotifyContainer *nc = new NotifyContainer(f.getEntryMethod(), *it);
_notifyCalls.push_back(nc);
}
//_processWaitEventMap = f.getProcessWaitEventMap();
//_processWaitEventMap = f.getProcessWaitEventMap();
}
///////////////////////////////////////////////////////////////////////////////////////////////
void EntryFunctionContainer::dumpSusCFG(raw_ostream & os)
{
void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) {
os << "\n#############################################";
os << "\n#############################################";
SuspensionAutomata::susCFGVectorType susCFGVector = _susCFG;
for (unsigned int i = 0; i < susCFGVector.size(); i++) {
os << "\n Block ID : " << susCFGVector.at(i)->getBlockID();
os << "\n Block ID : " << susCFGVector.at(i)->getBlockID();
os << "\n Is Wait Block : " << susCFGVector.at(i)->isWaitBlock();
if (susCFGVector.at(i)->getParentBlockID()) {
os << "\n Parent ID : " << susCFGVector.at(i)->getParentBlockID();
SusCFG *parentBlock = susCFGVector.at(i)->getParentSusCFGBlock();
os << "\n Parent ID : " << susCFGVector.at(i)->getParentBlockID();
SusCFG *parentBlock = susCFGVector.at(i)->getParentSusCFGBlock();
os << "\n Parent Block ID : " << parentBlock->getBlockID();
os << "\n Parent Block ID : " << parentBlock->getBlockID();
os << "\n Size of Children : " << parentBlock->getChildBlockList().size();
}
vector < SusCFG * >predBlocks = susCFGVector.at(i)->getPredBlocks();
vector < SusCFG * >succBlocks = susCFGVector.at(i)->getSuccBlocks();
vector<SusCFG *> predBlocks = susCFGVector.at(i)->getPredBlocks();
vector<SusCFG *> succBlocks = susCFGVector.at(i)->getSuccBlocks();
os << "\n Predecessor Blocks : ";
for (unsigned int j = 0; j < predBlocks.size(); j++) {
if (predBlocks.at(j)) {
os << predBlocks.at(j)->getBlockID() << " ";
if (predBlocks.at(j)) {
os << predBlocks.at(j)->getBlockID() << " ";
}
}
os << "\n Successor Blocks : ";
for (unsigned int j = 0; j < succBlocks.size(); j++) {
if (succBlocks.at(j)) {
os << succBlocks.at(j)->getBlockID() << " ";
if (succBlocks.at(j)) {
os << succBlocks.at(j)->getBlockID() << " ";
}
}
}
}
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 @@@@@@@@@@@@@@@@";
}
}
}
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";