Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Compil3r.Quad
Class BasicBlock  view BasicBlock download BasicBlock.java

java.lang.Object
  extended byCompil3r.Quad.BasicBlock

public class BasicBlock
extends java.lang.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,v 1.17 2003/05/28 03:07:45 joewhaley Exp $

Field Summary
private static int ENDS_IN_RET
          This basic block ends in a 'ret'.
private static int EXCEPTION_HANDLER_ENTRY
          Exception handler entry point.
private  ExceptionHandlerList exception_handler_list
          List of exception handlers for this basic block.
private  int flags
          Flags for this basic block.
private  int id_number
          Unique id number for this basic block.
private  java.util.List instructions
          List of instructions.
private static int JSR_ENTRY
          JSR subroutine entry point.
private  java.util.List predecessors
          List of predecessor basic blocks.
private  java.util.List successors
          List of successor basic blocks.
 
Constructor Summary
private BasicBlock()
          Private constructor for the entry node.
private BasicBlock(int numOfExits)
          Private constructor for the exit node.
private BasicBlock(int id, int numOfPredecessors, int numOfSuccessors, int numOfInstructions, ExceptionHandlerList ehs)
          Private constructor for internal nodes.
 
Method Summary
(package private)  void addExceptionHandler_first(ExceptionHandlerList eh)
           
(package private)  ExceptionHandlerList addExceptionHandler(ExceptionHandlerList eh)
           
 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.
 Util.Templates.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.
(package private) static BasicBlock createBasicBlock(int id, int numOfPredecessors, int numOfSuccessors, int numOfInstructions)
          Create new basic block with no exception handlers.
(package private) static BasicBlock createBasicBlock(int id, int numOfPredecessors, int numOfSuccessors, int numOfInstructions, ExceptionHandlerList ehs)
          Create new basic block with the given exception handlers.
(package private) static BasicBlock createEndNode(int numOfPredecessors)
          Creates new exit node
(package private) static BasicBlock createStartNode()
          Creates new entry node.
 boolean endsInRet()
           
 java.lang.String fullDump()
          Returns a String describing the name, predecessor, successor, exception handlers, and quads of this basic block.
 Util.Templates.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()
           
 Util.Templates.List.BasicBlock getPredecessors()
          Returns an list of the predecessors of this basic block.
 Quad getQuad(int i)
           
 int getQuadIndex(Quad q)
           
 Util.Templates.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.
 Util.Templates.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)
           
 Quad removeQuad(int i)
           
 boolean removeQuad(Quad q)
           
 boolean removeSuccessor(BasicBlock bb)
           
 void removeSuccessor(int i)
           
 void setExceptionHandlerEntry()
          Marks this basic block as an exception handler entry point.
(package private)  void setExceptionHandlerList(ExceptionHandlerList ehl)
           
 void setJSREntry()
          Marks this basic block as a JSR entry.
 int size()
          Returns the number of quads in this basic block.
 java.lang.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
 

Field Detail

id_number

private int id_number
Unique id number for this basic block.


instructions

private final java.util.List instructions
List of instructions.


successors

private final java.util.List successors
List of successor basic blocks.


predecessors

private final java.util.List predecessors
List of predecessor basic blocks.


exception_handler_list

private ExceptionHandlerList exception_handler_list
List of exception handlers for this basic block.


flags

private int flags
Flags for this basic block.


EXCEPTION_HANDLER_ENTRY

private static final int EXCEPTION_HANDLER_ENTRY
Exception handler entry point.

See Also:
Constant Field Values

JSR_ENTRY

private static final int JSR_ENTRY
JSR subroutine entry point.

See Also:
Constant Field Values

ENDS_IN_RET

private static final int ENDS_IN_RET
This basic block ends in a 'ret'.

See Also:
Constant Field Values
Constructor Detail

BasicBlock

private BasicBlock()
Private constructor for the entry node.


BasicBlock

private BasicBlock(int numOfExits)
Private constructor for the exit node.


BasicBlock

private BasicBlock(int id,
                   int numOfPredecessors,
                   int numOfSuccessors,
                   int numOfInstructions,
                   ExceptionHandlerList ehs)
Private constructor for internal nodes.

Method Detail

createStartNode

static BasicBlock createStartNode()
Creates new entry node. Only to be called by ControlFlowGraph.


createEndNode

static BasicBlock createEndNode(int numOfPredecessors)
Creates new exit node


createBasicBlock

static BasicBlock createBasicBlock(int id,
                                   int numOfPredecessors,
                                   int numOfSuccessors,
                                   int numOfInstructions)
Create new basic block with no exception handlers. Only to be called by ControlFlowGraph.


createBasicBlock

static BasicBlock createBasicBlock(int id,
                                   int numOfPredecessors,
                                   int numOfSuccessors,
                                   int numOfInstructions,
                                   ExceptionHandlerList ehs)
Create new basic block with the given exception handlers. Only to be called by ControlFlowGraph.


isEntry

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


isExit

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


iterator

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


backwardIterator

public Util.Templates.ListIterator.Quad backwardIterator()
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.


backwardVisitQuads

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


size

public int size()
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.


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.


addPredecessor

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


addSuccessor

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


removePredecessor

public boolean removePredecessor(BasicBlock bb)

removePredecessor

public void removePredecessor(int i)

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.


getFallthroughPredecessor

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


getSuccessors

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


getPredecessors

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


addExceptionHandler_first

void addExceptionHandler_first(ExceptionHandlerList eh)

addExceptionHandler

ExceptionHandlerList addExceptionHandler(ExceptionHandlerList eh)

setExceptionHandlerList

void setExceptionHandlerList(ExceptionHandlerList ehl)

getExceptionHandlers

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


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.


getExceptionHandlerEntries

public Util.Templates.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.


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.


setJSREntry

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


endsInRet

public boolean endsInRet()

toString

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


fullDump

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