Automata.h 2.87 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
3
4
#ifndef _AUTOMATA_H_
#define _AUTOMATA_H_

#include "clang/AST/DeclCXX.h"
rmrf's avatar
rmrf committed
5
#include "clang/AST/Expr.h"
Anirudh Kaushik's avatar
Anirudh Kaushik committed
6
7
#include "clang/AST/ParentMap.h"
#include "clang/AST/PrettyPrinter.h"
rmrf's avatar
rmrf committed
8
9
10
11
12
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "llvm/Support/raw_ostream.h"
#include <deque>
#include <map>
Anirudh Kaushik's avatar
Anirudh Kaushik committed
13
#include <stdio.h>
rmrf's avatar
rmrf committed
14
#include <vector>
Anirudh Kaushik's avatar
Anirudh Kaushik committed
15
namespace scpar {
rmrf's avatar
rmrf committed
16
17
using namespace clang;
using namespace std;
rmrf's avatar
rmrf committed
18

rmrf's avatar
rmrf committed
19
20
21
22
class Node {
public:
  typedef pair<int, Node *> connectPairType;
  typedef map<int, Node *> connectMapType;
rmrf's avatar
rmrf committed
23

rmrf's avatar
rmrf committed
24
25
  Node();
  Node(int);
rmrf's avatar
rmrf committed
26

rmrf's avatar
rmrf committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  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
Anirudh Kaushik's avatar
Anirudh Kaushik committed
134
#endif