ic.cfg
Class ControlFlowGraph

java.lang.Object
  extended by ic.cfg.ControlFlowGraph
All Implemented Interfaces:
Iterable<BasicBlock>

public class ControlFlowGraph
extends Object
implements Iterable<BasicBlock>

A ControlFlowGraph manages a collection of Basic Blocks and provides some basic operations on them.

Be sure to inialize the enter and exit blocks with the blocks you are using for those nodes. Those blocks should not contain real instructions from the method being analyzed. Instead, create two extra blocks with some special instruction values to indicate that they are the enter and exit blocks. See the DataFlowAnalysis documentation for more details.

This class implements the Iterable interface, so you can iterate over the blocks in a graph as follows:

   ControlFlowGraph cfg = ...;
   for (BasicBlock b :  cfg) {
     ...
   }
 


Field Summary
protected  Vector<BasicBlock> blocks
           
protected  BasicBlock enter
           
protected  BasicBlock exit
           
 
Constructor Summary
ControlFlowGraph()
           
 
Method Summary
 void dotToFile(String fileName)
          Writes a dot graph description to the file named fileName.
 BasicBlock getEnter()
          Return the block representing enter.
 BasicBlock getExit()
          Return the block representing exit.
 Iterator<BasicBlock> iterator()
          Returns an iterator for the blocks.
protected  BasicBlock newBlock(TInstr instr)
          Allocate a new block that holds the given instruction.
 void setEnter(BasicBlock enter)
          Set the block representing enter.
 void setExit(BasicBlock exit)
          Set the block representing exit.
 String toString()
          Return a string rep for a CFG.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

blocks

protected final Vector<BasicBlock> blocks

enter

protected BasicBlock enter

exit

protected BasicBlock exit
Constructor Detail

ControlFlowGraph

public ControlFlowGraph()
Method Detail

newBlock

protected BasicBlock newBlock(TInstr instr)
Allocate a new block that holds the given instruction. A unique number will be assigned to that block. Returns the block.


getEnter

public BasicBlock getEnter()
Return the block representing enter.


getExit

public BasicBlock getExit()
Return the block representing exit.


setEnter

public void setEnter(BasicBlock enter)
Set the block representing enter.


setExit

public void setExit(BasicBlock exit)
Set the block representing exit.


iterator

public Iterator<BasicBlock> iterator()
Returns an iterator for the blocks. The iteration order is the order in which blocks were allocated.

Specified by:
iterator in interface Iterable<BasicBlock>

toString

public String toString()
Return a string rep for a CFG.

Overrides:
toString in class Object

dotToFile

public void dotToFile(String fileName)
Writes a dot graph description to the file named fileName. You can visually examine the graph as follows. After generating graph.dot, execute the following on the command line:
   dot -Tpdf < graph.dot > graph.pdf
 
Some escape characters and punctuation may confuse dot, in which case you will need to add additional escaping commands, as I have done for the few obvious special cases (", \n, etc).