harpoon.Backend.Generic
Class CodeGen

java.lang.Object
  extended by harpoon.Backend.Generic.CodeGen
Direct Known Subclasses:
MaxMunchCG

public abstract class CodeGen
extends Object

Generic.CodeGen is a general class for specific Backends to extend. Typically a Specfile for a specific backend will be designed as an extension of this class.

Version:
$Id: CodeGen.java,v 1.4 2002/04/10 03:02:43 cananian Exp $
Author:
Felix S. Klock II <pnkfelix@mit.edu>

Field Summary
 Frame frame
           
protected  InstrFactory instrFactory
          InstrFactory for Instrs currently generated by CodeGen#emit.
 
Constructor Summary
CodeGen(Frame frame)
          Creates a Generic.CodeGen.
 
Method Summary
protected abstract  Instr cgg_backendEmit(Instr i)
          Protected helper method guaranteed to be called by emit(Instr).
abstract  List cgg_genCode(Code tree, InstrFactory inf)
          Creates a Instr list from the IR.Tree.Code tree.
abstract  Instr cgg_genData(Data tree, InstrFactory inf)
           
 void debug(String s)
           
protected abstract  void declare(Temp t, Derivation.DList dl)
           
protected abstract  void declare(Temp t, HClass clz)
           
protected  void declare(Temp t, TreeDerivation td, Exp e)
           
protected  Instr emit(Instr i)
          Emits i as the next instruction in the instruction stream.
protected  void endGroup(InstrGroup g)
           
 List genCode(Code tree, InstrFactory inf)
          Creates a Instr list from the IR.Tree.Code tree.
 Instr genData(Data tree, InstrFactory inf)
          Creates a Instr list from the IR.Tree.Data tree.
 String prettyPrint(Tree exp)
           
 void procFixup(HMethod hm, Code code, int stackspace, Set usedRegisters)
          Fixes up the procedure entry and exit code for a list of instrs, once it is known how many registers and how much stack space is used.
abstract  Instr procFixup(HMethod hm, Instr instr, int stackspace, Set usedRegisters)
          Fixes up the procedure entry and exit code for a list of instrs, once it is known how many registers and how much stack space is used.
protected  InstrGroup startGroup(InstrGroup.Type type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frame

public final Frame frame

instrFactory

protected InstrFactory instrFactory
InstrFactory for Instrs currently generated by CodeGen#emit. (Assigned by CodeGen#genCode and CodeGen#genData).

Constructor Detail

CodeGen

public CodeGen(Frame frame)
Creates a Generic.CodeGen.

Method Detail

startGroup

protected InstrGroup startGroup(InstrGroup.Type type)

endGroup

protected void endGroup(InstrGroup g)

emit

protected final Instr emit(Instr i)
Emits i as the next instruction in the instruction stream.


cgg_backendEmit

protected abstract Instr cgg_backendEmit(Instr i)
Protected helper method guaranteed to be called by emit(Instr). Must be overridden by CGG specific extension. (IE, there is a CodeGen extension where cgg_backendEmit(..) is implemented for every CodeGeneratorGenerator, such as MaxMunchCG).


declare

protected abstract void declare(Temp t,
                                HClass clz)

declare

protected abstract void declare(Temp t,
                                Derivation.DList dl)

declare

protected final void declare(Temp t,
                             TreeDerivation td,
                             Exp e)

procFixup

public abstract Instr procFixup(HMethod hm,
                                Instr instr,
                                int stackspace,
                                Set usedRegisters)
Fixes up the procedure entry and exit code for a list of instrs, once it is known how many registers and how much stack space is used.


procFixup

public void procFixup(HMethod hm,
                      Code code,
                      int stackspace,
                      Set usedRegisters)
Fixes up the procedure entry and exit code for a list of instrs, once it is known how many registers and how much stack space is used.


genCode

public final List genCode(Code tree,
                          InstrFactory inf)
Creates a Instr list from the IR.Tree.Code tree.
effects: Generates and returns a two element list, where the first element is the head of a Instrs to execute tree, and the second element is the Derivation for that list of instructions.

Returns:
The head of a list of Instrs

cgg_genCode

public abstract List cgg_genCode(Code tree,
                                 InstrFactory inf)
Creates a Instr list from the IR.Tree.Code tree.
effects: Generates and returns a two element list, where the first element is the head of a Instrs to execute tree, and the second element is the Derivation for that list of instructions.

Returns:
The head of a list of Instrs

genData

public final Instr genData(Data tree,
                           InstrFactory inf)
Creates a Instr list from the IR.Tree.Data tree.
effects: Generates and returns a list of Instrs representing the layout of tree.

Returns:
The head of a list of Instrs

cgg_genData

public abstract Instr cgg_genData(Data tree,
                                  InstrFactory inf)

debug

public void debug(String s)

prettyPrint

public String prettyPrint(Tree exp)