public abstract class BlockGraph extends Object implements DirectedGraph<Block>
Represents the control flow graph of a Body at the basic block level. Each node of the graph is a Block
while the edges represent the flow of control from one basic block to the next.
This is an abstract base class for different variants of BlockGraph, where the variants differ in how they analyze
the control flow between individual units (represented by passing different variants of UnitGraph to the
BlockGraph constructor) and in how they identify block leaders (represented by overriding
BlockGraph's definition of computeLeaders().
| Modifier and Type | Field and Description |
|---|---|
protected List<Block> |
mBlocks |
protected Body |
mBody |
protected List<Block> |
mHeads |
protected List<Block> |
mTails |
protected Chain<Unit> |
mUnits |
| Modifier | Constructor and Description |
|---|---|
protected |
BlockGraph(UnitGraph unitGraph)
Create a
BlockGraph representing at the basic block level the control flow specified, at the
Unit level, by a given UnitGraph. |
| Modifier and Type | Method and Description |
|---|---|
protected Map<Unit,Block> |
buildBlocks(Set<Unit> leaders,
UnitGraph unitGraph)
A utility method that does most of the work of constructing basic blocks, once the set of block leaders has been
determined, and which designates the heads and tails of the graph.
|
protected Set<Unit> |
computeLeaders(UnitGraph unitGraph)
|
List<Block> |
getBlocks()
Returns a list of the Blocks composing this graph.
|
Body |
getBody()
Returns the
Body this BlockGraph is derived from. |
List<Block> |
getHeads()
Returns a list of entry points for this graph.
|
List<Block> |
getPredsOf(Block b)
Returns a list of predecessors for the given node in the graph.
|
List<Block> |
getSuccsOf(Block b)
Returns a list of successors for the given node in the graph.
|
List<Block> |
getTails()
Returns a list of exit points for this graph.
|
Iterator<Block> |
iterator()
Returns an iterator for the nodes in this graph.
|
int |
size()
Returns the node count for this graph.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorprotected Body mBody
protected Set<Unit> computeLeaders(UnitGraph unitGraph)
Utility method for computing the basic block leaders for a Body, given its UnitGraph (i.e., the
instructions which begin new basic blocks).
This implementation designates as basic block leaders :
Unit which has zero predecessors (e.g. the Unit following a return or unconditional
branch) or more than one predecessor (e.g. a merge point).Units which are the target of any branch (even if they have no other predecessors and the branch has no
other successors, which is possible for the targets of unconditional branches or degenerate conditional branches which
both branch and fall through to the same Unit).Unit which has more than one successor (this includes the successors of
Units which may throw an exception that gets caught within the Body, as well the successors of
conditional branches).Unit in any Trap handler. (Strictly speaking, if unitGraph were a
ExceptionalUnitGraph that included only a single unexceptional predecessor for some handler—because
no trapped unit could possibly throw the exception that the handler catches, while the code preceding the handler fell
through to the handler's code—then you could merge the handler into the predecessor's basic block; but such
situations occur only in carefully contrived bytecode.)
protected Map<Unit,Block> buildBlocks(Set<Unit> leaders, UnitGraph unitGraph)
A utility method that does most of the work of constructing basic blocks, once the set of block leaders has been determined, and which designates the heads and tails of the graph.
BlockGraph provides an implementation of buildBlocks() which splits the Units in
unitGraph so that each Unit in the passed set of block leaders is the first unit in a block.
It defines as heads the blocks which begin with Units which are heads in unitGraph, and
defines as tails the blocks which end with Units which are tails in unitGraph. Subclasses
might override this behavior.
leaders - Contains Units which are to be block leaders.unitGraph - Provides information about the predecessors and successors of each Unit in the Body,
for determining the predecessors and successors of each created Block.Map from Units which begin or end a block to the block which contains them.public Body getBody()
Body this BlockGraph is derived from.Body this BlockGraph is derived from.public List<Block> getBlocks()
Blockpublic List<Block> getHeads()
DirectedGraphgetHeads in interface DirectedGraph<Block>public List<Block> getTails()
DirectedGraphgetTails in interface DirectedGraph<Block>public List<Block> getPredsOf(Block b)
DirectedGraphgetPredsOf in interface DirectedGraph<Block>public List<Block> getSuccsOf(Block b)
DirectedGraphgetSuccsOf in interface DirectedGraph<Block>public int size()
DirectedGraphsize in interface DirectedGraph<Block>public Iterator<Block> iterator()
DirectedGraphCopyright © 2020 Soot OSS. All rights reserved.