Class BlockGraph
- java.lang.Object
-
- soot.toolkits.graph.BlockGraph
-
- All Implemented Interfaces:
Iterable<Block>,DirectedBodyGraph<Block>,DirectedGraph<Block>
- Direct Known Subclasses:
ArrayRefBlockGraph,BriefBlockGraph,ClassicCompleteBlockGraph,EnhancedBlockGraph,ExceptionalBlockGraph,ZonedBlockGraph
public abstract class BlockGraph extends Object implements DirectedBodyGraph<Block>
Represents the control flow graph of a
Bodyat the basic block level. Each node of the graph is aBlockwhile 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 ofUnitGraphto theBlockGraphconstructor) and in how they identify block leaders (represented by overridingBlockGraph's definition ofcomputeLeaders().
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBlockGraph(UnitGraph unitGraph)Create aBlockGraphrepresenting at the basic block level the control flow specified, at theUnitlevel, by a givenUnitGraph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.BodygetBody()Returns theBodythisBlockGraphis 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.intsize()Returns the node count for this graph.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
computeLeaders
protected Set<Unit> computeLeaders(UnitGraph unitGraph)
Utility method for computing the basic block leaders for a
Body, given itsUnitGraph(i.e., the instructions which begin new basic blocks).This implementation designates as basic block leaders :
- Any
Unitwhich has zero predecessors (e.g. theUnitfollowing 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 sameUnit).- All successors of any
Unitwhich has more than one successor (this includes the successors ofUnits which may throw an exception that gets caught within theBody, as well the successors of conditional branches). - The first
Unitin anyTraphandler. (Strictly speaking, ifunitGraphwere aExceptionalUnitGraphthat 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.)
- Any
-
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.
BlockGraphprovides an implementation ofbuildBlocks()which splits theUnits inunitGraphso that eachUnitin the passed set of block leaders is the first unit in a block. It defines as heads the blocks which begin withUnits which are heads inunitGraph, and defines as tails the blocks which end withUnits which are tails inunitGraph. Subclasses might override this behavior.- Parameters:
leaders- ContainsUnits which are to be block leaders.unitGraph- Provides information about the predecessors and successors of eachUnitin theBody, for determining the predecessors and successors of each createdBlock.- Returns:
- a
MapfromUnits which begin or end a block to the block which contains them.
-
getBody
public Body getBody()
Returns theBodythisBlockGraphis derived from.- Specified by:
getBodyin interfaceDirectedBodyGraph<Block>- Returns:
- The
BodythisBlockGraphis 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
-
getHeads
public List<Block> getHeads()
Description copied from interface:DirectedGraphReturns a list of entry points for this graph.- Specified by:
getHeadsin interfaceDirectedGraph<Block>
-
getTails
public List<Block> getTails()
Description copied from interface:DirectedGraphReturns a list of exit points for this graph.- Specified by:
getTailsin interfaceDirectedGraph<Block>
-
getPredsOf
public List<Block> getPredsOf(Block b)
Description copied from interface:DirectedGraphReturns a list of predecessors for the given node in the graph.- Specified by:
getPredsOfin interfaceDirectedGraph<Block>
-
getSuccsOf
public List<Block> getSuccsOf(Block b)
Description copied from interface:DirectedGraphReturns a list of successors for the given node in the graph.- Specified by:
getSuccsOfin interfaceDirectedGraph<Block>
-
size
public int size()
Description copied from interface:DirectedGraphReturns the node count for this graph.- Specified by:
sizein interfaceDirectedGraph<Block>
-
iterator
public Iterator<Block> iterator()
Description copied from interface:DirectedGraphReturns an iterator for the nodes in this graph. No specific ordering of the nodes is guaranteed.
-
-