harpoon.IR.Assem
Class Code

java.lang.Object
  |
  +--harpoon.ClassFile.HCode
        |
        +--harpoon.IR.Assem.Code
Direct Known Subclasses:
Code, Code

public abstract class Code
extends HCode

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

Version:
$Id: Code.java,v 1.3 2002/02/26 22:45:17 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Nested Class Summary
 
Nested classes inherited from class harpoon.ClassFile.HCode
HCode.PrintCallback
 
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 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 getElementsI()
          Returns an Iterator over the instructions in this codeview.
 Frame getFrame()
           
 InstrFactory getInstrFactory()
          Allows access to the InstrFactory used by this codeview.
 HCodeElement[] 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.
 HCodeElement 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 callback)
          Deprecated. Use Code#myPrint(PrintWriter,boolean,PrintCallback)
protected  void myPrint(PrintWriter pw, boolean assem, HCode.PrintCallback callback)
          Displays the assembly instructions of this codeview.
 void print()
          Prints the assembly instructions of this to System.out.
 void print(PrintWriter pw, HCode.PrintCallback 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, getElementsE, 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

getRootElement

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

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

getLeafElements

public HCodeElement[] 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
Returns:
leaves of the code view, or null if this notion is not applicable.

getElementsI

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

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

elementArrayFactory

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

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

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 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

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 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:
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 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