Added DLL linkage specification to class declarations to support building
[dyninst.git] / dyninstAPI / h / BPatch_flowGraph.h
1 #ifndef _BPatch_flowGraph_h_
2 #define _BPatch_flowGraph_h_
3
4 #include "BPatch_dll.h"
5 #include "BPatch_Vector.h"
6 #include "BPatch_Set.h"
7 #include "BPatch_basicBlock.h"
8 #include "BPatch_basicBlockLoop.h"
9
10 class BPatch_image;
11
12 /** class which represents the control flow graph of a function
13   * in a executable code. 
14   *
15   * @see BPatch_basicBlock
16   * @see BPatch_basicBlockLoop
17   */
18 class BPATCH_DLL_EXPORT BPatch_flowGraph {
19         friend class BPatch_function;
20         friend class BPatch_basicBlock;
21         friend ostream& operator<<(ostream&,BPatch_flowGraph&);
22
23 private:
24         /** bpatch function for which the CFG is generated */
25         BPatch_function* bpFunction;
26
27         /** set of basic blocks that are entry to the control flow graph*/
28         BPatch_Set<BPatch_basicBlock*> entryBlock;
29
30         /** set of basic blocks that are exit from the control flow graph */
31         BPatch_Set<BPatch_basicBlock*> exitBlock;
32
33         /** set of loops contained in control flow graph */
34         BPatch_Set<BPatch_basicBlockLoop*>* loops;
35         
36         /** set of all basic blocks that control flow graph has */
37         BPatch_Set<BPatch_basicBlock*> allBlocks;
38
39 public:
40         /** destructor for the class */
41         ~BPatch_flowGraph();
42
43         /** returns the set of all basic blocks in the CFG */
44         BPatch_Set<BPatch_basicBlock*>* getAllBasicBlocks()
45                                             { return &allBlocks; };
46
47         /** returns the vector of entry basic blocks to CFG */
48         void getEntryBasicBlock(BPatch_Vector<BPatch_basicBlock*>&);
49
50         /** returns the vector of exit basic blocks to CFG */
51         void getExitBasicBlock(BPatch_Vector<BPatch_basicBlock*>&);
52
53         /** returns the vector of loops in CFG */
54         void getLoops(BPatch_Vector<BPatch_basicBlockLoop*>&);
55
56 private:
57         /** three colors used in depth first search algorithm */
58         static const int WHITE;
59         static const int GRAY;
60         static const int BLACK;
61
62         /** flag that keeps whether dominator info is initialized*/
63         bool isDominatorInfoReady;
64
65         /** flag that keeps whether source block info is initialized*/
66         bool isSourceBlockInfoReady;
67
68         /** constructor of the class */
69         BPatch_flowGraph(BPatch_function*);
70
71         /** constructor for the class */
72         BPatch_flowGraph(BPatch_image*,char*);
73
74         void createBasicBlocks();
75
76         void fillLoopInfo(BPatch_Set<BPatch_basicBlock*>**,BPatch_basicBlock**);
77
78         void dfsVisit(BPatch_basicBlock*,int*,
79                       BPatch_Set<BPatch_basicBlock*>**,
80                       int* which=NULL,BPatch_basicBlock** order=NULL); 
81
82         void findBackEdges(BPatch_Set<BPatch_basicBlock*>**);
83
84         void findAndDeleteUnreachable();
85
86         static void findBBForBackEdge(BPatch_basicBlock*,BPatch_basicBlock*,
87                                       BPatch_Set<BPatch_basicBlock*>&);
88
89         /** creates the source line blocks of all blocks in CFG.
90           * without calling this method line info is not available
91           */
92         void createSourceBlocks();
93
94         /** fills the dominator and immediate-dom information of basic blocks.
95           * without calling this method dominator info is not available
96           */
97         void fillDominatorInfo();
98 };
99
100 #endif /* _BPatch_flowGraph_h_ */