org.quilt.cl
Class BytecodeCollector

java.lang.Object
  |
  +--org.quilt.cl.BytecodeCollector
All Implemented Interfaces:
Visitor

public class BytecodeCollector
extends java.lang.Object
implements Visitor

Collects the bytecode for a method while walking the method control flow graph. Inspired by Quilt 0.5's BytecodeLayout,

Author:
David Dixon-Peugh and the rest of the Quilt development team. However, errors and omissions in this version are entirely due to, Jim Dixon

Constructor Summary
BytecodeCollector()
          No-arg constructor.
 
Method Summary
 void discoverEdge(Edge e)
          Action taken upon first encountering an edge.
 void discoverGraph(Directed g)
          Action taken upon beginning to visit the graph.
 void discoverVertex(Vertex vtx)
          Action taken upon beginning to visit a graph vertex.
 void finishEdge(Edge e)
          Action taken before departing an edge.
 void finishGraph(Directed g)
          Finish the graph.
 void finishVertex(Vertex vtx)
          Action taken before leaving a vertex in the graph.
 org.apache.bcel.generic.CodeExceptionGen[] getCEGs(CatchData[] cd)
          Given an array of exception handler descriptions, return an array of CodeExceptionGen.
 org.apache.bcel.generic.InstructionList getInstructionList()
          Get the instruction list after completing walking the graph, that is, after calling visit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BytecodeCollector

public BytecodeCollector()
No-arg constructor.

Method Detail

discoverGraph

public void discoverGraph(Directed g)
Action taken upon beginning to visit the graph.

Specified by:
discoverGraph in interface Visitor
Parameters:
g - Directed graph to be visited.

discoverVertex

public void discoverVertex(Vertex vtx)
Action taken upon beginning to visit a graph vertex. Unless this is an Entry or Exit vertex, save the starting position in the bytecode to give a offset for edges with this vertex as target. Save the end instruction in the bytecode so that we can insert any connector code their later, in finishVertex. Entry and Exit vertices carry no bytecode and never have a connecting instruction, so they can be ignored when collecting code.

Specified by:
discoverVertex in interface Visitor

discoverEdge

public void discoverEdge(Edge e)
Action taken upon first encountering an edge.

Specified by:
discoverEdge in interface Visitor
Parameters:
e - A FlowControlEdge, a weighted, directed edge.

finishEdge

public void finishEdge(Edge e)
Action taken before departing an edge.

Specified by:
finishEdge in interface Visitor
Parameters:
e - The control flow graph edge.

finishVertex

public void finishVertex(Vertex vtx)
Action taken before leaving a vertex in the graph. The connection instruction, if any, is fixed up by setting its target(s). If the connection instruction is a goto, which might jump into another graph, fixup is delayed until the user asks for the instruction list, when the processing of all graphs has been completed.

Specified by:
finishVertex in interface Visitor
See Also:
CodeVertex.getInstructionList

finishGraph

public void finishGraph(Directed g)
Finish the graph.

Specified by:
finishGraph in interface Visitor
Parameters:
g - The control flow graph - ignored.

getInstructionList

public org.apache.bcel.generic.InstructionList getInstructionList()
Get the instruction list after completing walking the graph, that is, after calling visit.

Returns:
A reference to the bytecode generated by walking the control flow graph.

getCEGs

public org.apache.bcel.generic.CodeExceptionGen[] getCEGs(CatchData[] cd)
Given an array of exception handler descriptions, return an array of CodeExceptionGen. The array may be empty. XXX This method has not been thoroughly tested.

Parameters:
cd - Array of exception handler descriptions in terms of vertices
Returns:
Array of BCEL exception handler structures.


Copyright © 2001-2003 Apache Software Foundation. All Rights Reserved.