harpoon.IR.Quads
Class Quad

java.lang.Object
  extended by harpoon.IR.Quads.Quad
All Implemented Interfaces:
HCodeElement, CFGraphable<Quad,Edge>, UseDefable, Graph.Node<Quad,Edge>, Serializable, Cloneable, Comparable<Quad>
Direct Known Subclasses:
AGET, ALENGTH, ANEW, ARRAYINIT, ASET, COMPONENTOF, CONST, DEBUG, FOOTER, GET, HANDLER, HEADER, INSTANCEOF, LowQuad, METHOD, MONITORENTER, MONITOREXIT, MOVE, NEW, NOP, OPER, PHI, RETURN, SET, SIGMA, THROW

public abstract class Quad
extends Object
implements HCodeElement, UseDefable, CFGraphable<Quad,Edge>, Cloneable, Comparable<Quad>, Serializable

Quad is the base class for the quadruple representation.

Version:
$Id: Quad.java,v 1.15 2005/09/28 18:23:24 salcianu Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Serialized Form

Field Summary
static ArrayFactory<Quad> arrayFactory
          Array factory: returns Quad[]s
 
Constructor Summary
protected Quad(QuadFactory qf, HCodeElement source)
          Initializes a quad with exactly one input edge and exactly one output edge.
protected Quad(QuadFactory qf, HCodeElement source, int prev_arity, int next_arity)
          Initializes a quad with prev_arity input edges and next_arity output edges.
 
Method Summary
abstract
<T> T
accept(QuadValueVisitor<T> v)
           
abstract  void accept(QuadVisitor v)
          Accept a visitor.
static Edge addEdge(Quad from, int from_index, Quad to, int to_index)
          Adds an edge between two Quads.
static void addEdges(Quad[] quadlist)
          Add edges between a string of Quads.
 void addHandlers(HandlerSet handlers)
          Add this quad to the given handler sets.
 Quad clone()
           
 Quad clone(QuadFactory qf, CloningTempMap tm)
          Clone a quad into a new quad factory, renaming all of the temps according to tm (which ought to ensure that all the new temps belong to the TempFactory of the new QuadFactory).
static Quad clone(QuadFactory qf, Quad header)
          Create a new copy of a string of Quads starting at the given header using QuadFactory.
 int compareTo(Quad o)
           
 Temp[] def()
          Return all the Temps defined by this Quad.
 Collection<Temp> defC()
          Returns a Collection of all the Temps defined in this HCodeElement.
 List<Edge> edgeC()
          Returns a List of all the edges to and from this HCodeElement.
 Edge[] edges()
          Returns an array of all the edges to and from this CFGraphable.
 QuadFactory getFactory()
          Returns the QuadFactory that generated this Quad.
 int getID()
          Returns a unique numeric identifier for this Quad.
 int getLineNumber()
          Returns the line in the original source file that this Quad is derived from.
 String getSourceFile()
          Returns the original source file name that this Quad is derived from.
 HandlerSet handlers()
          Return a set of all the handlers guarding this Quad.
 int hashCode()
           
 boolean isPred(Quad q)
          Return true iff the given node is a predecessor of this node.
 boolean isSucc(Quad q)
          Return true iff the given node is a successor of this node.
abstract  int kind()
          Return an integer enumeration of the kind of this Quad.
protected static Temp map(TempMap tm, Temp t)
          Apply TempMap tm to Temp t.
protected static Temp[] map(TempMap tm, Temp[] ta)
          Apply TempMap to array of Temps.
protected static Temp[][] map(TempMap tm, Temp[][] taa)
          Apply TempMap to 2-d array of Temps.
 Quad[] next()
          Returns an array containing all the successors of this quad, in order.
 Quad next(int i)
          Returns the ith successor of this quad.
 Edge[] nextEdge()
          Returns an array containing all the outgoing edges from this quad.
 Edge nextEdge(int i)
          Returns the ith outgoing edge for this quad.
 int nextLength()
          Return the number of successors of this quad.
 Edge[] pred()
          Returns an array of all the edges entering this CFGraphable.
 List<Edge> predC()
          Returns a List of all the edges to this HCodeElement.
 Quad[] prev()
          Returns an array containing all the predecessors of this quad, in order.
 Quad prev(int i)
          Returns the ith predecessor of this quad.
 Edge[] prevEdge()
          Returns an array containing all the incoming edges of this quad.
 Edge prevEdge(int i)
          Returns the ith incoming edge of this quad.
 int prevLength()
          Return the number of predecessors of this quad.
 Edge remove()
          Remove this quad from the graph.
 void removeHandlers(HandlerSet handlers)
          Remove this quad from the given handler sets.
abstract  Quad rename(QuadFactory qf, TempMap defMap, TempMap useMap)
          Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping.
 Quad rename(TempMap defMap, TempMap useMap)
          Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping.
static void replace(Quad oldQ, Quad newQ)
          Replace one quad with another.
 Edge[] succ()
          Returns an array of all the edges leaving this CFGraphable.
 List<Edge> succC()
          Returns a List of all the edges from this HCodeElement.
 String toLongString()
          Returns a string representation of this quad containing the source file and the line number info, in addition to the other information provided by the regulat toString().
abstract  String toString()
          Force everyone to reimplement toString()
static void transferHandlers(Quad oldQ, Quad newQ)
          Update the handlers for newQ to match the handlers for oldQ, removing handlers from oldQ in the process.
 Temp[] use()
          Return all the Temps used by this Quad.
 Collection<Temp> useC()
          Returns a Collection of all the Temps read in this HCodeElement.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

arrayFactory

public static final ArrayFactory<Quad> arrayFactory
Array factory: returns Quad[]s

Constructor Detail

Quad

protected Quad(QuadFactory qf,
               HCodeElement source,
               int prev_arity,
               int next_arity)
Initializes a quad with prev_arity input edges and next_arity output edges.


Quad

protected Quad(QuadFactory qf,
               HCodeElement source)
Initializes a quad with exactly one input edge and exactly one output edge.

Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getFactory

public QuadFactory getFactory()
Returns the QuadFactory that generated this Quad.


getSourceFile

public String getSourceFile()
Returns the original source file name that this Quad is derived from.

Specified by:
getSourceFile in interface HCodeElement

getLineNumber

public int getLineNumber()
Returns the line in the original source file that this Quad is derived from.

Specified by:
getLineNumber in interface HCodeElement

getID

public int getID()
Returns a unique numeric identifier for this Quad.

Specified by:
getID in interface HCodeElement

toString

public abstract String toString()
Force everyone to reimplement toString()

Overrides:
toString in class Object

toLongString

public String toLongString()
Returns a string representation of this quad containing the source file and the line number info, in addition to the other information provided by the regulat toString(). Great info for debugging!


accept

public abstract void accept(QuadVisitor v)
Accept a visitor.


accept

public abstract <T> T accept(QuadValueVisitor<T> v)

kind

public abstract int kind()
Return an integer enumeration of the kind of this Quad. The enumerated values are defined in QuadKind.


rename

public abstract Quad rename(QuadFactory qf,
                            TempMap defMap,
                            TempMap useMap)
Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping. The new Quad will have no edges.

The new Quad will come from the specified QuadFactory.


rename

public final Quad rename(TempMap defMap,
                         TempMap useMap)
Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping. The new Quad will have no edges.

The new Quad will come from the same QuadFactory as the receiver.


use

public Temp[] use()
Return all the Temps used by this Quad.

Specified by:
use in interface UseDefable

def

public Temp[] def()
Return all the Temps defined by this Quad.

Specified by:
def in interface UseDefable

useC

public Collection<Temp> useC()
Description copied from interface: UseDefable
Returns a Collection of all the Temps read in this HCodeElement.

Specified by:
useC in interface UseDefable

defC

public Collection<Temp> defC()
Description copied from interface: UseDefable
Returns a Collection of all the Temps defined in this HCodeElement.

Specified by:
defC in interface UseDefable

next

public Quad next(int i)
Returns the ith successor of this quad.


prev

public Quad prev(int i)
Returns the ith predecessor of this quad.


nextLength

public int nextLength()
Return the number of successors of this quad.


prevLength

public int prevLength()
Return the number of predecessors of this quad.


next

public Quad[] next()
Returns an array containing all the successors of this quad, in order.


prev

public Quad[] prev()
Returns an array containing all the predecessors of this quad, in order.


nextEdge

public Edge[] nextEdge()
Returns an array containing all the outgoing edges from this quad.


prevEdge

public Edge[] prevEdge()
Returns an array containing all the incoming edges of this quad.


nextEdge

public Edge nextEdge(int i)
Returns the ith outgoing edge for this quad.


prevEdge

public Edge prevEdge(int i)
Returns the ith incoming edge of this quad.


edges

public Edge[] edges()
Description copied from interface: CFGraphable
Returns an array of all the edges to and from this CFGraphable.

Specified by:
edges in interface CFGraphable<Quad,Edge>

pred

public Edge[] pred()
Description copied from interface: CFGraphable
Returns an array of all the edges entering this CFGraphable.

Specified by:
pred in interface CFGraphable<Quad,Edge>

succ

public Edge[] succ()
Description copied from interface: CFGraphable
Returns an array of all the edges leaving this CFGraphable.

Specified by:
succ in interface CFGraphable<Quad,Edge>

edgeC

public List<Edge> edgeC()
Description copied from interface: CFGraphable
Returns a List of all the edges to and from this HCodeElement.

Specified by:
edgeC in interface CFGraphable<Quad,Edge>

predC

public List<Edge> predC()
Description copied from interface: CFGraphable
Returns a List of all the edges to this HCodeElement. Each CFGEdge returned is guaranteed to return this in response to a call to to(); the actual predecessor will be returned from from().

Specified by:
predC in interface CFGraphable<Quad,Edge>
Specified by:
predC in interface Graph.Node<Quad,Edge>

succC

public List<Edge> succC()
Description copied from interface: CFGraphable
Returns a List of all the edges from this HCodeElement. Each CFGEdge returned is guaranteed to return this in response to a call to from(); the actual successor to this will be returned from to().

Specified by:
succC in interface CFGraphable<Quad,Edge>
Specified by:
succC in interface Graph.Node<Quad,Edge>

isSucc

public boolean isSucc(Quad q)
Description copied from interface: Graph.Node
Return true iff the given node is a successor of this node.

Specified by:
isSucc in interface Graph.Node<Quad,Edge>

isPred

public boolean isPred(Quad q)
Description copied from interface: Graph.Node
Return true iff the given node is a predecessor of this node.

Specified by:
isPred in interface Graph.Node<Quad,Edge>

addEdge

public static Edge addEdge(Quad from,
                           int from_index,
                           Quad to,
                           int to_index)
Adds an edge between two Quads. The from_indexed outgoing edge of from is connected to the to_indexed incoming edge of to.

Returns:
the added Edge.

addEdges

public static void addEdges(Quad[] quadlist)
Add edges between a string of Quads. The first outgoing edge is connected to the first incoming edge for all edges added. The same as multiple addEdge(q[i], 0, q[i+1], 0) calls.


replace

public static void replace(Quad oldQ,
                           Quad newQ)
Replace one quad with another. The number of in and out edges of the new and old quads must match exactly.


remove

public Edge remove()
Remove this quad from the graph. The given quad must have exactly one predecessor and one successor. Also removes the quad from any handler sets it may belong to. Returns the new edge which replaces this quad.


transferHandlers

public static void transferHandlers(Quad oldQ,
                                    Quad newQ)
Update the handlers for newQ to match the handlers for oldQ, removing handlers from oldQ in the process.


addHandlers

public final void addHandlers(HandlerSet handlers)
Add this quad to the given handler sets.


removeHandlers

public final void removeHandlers(HandlerSet handlers)
Remove this quad from the given handler sets.


handlers

public final HandlerSet handlers()
Return a set of all the handlers guarding this Quad.


compareTo

public int compareTo(Quad o)
Specified by:
compareTo in interface Comparable<Quad>

clone

public final Quad clone()
Overrides:
clone in class Object

clone

public final Quad clone(QuadFactory qf,
                        CloningTempMap tm)
Clone a quad into a new quad factory, renaming all of the temps according to tm (which ought to ensure that all the new temps belong to the TempFactory of the new QuadFactory).


clone

public static Quad clone(QuadFactory qf,
                         Quad header)
Create a new copy of a string of Quads starting at the given header using QuadFactory.


map

protected static final Temp map(TempMap tm,
                                Temp t)
Apply TempMap tm to Temp t.

Returns:
tm.tempMap(t) if t is non-null, or null if t is null.

map

protected static final Temp[] map(TempMap tm,
                                  Temp[] ta)
Apply TempMap to array of Temps. Null Temps get mapped to null.


map

protected static final Temp[][] map(TempMap tm,
                                    Temp[][] taa)
Apply TempMap to 2-d array of Temps. Null Temps get mapped to null.