harpoon.IR.Assem
Class Code

java.lang.Object
  extended by harpoon.ClassFile.HCode<Instr>
      extended by harpoon.IR.Assem.Code
All Implemented Interfaces:
Graph<Instr,InstrEdge>
Direct Known Subclasses:
Code, Code

public abstract class Code
extends HCode<Instr>
implements Graph<Instr,InstrEdge>

IR.Assem.Code is an abstract superclass of codeviews which use Instrs.

Version:
$Id: Code.java,v 1.8 2004/02/08 01:55:08 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Nested Class Summary
 
Nested classes/interfaces inherited from class harpoon.ClassFile.HCode
HCode.PrintCallback<HCE extends HCodeElement>
 
Nested classes/interfaces inherited from interface harpoon.Util.Collections.Graph
Graph.Edge<N extends Graph.Node<N,E>,E extends Graph.Edge<N,E>>, Graph.Node<N extends Graph.Node<N,E>,E extends Graph.Edge<N,E>>
 
Field Summary
protected  Frame frame
          The Frame associated with this codeview.
protected  InstrFactory inf
          Instruction factory.
protected  Instr instrs
          The root Instr of the Instrs composing this code view.
protected  HMethod parent
          The method that this code view represents.
 
Constructor Summary
protected Code(HMethod parent, Frame frame)
          constructor.
protected Code(HMethod parent, Frame frame, String codeName)
          constructor.
 
Method Summary
 ArrayFactory<Instr> elementArrayFactory()
          Returns an array factory to create the instruction elements of this codeview.
static String formatCommentedInstr(String exec, String orig)
          Returns an assembly code String version of exec with orig in the comments for exec.
 Derivation getDerivation()
          Returns the Derivation associated with this.
 Iterator<Instr> getElementsI()
          Returns an Iterator over the instructions in this codeview.
 Frame getFrame()
           
 InstrFactory getInstrFactory()
          Allows access to the InstrFactory used by this codeview.
 Instr[] getLeafElements()
          Return the 'leaves' of this code view; that is, the elements with no successors.
 HMethod getMethod()
          Return the HMethod to which this HCode belongs.
abstract  String getRegisterName(Instr i, Temp val, String suffix)
          Returns an assembly code identifier for the register that val will be stored into.
 Instr getRootElement()
          Return the 'root' element of this code view.
 void myPrint(PrintWriter apw, boolean assem)
          Simple wrapper around myPrint passing a nop PrintCallback.
protected  void myPrint(PrintWriter apw, boolean assem, boolean annotateID, HCode.PrintCallback<Instr> callback)
          Deprecated. Use Code#myPrint(PrintWriter,boolean,PrintCallback)
protected  void myPrint(PrintWriter pw, boolean assem, HCode.PrintCallback<Instr> callback)
          Displays the assembly instructions of this codeview.
 Set<Instr> nodes()
          Return the set of nodes comprising this Graph.
 void print()
          Prints the assembly instructions of this to System.out.
 void print(PrintWriter pw, HCode.PrintCallback<Instr> callback)
          Prints the assembly instructions of this to pw.
 String toAssem(Instr instr)
          Produces an assembly code string for instr.
 
Methods inherited from class harpoon.ClassFile.HCode
clone, clone, elementIndexer, getElements, getElementsL, getName, print, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected HMethod parent
The method that this code view represents.


instrs

protected Instr instrs
The root Instr of the Instrs composing this code view.


inf

protected final InstrFactory inf
Instruction factory.


frame

protected final Frame frame
The Frame associated with this codeview.

Constructor Detail

Code

protected Code(HMethod parent,
               Frame frame,
               String codeName)
constructor.


Code

protected Code(HMethod parent,
               Frame frame)
constructor.

Method Detail

getMethod

public HMethod getMethod()
Description copied from class: HCode
Return the HMethod to which this HCode belongs.

Specified by:
getMethod in class HCode<Instr>

getRootElement

public Instr getRootElement()
Description copied from class: HCode
Return the 'root' element of this code view.

Overrides:
getRootElement in class HCode<Instr>
Returns:
root of the code view, or null if this notion is not applicable.

getLeafElements

public Instr[] getLeafElements()
Description copied from class: HCode
Return the 'leaves' of this code view; that is, the elements with no successors.

Overrides:
getLeafElements in class HCode<Instr>
Returns:
leaves of the code view, or null if this notion is not applicable.

getElementsI

public Iterator<Instr> getElementsI()
Returns an Iterator over the instructions in this codeview.

Overrides:
getElementsI in class HCode<Instr>
Returns:
An iterator over the Instrs making up this code view. The root Instr is the first element in the iteration.

elementArrayFactory

public ArrayFactory<Instr> elementArrayFactory()
Returns an array factory to create the instruction elements of this codeview.

Specified by:
elementArrayFactory in class HCode<Instr>
Returns:
An ArrayFactory which produces Instrs.

nodes

public Set<Instr> nodes()
Description copied from interface: Graph
Return the set of nodes comprising this Graph.

Specified by:
nodes in interface Graph<Instr,InstrEdge>

getInstrFactory

public InstrFactory getInstrFactory()
Allows access to the InstrFactory used by this codeview.

Returns:
The InstrFactory used by this codeview.

getFrame

public Frame getFrame()

print

public void print()
Prints the assembly instructions of this to System.out.

See Also:
HCode.print(java.io.PrintWriter)

print

public void print(PrintWriter pw,
                  HCode.PrintCallback<Instr> callback)
Prints the assembly instructions of this to pw. Default implementation is just a wrapper call to myPrint(pw, true, false), which turns each Instr into its architecture specific assembly format and omits Instr ID number information.

Overrides:
print in class HCode<Instr>

myPrint

public final void myPrint(PrintWriter apw,
                          boolean assem)
Simple wrapper around myPrint passing a nop PrintCallback.


myPrint

protected final void myPrint(PrintWriter apw,
                             boolean assem,
                             boolean annotateID,
                             HCode.PrintCallback<Instr> callback)
Deprecated. Use Code#myPrint(PrintWriter,boolean,PrintCallback)

Displays the assembly instructions of this codeview. Attempts to do so in a well-formatted, easy to read way.
XXX - currently uses generic, not so easy to read, printer.

Parameters:
pw - The PrintWriter to send the formatted output to.
assem - If true, uses toAssem(Instr) to convert Instrs to assembly form. Else just calls Instr.toString().
annotateID - If true, prints out the ID for each Instr before printing the Instr itself.
See Also:
toAssem(harpoon.IR.Assem.Instr)

myPrint

protected final void myPrint(PrintWriter pw,
                             boolean assem,
                             HCode.PrintCallback<Instr> callback)
Displays the assembly instructions of this codeview. Attempts to do so in a well-formatted, easy to read way.
XXX - currently uses generic, not so easy to read, printer.

Parameters:
pw - The PrintWriter to send the formatted output to.
assem - If true, uses toAssem(Instr) to convert Instrs to assembly form. Else just calls Instr.toString().
See Also:
toAssem(harpoon.IR.Assem.Instr)

toAssem

public String toAssem(Instr instr)
Produces an assembly code string for instr. Uses getRegisterName() to do register name string mapping.


getDerivation

public Derivation getDerivation()
Returns the Derivation associated with this. Returns null if Derivation information is not available.


getRegisterName

public abstract String getRegisterName(Instr i,
                                       Temp val,
                                       String suffix)
Returns an assembly code identifier for the register that val will be stored into.


formatCommentedInstr

public static String formatCommentedInstr(String exec,
                                          String orig)
Returns an assembly code String version of exec with orig in the comments for exec.
requires: exec and orig have the same number of lines
effects: let s be a new empty string in for each line:le in exec, let lo be the next line of orig ; s += (le + " @" + lo) return s