Changes to work towards compatability with IBM's version of dyninst.
[dyninst.git] / dyninstAPI / h / BPatch_basicBlock.h
1 #ifndef _BPatch_basicBlock_h_
2 #define _BPatch_basicBlock_h_
3
4 #include "BPatch_dll.h"
5 #include "BPatch_Vector.h"
6 #include "BPatch_Set.h"
7 #include "BPatch_sourceBlock.h" 
8
9 /** class for machine code basic blocks. We assume the user can not 
10   * create basic blocks using its constructor. It is not safe. 
11   * basic blocks are used for reading purposes not for inserting
12   * a new code to the machine executable other than instrumentation code
13   *
14   * @see BPatch_flowGraph
15   * @see BPatch_sourceBlock
16   * @see BPatch_basicBlockLoop
17   */
18
19 class BPATCH_DLL_EXPORT BPatch_basicBlock {
20         friend class BPatch_flowGraph;
21         friend class TarjanDominator;
22
23         friend ostream& operator<<(ostream&,BPatch_basicBlock&);
24
25 private:
26         /** the flow graph that contains this basic block */
27         BPatch_flowGraph *flowGraph;
28
29         /** the ID of the block.It is unique in the CFG.
30           * starts at 0 and goes up to (number of basic blocks - 1)
31           */
32         int blockNumber;
33
34         /** a flag to keep whether a basic block is the entry to CFG or not */
35         bool isEntryBasicBlock;
36
37         /** a flag to keep whether a basic block is the exit from CFG or not */
38         bool isExitBasicBlock;
39
40         /** the start address of the basic blocks. */
41         unsigned long startAddress;
42
43         /** the end address of the basic blocks
44           * address of the last instruction in the block 
45           */
46         unsigned long endAddress;
47
48         /** set of basic blocks that this basicblock dominates immediately*/
49         BPatch_Set<BPatch_basicBlock*>* immediateDominates;
50
51         /** basic block which is the immediate dominator of the basic block */
52         BPatch_basicBlock* immediateDominator;
53
54         /** the set of basic blocks that are predecessors in the CFG */
55         BPatch_Set<BPatch_basicBlock*> sources;
56
57         /** the set of basic blocks that are successors in the CFG */
58         BPatch_Set<BPatch_basicBlock*> targets;
59
60         /** the source block(source lines) that basic block corresponds*/
61         BPatch_sourceBlock* sourceBlock;
62
63 public:
64         /** method that returns the predecessors of the basic block */
65         void getSources(BPatch_Vector<BPatch_basicBlock*>&);
66
67         /** method that returns the successors  of the basic block */
68         void getTargets(BPatch_Vector<BPatch_basicBlock*>&);
69
70         /** returns true if argument is dominated by this basic block */
71         bool dominates(BPatch_basicBlock*);
72
73         /** return the immediate dominator of a basic block */
74         BPatch_basicBlock* getImmediateDominator();
75
76         /** method that returns the basic blocks immediately dominated by 
77           * the basic block 
78           */
79         void getImmediateDominates(BPatch_Vector<BPatch_basicBlock*>&);
80
81         /** method that returns all basic blocks dominated by the basic block */
82         void getAllDominates(BPatch_Set<BPatch_basicBlock*>&);
83         
84         /** returns the source block corresponding to the basic block */
85         BPatch_sourceBlock* getSourceBlock();
86
87         /** returns the block id */
88         int getBlockNumber();
89
90         /** destructor of class */
91         ~BPatch_basicBlock();
92
93         /** return the start and end addresses of the basic block */
94         bool getAddressRange(void*& _startAddress, void*& _endAddress);
95 private:
96
97 // internal use only
98         /** constructor of class */
99         BPatch_basicBlock(BPatch_flowGraph*, int);
100
101         /** constructor of class */
102         BPatch_basicBlock();
103
104         /** method to set the block id */
105         void setBlockNumber(int);
106 };
107
108 #endif /* _BPatch_basicBlock_h_ */