1 #ifndef _BPatch_basicBlock_h_
2 #define _BPatch_basicBlock_h_
4 #include "BPatch_dll.h"
5 #include "BPatch_Vector.h"
6 #include "BPatch_Set.h"
7 #include "BPatch_sourceBlock.h"
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
14 * @see BPatch_flowGraph
15 * @see BPatch_sourceBlock
16 * @see BPatch_basicBlockLoop
19 class BPATCH_DLL_EXPORT BPatch_basicBlock {
20 friend class BPatch_flowGraph;
21 friend class TarjanDominator;
23 friend ostream& operator<<(ostream&,BPatch_basicBlock&);
26 /** the flow graph that contains this basic block */
27 BPatch_flowGraph *flowGraph;
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)
34 /** a flag to keep whether a basic block is the entry to CFG or not */
35 bool isEntryBasicBlock;
37 /** a flag to keep whether a basic block is the exit from CFG or not */
38 bool isExitBasicBlock;
40 /** the start address of the basic blocks. */
41 unsigned long startAddress;
43 /** the end address of the basic blocks
44 * address of the last instruction in the block
46 unsigned long endAddress;
48 /** set of basic blocks that this basicblock dominates immediately*/
49 BPatch_Set<BPatch_basicBlock*>* immediateDominates;
51 /** basic block which is the immediate dominator of the basic block */
52 BPatch_basicBlock* immediateDominator;
54 /** the set of basic blocks that are predecessors in the CFG */
55 BPatch_Set<BPatch_basicBlock*> sources;
57 /** the set of basic blocks that are successors in the CFG */
58 BPatch_Set<BPatch_basicBlock*> targets;
60 /** the source block(source lines) that basic block corresponds*/
61 BPatch_sourceBlock* sourceBlock;
64 /** method that returns the predecessors of the basic block */
65 void getSources(BPatch_Vector<BPatch_basicBlock*>&);
67 /** method that returns the successors of the basic block */
68 void getTargets(BPatch_Vector<BPatch_basicBlock*>&);
70 /** returns true if argument is dominated by this basic block */
71 bool dominates(BPatch_basicBlock*);
73 /** return the immediate dominator of a basic block */
74 BPatch_basicBlock* getImmediateDominator();
76 /** method that returns the basic blocks immediately dominated by
79 void getImmediateDominates(BPatch_Vector<BPatch_basicBlock*>&);
81 /** method that returns all basic blocks dominated by the basic block */
82 void getAllDominates(BPatch_Set<BPatch_basicBlock*>&);
84 /** returns the source block corresponding to the basic block */
85 BPatch_sourceBlock* getSourceBlock();
87 /** returns the block id */
90 /** destructor of class */
93 /** return the start and end addresses of the basic block */
94 bool getAddressRange(void*& _startAddress, void*& _endAddress);
98 /** constructor of class */
99 BPatch_basicBlock(BPatch_flowGraph*, int);
101 /** constructor of class */
104 /** method to set the block id */
105 void setBlockNumber(int);
108 #endif /* _BPatch_basicBlock_h_ */