joeq.Compiler.Quad
Class BasicBlock

java.lang.Object
  extended by joeq.Compiler.Quad.BasicBlock

public class BasicBlock
extends Object

Represents a basic block in the quad intermediate representation. Basic blocks are single-entry regions, but not necessarily single-exit regions due to the fact that control flow may exit a basic block early due to a run time exception. That is to say, a potential exception point does not end a basic block. Each basic block contains a list of quads, a list of predecessors, a list of successors, and a list of exception handlers. It also has an id number that is unique within its control flow graph, and some flags. You should never create a basic block directly. You should create one via a ControlFlowGraph so that the id number is correct.

Version:
$Id: BasicBlock.java 2465 2006-06-07 23:03:17Z joewhaley $
Author:
John Whaley
See Also:
Quad, ControlFlowGraph, ExceptionHandlerList

Method Summary
 void addAtEnd(ControlFlowGraph ir, Quad c)
           
 void addPredecessor(BasicBlock b)
          Add a predecessor basic block to this basic block.
 void addQuad(int index, Quad q)
          Add a quad to this basic block at the given location.
 void addSuccessor(BasicBlock b)
          Add a successor basic block to this basic block.
 void appendExceptionHandlerList(ExceptionHandlerList list)
          Appends the list of exception handlers to the current list of exception handlers.
 void appendQuad(Quad q)
          Append a quad to the end of this basic block.
 void appendQuadBeforeBranchOrPEI(Quad c)
           
 ListIterator.Quad backwardIterator()
          Returns an iterator over the quads in this basic block in backward order.
 void backwardVisitQuads(QuadVisitor qv)
          Visit all of the quads in this basic block in backward order with the given quad visitor.
 boolean endsInRet()
           
 String fullDump()
          Returns a String describing the name, predecessor, successor, exception handlers, and quads of this basic block.
 List.BasicBlock getExceptionHandlerEntries()
           
 ExceptionHandlerList getExceptionHandlers()
          Returns the list of exception handlers that guard this basic block.
 BasicBlock getFallthroughPredecessor()
          Returns the fallthrough predecessor to this basic block, if it exists.
 BasicBlock getFallthroughSuccessor()
          Returns the fallthrough successor to this basic block, if it exists.
 int getID()
          Returns the unique id number for this basic block.
 Quad getLastQuad()
           
 int getNumberOfPredecessors()
           
 int getNumberOfSuccessors()
           
 List.BasicBlock getPredecessors()
          Returns an list of the predecessors of this basic block.
 Quad getQuad(int i)
           
 int getQuadIndex(Quad q)
           
 List.BasicBlock getSuccessors()
          Returns a list of the successors of this basic block.
 boolean isEntry()
          Returns true if this is the entry basic block.
 boolean isExceptionHandlerEntry()
          Returns true if this basic block has been marked as an exception handler entry point.
 boolean isExit()
          Returns true if this is the exit basic block.
 boolean isJSREntry()
          Returns true if this basic block has been marked as a JSR entry.
 ListIterator.Quad iterator()
          Returns an iterator over the quads in this basic block in forward order.
 void removeAllPredecessors()
           
 void removeAllQuads()
           
 void removeAllSuccessors()
           
 boolean removePredecessor(BasicBlock bb)
           
 void removePredecessor(int i)
           
 boolean removePredecessors(Collection bb)
           
 Quad removeQuad(int i)
           
 boolean removeQuad(Quad q)
           
 boolean removeSuccessor(BasicBlock bb)
           
 void removeSuccessor(int i)
           
 void replaceQuad(int pos, Quad q)
          Replace the quad at position pos.
 void setExceptionHandlerEntry()
          Marks this basic block as an exception handler entry point.
 void setJSREntry()
          Marks this basic block as a JSR entry.
 int size()
          Returns the number of quads in this basic block.
 String toString()
          Returns the name of this basic block.
 void visitQuads(QuadVisitor qv)
          Visit all of the quads in this basic block in forward order with the given quad visitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

isEntry

public boolean isEntry()
Returns true if this is the entry basic block.

Returns:
true if this is the entry basic block.

isExit

public boolean isExit()
Returns true if this is the exit basic block.

Returns:
true if this is the exit basic block.

iterator

public ListIterator.Quad iterator()
Returns an iterator over the quads in this basic block in forward order.

Returns:
an iterator over the quads in this basic block in forward order.

backwardIterator

public ListIterator.Quad backwardIterator()
Returns an iterator over the quads in this basic block in backward order.

Returns:
an iterator over the quads in this basic block in backward order.

visitQuads

public void visitQuads(QuadVisitor qv)
Visit all of the quads in this basic block in forward order with the given quad visitor.

Parameters:
qv - QuadVisitor to visit the quads with.
See Also:
QuadVisitor

backwardVisitQuads

public void backwardVisitQuads(QuadVisitor qv)
Visit all of the quads in this basic block in backward order with the given quad visitor.

Parameters:
qv - QuadVisitor to visit the quads with.
See Also:
QuadVisitor

size

public int size()
Returns the number of quads in this basic block.

Returns:
the number of quads in this basic block.

getQuad

public Quad getQuad(int i)

getLastQuad

public Quad getLastQuad()

getQuadIndex

public int getQuadIndex(Quad q)

removeQuad

public Quad removeQuad(int i)

removeQuad

public boolean removeQuad(Quad q)

removeAllQuads

public void removeAllQuads()

addQuad

public void addQuad(int index,
                    Quad q)
Add a quad to this basic block at the given location. Cannot add quads to the entry or exit basic blocks.

Parameters:
index - the index to add the quad
q - quad to add

appendQuad

public void appendQuad(Quad q)
Append a quad to the end of this basic block. Cannot add quads to the entry or exit basic blocks.

Parameters:
q - quad to add

replaceQuad

public void replaceQuad(int pos,
                        Quad q)
Replace the quad at position pos.


addPredecessor

public void addPredecessor(BasicBlock b)
Add a predecessor basic block to this basic block. Cannot add predecessors to the entry basic block.

Parameters:
b - basic block to add as a predecessor

addSuccessor

public void addSuccessor(BasicBlock b)
Add a successor basic block to this basic block. Cannot add successors to the exit basic block.

Parameters:
b - basic block to add as a successor

removePredecessor

public boolean removePredecessor(BasicBlock bb)

removePredecessor

public void removePredecessor(int i)

removePredecessors

public boolean removePredecessors(Collection bb)

removeSuccessor

public boolean removeSuccessor(BasicBlock bb)

removeSuccessor

public void removeSuccessor(int i)

removeAllPredecessors

public void removeAllPredecessors()

removeAllSuccessors

public void removeAllSuccessors()

getNumberOfSuccessors

public int getNumberOfSuccessors()

getNumberOfPredecessors

public int getNumberOfPredecessors()

getFallthroughSuccessor

public BasicBlock getFallthroughSuccessor()
Returns the fallthrough successor to this basic block, if it exists. If there is none, returns null.

Returns:
the fallthrough successor, or null if there is none.

getFallthroughPredecessor

public BasicBlock getFallthroughPredecessor()
Returns the fallthrough predecessor to this basic block, if it exists. If there is none, returns null.

Returns:
the fallthrough predecessor, or null if there is none.

getSuccessors

public List.BasicBlock getSuccessors()
Returns a list of the successors of this basic block.

Returns:
a list of the successors of this basic block.

getPredecessors

public List.BasicBlock getPredecessors()
Returns an list of the predecessors of this basic block.

Returns:
an iterator of the predecessors of this basic block.

getExceptionHandlers

public ExceptionHandlerList getExceptionHandlers()
Returns the list of exception handlers that guard this basic block.

Returns:
an iterator of the exception handlers that guard this basic block.
See Also:
ExceptionHandlerList

appendExceptionHandlerList

public void appendExceptionHandlerList(ExceptionHandlerList list)
Appends the list of exception handlers to the current list of exception handlers. Doesn't append if it is already there.


getID

public int getID()
Returns the unique id number for this basic block.

Returns:
the unique id number for this basic block.

getExceptionHandlerEntries

public List.BasicBlock getExceptionHandlerEntries()

isExceptionHandlerEntry

public boolean isExceptionHandlerEntry()
Returns true if this basic block has been marked as an exception handler entry point. Returns false otherwise.

Returns:
if this basic block has been marked as an exception handler entry point.

setExceptionHandlerEntry

public void setExceptionHandlerEntry()
Marks this basic block as an exception handler entry point.


isJSREntry

public boolean isJSREntry()
Returns true if this basic block has been marked as a JSR entry. entry point. Returns false otherwise.

Returns:
if this basic block has been marked as a JSR entry.

setJSREntry

public void setJSREntry()
Marks this basic block as a JSR entry.


endsInRet

public boolean endsInRet()

appendQuadBeforeBranchOrPEI

public void appendQuadBeforeBranchOrPEI(Quad c)

toString

public String toString()
Returns the name of this basic block.

Overrides:
toString in class Object
Returns:
the name of this basic block.

addAtEnd

public void addAtEnd(ControlFlowGraph ir,
                     Quad c)

fullDump

public String fullDump()
Returns a String describing the name, predecessor, successor, exception handlers, and quads of this basic block.

Returns:
a verbose string describing this basic block


Copyright © 2001-2008 John Whaley. All Rights Reserved.