harpoon.Tools.PatMat
Class CodeGeneratorGenerator

java.lang.Object
  extended by harpoon.Tools.PatMat.CodeGeneratorGenerator
Direct Known Subclasses:
MaximalMunchCGG

public abstract class CodeGeneratorGenerator
extends Object

CodeGeneratorGenerator generates a java program to convert Trees into Instr sequences. A Code Generator Generator (CGG) takes a set of instruction pattern tiles and constructs a java source file for a utility class containing a method codegen(TreeCode) which will generate an HCode in Instr form from a TreeCode. In short, a CGG generates a Code Generator.

Version:
$Id: CodeGeneratorGenerator.java,v 1.5 2004/02/08 01:59:54 cananian Exp $
Author:
Felix S. Klock II <pnkfelix@mit.edu>
See Also:
CodeGen

Field Summary
protected  Spec spec
          The machine specification that the CodeGenerators outputted by this will target.
 
Constructor Summary
CodeGeneratorGenerator(Spec s, String className)
          Creates a CodeGeneratorGenerator.
 
Method Summary
 void outputJavaFile(PrintWriter out)
          Writes the Code Generator to out.
abstract  void outputSelectionMethod(PrintWriter out, boolean isData)
          Writes the Instruction Selection Method to out.
protected abstract  String producedClassType()
          Returns the fully qualified name of the superclass of the generated CodeGen.
protected  String returnCodeStatements()
           
protected  String returnDataStatements()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spec

protected Spec spec
The machine specification that the CodeGenerators outputted by this will target.

Constructor Detail

CodeGeneratorGenerator

public CodeGeneratorGenerator(Spec s,
                              String className)
Creates a CodeGeneratorGenerator.
requires:
  1. s follows the standard template for defining a machine specification.
  2. if s contains Java statements that rely on knowledge about the class to be produced (such as a Constructor implementation) then the class named must match the className parameter.

effects: Creates a new CodeGeneratorGenerator and associates the machine specification s with the newly constructed CodeGeneratorGenerator.

Parameters:
s - Spec defining the machine specification that the CodeGenerator output by this will target.
className - Formal name of the class that this outputs.
See Also:
Standard Specification Template
Method Detail

producedClassType

protected abstract String producedClassType()
Returns the fully qualified name of the superclass of the generated CodeGen. The superclass should be a subclass of Generic.CodeGen (or Generic.CodeGen itself.


outputJavaFile

public void outputJavaFile(PrintWriter out)
Writes the Code Generator to out.
modifies: out
effects: Generates Java source for the machine specification associated with this. Then writes the Java source code out to out, and flushes out after it finishes outputting the source code.
All of the output file is parameterized by this.spec, with the exception of
  1. Class name. This is already defined by this.className.
  2. Class signature. This is already hardcoded as public class this.className extends harpoon.Backend.Generic.CodeGen.
  3. Code-gen method signature. This is already hardcoded as public final Instr gen(harpoon.IR.Tree.Code tree, harpoon.IR.Assem.InstrFactory inf).
  4. Data-gen method signature. This is already hardcoded as public final Instr gen(harpoon.IR.Tree.Data tree, harpoon.IR.Assem.InstrFactory inf).

Parameters:
out - Target output device for the Java source code.

returnCodeStatements

protected String returnCodeStatements()

returnDataStatements

protected String returnDataStatements()

outputSelectionMethod

public abstract void outputSelectionMethod(PrintWriter out,
                                           boolean isData)
Writes the Instruction Selection Method to out.
modifies: out
effects:
Generates Java source for the instruction selection method, not including method signature or surrounding braces.
Outputs generated source to out.
Subclass Implementation Notes:
Generated method has one parameter available to be referenced: code, a Tree.Code that represents the input set of Tree HCodeElements. From this the code may access the Frame, TreeDerivation, and IR.Tree.Tree objects necessary to create assembly code Instrs using the actions provided by a spec file.
Generated method must, for each pattern in this.spec, define variables for the action statements in the pattern to refer to. These variables are:
  1. The Spec.ExpId objects defined in the pattern, including the result_id and %extra Temp objects.
  2. The HCodeElement ROOT. This should be defined as the IR.Tree.Tree element being analyzed. To reference specific fields or methods of the IR.Tree.Tree element being analyzed, one should cast ROOT to the appropriate subclass of IR.Tree.Tree (though this requirement may be dropped in the future).

Generated method finds a tiling for tree, using the information in this.spec as a Spec.Rule tile source, and then runs Spec.Rule.action_str for each matching tile.
Awards bonus points to subclasses that implement this method to output documentation for the generated method body.

Parameters:
out - Target output device for the Java source code.
isData - indicates if we're pattern matching code or data tables