soot.toolkits.graph
Class BlockGraph

java.lang.Object
  extended by soot.toolkits.graph.BlockGraph
All Implemented Interfaces:
Iterable<Block>, DirectedGraph<Block>
Direct Known Subclasses:
ArrayRefBlockGraph, BriefBlockGraph, ClassicCompleteBlockGraph, EnhancedBlockGraph, ExceptionalBlockGraph, ZonedBlockGraph

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().


Field Summary
protected  List<Block> mBlocks
           
protected  Body mBody
           
protected  List<Block> mHeads
           
protected  List<Block> mTails
           
protected  Chain<Unit> mUnits
           
 
Constructor Summary
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.
 
Method Summary
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)
          Utility method for computing the basic block leaders for a Body, given its UnitGraph (i.e., the instructions which begin new basic blocks).
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mBody

protected Body mBody

mUnits

protected Chain<Unit> mUnits

mBlocks

protected List<Block> mBlocks

mHeads

protected List<Block> mHeads

mTails

protected List<Block> mTails
Constructor Detail

BlockGraph

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.

Parameters:
unitGraph - A representation of the control flow at the level of individual Units.
Method Detail

computeLeaders

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 :

Parameters:
unitGraph - is the Unit-level CFG which is to be split into basic blocks.
Returns:
the Set of Units in unitGraph which are block leaders.

buildBlocks

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.

Parameters:
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.
Returns:
a Map from Units which begin or end a block to the block which contains them.

getBody

public Body getBody()
Returns the Body this BlockGraph is derived from.

Returns:
The Body this BlockGraph is derived from.

getBlocks

public List<Block> getBlocks()
Returns a list of the Blocks composing this graph.

Returns:
A list of the blocks composing this graph in the same order as they partition underlying Body instance's unit chain.
See Also:
Block

toString

public String toString()
Overrides:
toString in class Object

getHeads

public List<Block> getHeads()
Description copied from interface: DirectedGraph
Returns a list of entry points for this graph.

Specified by:
getHeads in interface DirectedGraph<Block>

getTails

public List<Block> getTails()
Description copied from interface: DirectedGraph
Returns a list of exit points for this graph.

Specified by:
getTails in interface DirectedGraph<Block>

getPredsOf

public List<Block> getPredsOf(Block b)
Description copied from interface: DirectedGraph
Returns a list of predecessors for the given node in the graph.

Specified by:
getPredsOf in interface DirectedGraph<Block>

getSuccsOf

public List<Block> getSuccsOf(Block b)
Description copied from interface: DirectedGraph
Returns a list of successors for the given node in the graph.

Specified by:
getSuccsOf in interface DirectedGraph<Block>

size

public int size()
Description copied from interface: DirectedGraph
Returns the node count for this graph.

Specified by:
size in interface DirectedGraph<Block>

iterator

public Iterator<Block> iterator()
Description copied from interface: DirectedGraph
Returns an iterator for the nodes in this graph. No specific ordering of the nodes is guaranteed.

Specified by:
iterator in interface Iterable<Block>
Specified by:
iterator in interface DirectedGraph<Block>