coins.backend.gen
Class CodeGenerator

java.lang.Object
  extended bycoins.backend.gen.CodeGenerator
Direct Known Subclasses:
CodeGenerator_alpha, CodeGenerator_arm, CodeGenerator_mb, CodeGenerator_mips, CodeGenerator_ppc, CodeGenerator_sample, CodeGenerator_sh4, CodeGenerator_sparc, CodeGenerator_thumb, CodeGenerator_x86, CodeGenerator_x86_64, CodeGenerator_x86simd

public abstract class CodeGenerator
extends java.lang.Object

Abstract code generator. Generators for specific machines are defined as subclasses of this class.


Nested Class Summary
(package private) static class CodeGenerator.FunctionAttr
          Keeps track of function's attributes.
(package private)  class CodeGenerator.LexpToString
          Convert address expression to external form.
(package private)  class CodeGenerator.Match
          Node of matching tree (or DAG)
 
Field Summary
(package private)  int addrType
          Address type
(package private)  java.io.PrintWriter asmWriter
          Output Writer
(package private)  java.lang.String convention
          OS convention
(package private)  java.io.PrintWriter debOut
          Debugging message
(package private)  NumberSet disableRewrite
          Flags for disabling rescanning.
(package private) static int F128
           
(package private) static int F32
           
(package private) static int F64
           
(package private)  Function func
          Current function
(package private)  java.util.Map funcAttrTbl
          Function attribute tables.
(package private) static int I16
           
(package private) static int I32
           
(package private) static int I64
          Commonly used type constants.
(package private) static int I8
           
(package private) static int INLINECOPYUNIT
           
(package private)  CodeGenerator.LexpToString lexpConv
           
(package private)  LirFactory lir
          LIR factory
(package private)  LocalTransformer localEarlyRewritingTrig
          Early time pre-rewriting of LIR, function by function.
(package private)  LocalTransformer localLateRewritingTrig
          Late time pre-rewriting of LIR, function by function.
(package private)  java.lang.String machineName
          CPU name
(package private)  MachineParams machineParams
          Feature of Machine
(package private)  Module module
          L-Module
(package private)  boolean optSpeed
          Flag speed/space tradeoff.
(package private)  LocalTransformer ProcessFramesTrig
           
(package private)  Root root
          Global variables
(package private)  int typeParamWord
          Type of parameter words on stack
 
Constructor Summary
CodeGenerator()
          Creator
 
Method Summary
 int alignForType(int type)
          Return alignment for type.
(package private)  BiList buildCode(Function f)
          Convert FUNCTION to S-expression assembly code.
(package private)  ImList clcvnClobbers()
          Return clobber list
(package private)  LirNode clcvnParamMem(int type, int location, boolean caller)
          Return parameter memory
(package private)  int clcvnParamOffset(int location)
          Return offset of parameter
(package private)  LirNode clcvnParamReg(int type, int location, boolean caller)
          Return parameter register
(package private)  LirNode clcvnParamWord(int type, int location, boolean caller)
          Return parameter word - either register or memory.
(package private)  LirNode clcvnPartialWord(LirNode exp, int part)
          Return partial word of object
(package private)  void clcvnPassFloatRegMem(int location, LirNode arg, BiLink memp, BiLink regp, BiList alist)
          Pass floating point number to register/ register and memory.
(package private)  int clcvnRegLimit()
          Return number of registers multiply word-size.
(package private)  LirNode clcvnReturnValue(int type)
          Return return register
(package private)  LirNode clcvnSetPartialWord(LirNode lhs, int part, LirNode rhs)
          Set partial word of object
(package private)  boolean clcvnStructReturnAsFirst()
          Return true if struct return address
(package private)  LirNode clcvnStructReturnPtr(boolean caller)
          Create code that sets address of struct to hidden parameter.
 void close()
          Close output stream.
 ImList codeInfo(LirNode ins)
          Return cost and misc.
 LocalTransformer convToAsm()
           
(package private) abstract  java.lang.String defaultRegsetForType(int type)
          Return default register set for type.
(package private)  LirNode dropRegToFrame(LirNode node)
          Convert (REG t ...) node to (MEM t (FRAME I32 ...)).
 Transformer[] earlyRewritingSequence()
          Return early time pre-rewriting sequence.
(package private)  void emitAlign(java.io.PrintWriter out, int align)
          Emit align (Bytesize)
(package private)  java.lang.String emitAsmCode(java.lang.String format, ImList args)
          Emit asm instruction.
(package private)  void emitBeginningOfModule(Module mod, java.io.PrintWriter out)
          Emit beginning of module
(package private)  void emitBeginningOfSegment(java.io.PrintWriter out, java.lang.String segment)
          Emit beginning of segment
(package private)  void emitCode(BiList asmList, java.io.PrintWriter file)
          Emit S-expression assembly code to file.
(package private)  void emitCodeLabel(java.io.PrintWriter out, java.lang.String label)
          Emit label for code
(package private)  void emitComment(java.io.PrintWriter out, java.lang.String comment)
          print comment in assembly language.
(package private)  void emitCommon(java.io.PrintWriter out, SymStatic symbol, int bytes)
          Emit data common
(package private)  void emitData(java.io.PrintWriter out, int type, LirNode node)
          Emit data for big endian machine.
(package private)  void emitDataLabel(java.io.PrintWriter out, java.lang.String label)
          Emit label for data
(package private)  void emitEndOfModule(Module mod, java.io.PrintWriter out)
          Emit ending of module
(package private)  void emitEndOfSegment(java.io.PrintWriter out, java.lang.String segment)
          Emit end of segment
(package private)  void emitIdent(java.io.PrintWriter out, java.lang.String ident)
          Print .ident in assembly language.
(package private)  void emitLinkage(java.io.PrintWriter out, SymStatic symbol)
          Emit linkage information of symbol
(package private) abstract  java.lang.String emitLir(LirNode node)
          Expand emit-macro for LirNode.
(package private)  java.lang.String emitLirDefault(LirNode node)
          Default expansion action for LirNode.
(package private) abstract  java.lang.String emitList(ImList form, boolean topLevel)
          Expand emit-macro for list form.
(package private)  java.lang.String emitListDefault(ImList form, boolean topLevel)
          Default expansion action for S-expression.
 void emitNamedConst(java.lang.String name, LirNode value)
          Emit named constant.
(package private)  java.lang.String emitObject(java.lang.Object x)
          Convert S-expression assembly code to string.
(package private)  java.lang.String emitObjectX(java.lang.Object x, boolean top)
          Convert S-expression assembly code to string.
(package private)  void emitSegment(java.io.PrintWriter file, java.lang.String segment)
          Change default segment to segment.
(package private)  java.lang.String emitTop(java.lang.Object x)
          Convert toplevel S-expression assembly code to string.
(package private)  void emitZeros(java.io.PrintWriter out, int bytes)
          Emit data zeros
(package private)  boolean equalArg(LirNode x, LirNode y)
          Return true if variable x and y are same.
(package private) abstract  java.lang.Object expandBuildMacro(ImList form)
          Expand building macro for list form.
(package private)  boolean frameIsEmpty(Function f)
           
(package private)  int frameSize(Function f)
          Return frame size (in positive) of function.
 void genHeader(Module mod)
          Generate header on assembly file.
 void genTrailer(Module mod)
          Generate trailer on assembly file.
(package private) abstract  int getCost1(LirNode t, int goal)
          Return the cost for LIR node t and goal nonterminal goal.
(package private) abstract  int getCost2(LirNode t, int goal)
           
(package private)  CodeGenerator.FunctionAttr getFunctionAttr(Function func)
          Return function attributes.
 MachineParams getMachineParams()
          Return machineParams
(package private) abstract  Rule getRule(LirNode t, int goal)
          Return the chosen rule for LIR node t and goal nonterminal goal.
 void initialize(Root root, Module module, TargetMachine target, java.lang.String machine, java.lang.String convention)
          Set root pointer etc.
(package private)  void initializeMachineDep()
          Do Machine-dependent initialization (subclass may override this).
(package private) abstract  void initLabeling(LirFactory lir)
          Initialize for labeling.
(package private) abstract  void initRewriteLabeling()
          Initialization for rewriting.
(package private)  java.io.OutputStream insertPostProcessor(java.io.OutputStream stream)
          Insert post-processor filter pass.
 void instructionSelection(Function f)
          Rewrite a function so that each LIR tree corresponds to single machine instruction.
(package private)  boolean isComplex(LirNode node)
          Return true if node is a complex one.
(package private)  boolean isSimple(LirNode node)
          Return true if node is a simple variable.
(package private) abstract  void labelTree(LirNode t)
          Label LIR tree t.
 Transformer[] lateRewritingSequence()
          Return late time pre-rewriting sequence.
(package private)  java.lang.String makeAsmSymbol(java.lang.String symbol)
          Make symbol in assembly language form.
(package private)  java.lang.String makeLabelDef(java.lang.String label)
          Return label definition
(package private)  Symbol mapRegToFrame(Symbol reg)
          Return FRAME variable symbol entry which corresponds to REG variable.
(package private)  int nActualOperands(LirNode node)
          Return the number of operands excluding CLOBBER and USE.
(package private)  CodeGenerator.FunctionAttr newFunctionAttr(Function f)
          Prepare new function attribute information.
(package private)  LirNode noRescan(LirNode node)
          Disable rewriting of LIR node.
(package private)  void notifyEndToPostProcessor()
          Notify end of assembly to post-processor.
(package private)  int paramOffset(LirNode arg)
          Return offset of the formal parameter (used by va_start).
(package private)  int paramToBeSaved()
          Return the location of parameter which should be reside on memory.
(package private)  void peepHoleOpt(BiList list)
          Peep-hole optimizer.
(package private)  LirNode phyReg(java.lang.String name)
          Return physical register node.
 void prepareCodeInfo(Function f)
           
 void prerewrite(Function f, java.lang.String phase)
          Pre-rewrite of L-Function.
(package private)  void printLabel(LirNode t, java.lang.String indent)
          Print label of tree t.
(package private) abstract  java.lang.Object quiltLir(LirNode node)
          Expand building macro for LirNode.
(package private)  java.lang.Object quiltLirDefault(LirNode node)
          Expand LirNode
(package private)  CodeGenerator.Match reduce(LirNode t, int goal)
          Reduce labeled tree t with goal nonterminal goal.
(package private)  SymAuto reserveFrame(java.lang.String name, int type)
          Reserve frame variable.
(package private)  LirNode rewriteAggregateCopy(LirNode node, BiList pre)
          Rewrite aggregate copy.
(package private)  LirNode rewriteAsm(LirNode node, BiList pre, BiList post)
          Rewrite ASM
(package private)  LirNode rewriteCall(LirNode node, BiList pre, BiList post)
          Rewrite CALL.
(package private)  LirNode rewriteCONVFU(LirNode node, BiList pre)
          Rewrite CONVFU(x) to: if (x < 2147483648) CONVFS(x) else CONVFS(x - 2147483648) + 214748648
(package private)  LirNode rewriteCONVUF(LirNode node, BiList pre)
          Rewrite CONVUF
(package private)  LirNode rewriteEpilogue(LirNode node, BiList pre)
          Rewrite EPILOGUE
(package private)  LirNode rewriteFrame(LirNode node)
          Rewrite FRAME node to target machine form.
(package private)  LirNode rewriteJumpn(LirNode node, BiList pre)
          Rewrite JUMPN.
(package private)  LirNode rewritePrologue(LirNode node, BiList post)
          Rewrite PROLOGUE
(package private) abstract  LirNode rewriteTree(LirNode tree, java.lang.String phase, BiList pre, BiList post)
          Rewrite L-expression.
(package private)  java.lang.String segmentForConst()
          Return segment for read-only constant.
 void setAsmStream(java.io.OutputStream stream)
          Set assembler output stream.
(package private) abstract  java.lang.String showLabel(LirNode t)
          Return label state
(package private) abstract  int startNT()
          Return start nonterminal symbol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

I64

static final int I64
Commonly used type constants.


I32

static final int I32

I16

static final int I16

I8

static final int I8

F128

static final int F128

F64

static final int F64

F32

static final int F32

root

Root root
Global variables


module

Module module
L-Module


debOut

java.io.PrintWriter debOut
Debugging message


machineParams

MachineParams machineParams
Feature of Machine


addrType

int addrType
Address type


typeParamWord

int typeParamWord
Type of parameter words on stack


machineName

java.lang.String machineName
CPU name


convention

java.lang.String convention
OS convention


funcAttrTbl

java.util.Map funcAttrTbl
Function attribute tables.


optSpeed

boolean optSpeed
Flag speed/space tradeoff.


func

Function func
Current function


lir

LirFactory lir
LIR factory


asmWriter

java.io.PrintWriter asmWriter
Output Writer


disableRewrite

NumberSet disableRewrite
Flags for disabling rescanning.


localEarlyRewritingTrig

final LocalTransformer localEarlyRewritingTrig
Early time pre-rewriting of LIR, function by function.


localLateRewritingTrig

final LocalTransformer localLateRewritingTrig
Late time pre-rewriting of LIR, function by function.


ProcessFramesTrig

final LocalTransformer ProcessFramesTrig

INLINECOPYUNIT

static final int INLINECOPYUNIT
See Also:
Constant Field Values

lexpConv

CodeGenerator.LexpToString lexpConv
Constructor Detail

CodeGenerator

public CodeGenerator()
Creator

Method Detail

initialize

public void initialize(Root root,
                       Module module,
                       TargetMachine target,
                       java.lang.String machine,
                       java.lang.String convention)
Set root pointer etc. This class is created by newInstance() so constructor can't take arguments.


setAsmStream

public void setAsmStream(java.io.OutputStream stream)
Set assembler output stream.


insertPostProcessor

java.io.OutputStream insertPostProcessor(java.io.OutputStream stream)
Insert post-processor filter pass. Subclasses may override it.


notifyEndToPostProcessor

void notifyEndToPostProcessor()
Notify end of assembly to post-processor. Subclasses may override it.


initializeMachineDep

void initializeMachineDep()
Do Machine-dependent initialization (subclass may override this).


getFunctionAttr

CodeGenerator.FunctionAttr getFunctionAttr(Function func)
Return function attributes.


noRescan

LirNode noRescan(LirNode node)
Disable rewriting of LIR node.


prerewrite

public void prerewrite(Function f,
                       java.lang.String phase)
Pre-rewrite of L-Function.


initRewriteLabeling

abstract void initRewriteLabeling()
Initialization for rewriting.


rewriteTree

abstract LirNode rewriteTree(LirNode tree,
                             java.lang.String phase,
                             BiList pre,
                             BiList post)
Rewrite L-expression.


earlyRewritingSequence

public Transformer[] earlyRewritingSequence()
Return early time pre-rewriting sequence.


lateRewritingSequence

public Transformer[] lateRewritingSequence()
Return late time pre-rewriting sequence.


frameSize

int frameSize(Function f)
Return frame size (in positive) of function.


frameIsEmpty

boolean frameIsEmpty(Function f)

dropRegToFrame

LirNode dropRegToFrame(LirNode node)
Convert (REG t ...) node to (MEM t (FRAME I32 ...)).


mapRegToFrame

Symbol mapRegToFrame(Symbol reg)
Return FRAME variable symbol entry which corresponds to REG variable.


reserveFrame

SymAuto reserveFrame(java.lang.String name,
                     int type)
Reserve frame variable.


rewriteAggregateCopy

LirNode rewriteAggregateCopy(LirNode node,
                             BiList pre)
Rewrite aggregate copy. Subclasses may override this.


paramToBeSaved

int paramToBeSaved()
Return the location of parameter which should be reside on memory.


paramOffset

int paramOffset(LirNode arg)
Return offset of the formal parameter (used by va_start).


equalArg

boolean equalArg(LirNode x,
                 LirNode y)
Return true if variable x and y are same.


rewritePrologue

LirNode rewritePrologue(LirNode node,
                        BiList post)
Rewrite PROLOGUE


rewriteEpilogue

LirNode rewriteEpilogue(LirNode node,
                        BiList pre)
Rewrite EPILOGUE


isComplex

boolean isComplex(LirNode node)
Return true if node is a complex one.


phyReg

LirNode phyReg(java.lang.String name)
Return physical register node.


rewriteCall

LirNode rewriteCall(LirNode node,
                    BiList pre,
                    BiList post)
Rewrite CALL. Subclasses may override this.


clcvnRegLimit

int clcvnRegLimit()
Return number of registers multiply word-size.


clcvnParamWord

LirNode clcvnParamWord(int type,
                       int location,
                       boolean caller)
Return parameter word - either register or memory.


clcvnParamReg

LirNode clcvnParamReg(int type,
                      int location,
                      boolean caller)
Return parameter register


clcvnParamMem

LirNode clcvnParamMem(int type,
                      int location,
                      boolean caller)
Return parameter memory


clcvnPassFloatRegMem

void clcvnPassFloatRegMem(int location,
                          LirNode arg,
                          BiLink memp,
                          BiLink regp,
                          BiList alist)
Pass floating point number to register/ register and memory.


clcvnParamOffset

int clcvnParamOffset(int location)
Return offset of parameter


clcvnReturnValue

LirNode clcvnReturnValue(int type)
Return return register


clcvnSetPartialWord

LirNode clcvnSetPartialWord(LirNode lhs,
                            int part,
                            LirNode rhs)
Set partial word of object


clcvnPartialWord

LirNode clcvnPartialWord(LirNode exp,
                         int part)
Return partial word of object


clcvnClobbers

ImList clcvnClobbers()
Return clobber list


clcvnStructReturnAsFirst

boolean clcvnStructReturnAsFirst()
Return true if struct return address


clcvnStructReturnPtr

LirNode clcvnStructReturnPtr(boolean caller)
Create code that sets address of struct to hidden parameter. Subclasses may override this.


rewriteJumpn

LirNode rewriteJumpn(LirNode node,
                     BiList pre)
Rewrite JUMPN. Subclasses may override this.


rewriteAsm

LirNode rewriteAsm(LirNode node,
                   BiList pre,
                   BiList post)
Rewrite ASM


nActualOperands

int nActualOperands(LirNode node)
Return the number of operands excluding CLOBBER and USE.


instructionSelection

public void instructionSelection(Function f)
Rewrite a function so that each LIR tree corresponds to single machine instruction.


genHeader

public void genHeader(Module mod)
Generate header on assembly file.


convToAsm

public LocalTransformer convToAsm()

emitNamedConst

public void emitNamedConst(java.lang.String name,
                           LirNode value)
Emit named constant.


buildCode

BiList buildCode(Function f)
Convert FUNCTION to S-expression assembly code.


prepareCodeInfo

public void prepareCodeInfo(Function f)

codeInfo

public ImList codeInfo(LirNode ins)
Return cost and misc. information about instruction tree.

Parameters:
ins - instruction L-expression tree which are alpready reduced.
Returns:
ImList of (hasDelaySlot, cost)

quiltLirDefault

java.lang.Object quiltLirDefault(LirNode node)
Expand LirNode


peepHoleOpt

void peepHoleOpt(BiList list)
Peep-hole optimizer. This method is dummy; Subclasses may override this.


emitCode

void emitCode(BiList asmList,
              java.io.PrintWriter file)
Emit S-expression assembly code to file.


emitTop

java.lang.String emitTop(java.lang.Object x)
Convert toplevel S-expression assembly code to string.


emitObject

java.lang.String emitObject(java.lang.Object x)
Convert S-expression assembly code to string.


emitObjectX

java.lang.String emitObjectX(java.lang.Object x,
                             boolean top)
Convert S-expression assembly code to string.

Parameters:
top - true if this is a top-level.

emitListDefault

java.lang.String emitListDefault(ImList form,
                                 boolean topLevel)
Default expansion action for S-expression.


emitLirDefault

java.lang.String emitLirDefault(LirNode node)
Default expansion action for LirNode. (obsoleted)


genTrailer

public void genTrailer(Module mod)
Generate trailer on assembly file.


close

public void close()
Close output stream.


emitSegment

void emitSegment(java.io.PrintWriter file,
                 java.lang.String segment)
Change default segment to segment.


printLabel

void printLabel(LirNode t,
                java.lang.String indent)
Print label of tree t.


reduce

CodeGenerator.Match reduce(LirNode t,
                           int goal)
                     throws NoMatchException
Reduce labeled tree t with goal nonterminal goal.

Throws:
NoMatchException

isSimple

boolean isSimple(LirNode node)
Return true if node is a simple variable.


rewriteCONVUF

LirNode rewriteCONVUF(LirNode node,
                      BiList pre)
Rewrite CONVUF


rewriteCONVFU

LirNode rewriteCONVFU(LirNode node,
                      BiList pre)
Rewrite CONVFU(x) to: if (x < 2147483648) CONVFS(x) else CONVFS(x - 2147483648) + 214748648


initLabeling

abstract void initLabeling(LirFactory lir)
Initialize for labeling.


showLabel

abstract java.lang.String showLabel(LirNode t)
Return label state


labelTree

abstract void labelTree(LirNode t)
Label LIR tree t.


getRule

abstract Rule getRule(LirNode t,
                      int goal)
Return the chosen rule for LIR node t and goal nonterminal goal.


getCost1

abstract int getCost1(LirNode t,
                      int goal)
Return the cost for LIR node t and goal nonterminal goal.


getCost2

abstract int getCost2(LirNode t,
                      int goal)

startNT

abstract int startNT()
Return start nonterminal symbol.


defaultRegsetForType

abstract java.lang.String defaultRegsetForType(int type)
Return default register set for type.


emitList

abstract java.lang.String emitList(ImList form,
                                   boolean topLevel)
Expand emit-macro for list form.


emitLir

abstract java.lang.String emitLir(LirNode node)
Expand emit-macro for LirNode.


expandBuildMacro

abstract java.lang.Object expandBuildMacro(ImList form)
Expand building macro for list form.


quiltLir

abstract java.lang.Object quiltLir(LirNode node)
Expand building macro for LirNode.


rewriteFrame

LirNode rewriteFrame(LirNode node)
Rewrite FRAME node to target machine form.


emitIdent

void emitIdent(java.io.PrintWriter out,
               java.lang.String ident)
Print .ident in assembly language.


emitComment

void emitComment(java.io.PrintWriter out,
                 java.lang.String comment)
print comment in assembly language.


emitBeginningOfModule

void emitBeginningOfModule(Module mod,
                           java.io.PrintWriter out)
Emit beginning of module


emitEndOfModule

void emitEndOfModule(Module mod,
                     java.io.PrintWriter out)
Emit ending of module


emitBeginningOfSegment

void emitBeginningOfSegment(java.io.PrintWriter out,
                            java.lang.String segment)
Emit beginning of segment


emitEndOfSegment

void emitEndOfSegment(java.io.PrintWriter out,
                      java.lang.String segment)
Emit end of segment


emitLinkage

void emitLinkage(java.io.PrintWriter out,
                 SymStatic symbol)
Emit linkage information of symbol


emitDataLabel

void emitDataLabel(java.io.PrintWriter out,
                   java.lang.String label)
Emit label for data


emitCodeLabel

void emitCodeLabel(java.io.PrintWriter out,
                   java.lang.String label)
Emit label for code


emitAlign

void emitAlign(java.io.PrintWriter out,
               int align)
Emit align (Bytesize)


emitCommon

void emitCommon(java.io.PrintWriter out,
                SymStatic symbol,
                int bytes)
Emit data common


emitZeros

void emitZeros(java.io.PrintWriter out,
               int bytes)
Emit data zeros


emitAsmCode

java.lang.String emitAsmCode(java.lang.String format,
                             ImList args)
Emit asm instruction.


emitData

void emitData(java.io.PrintWriter out,
              int type,
              LirNode node)
Emit data for big endian machine. Redefine this method if your machine is little endian.


newFunctionAttr

CodeGenerator.FunctionAttr newFunctionAttr(Function f)
Prepare new function attribute information.


alignForType

public int alignForType(int type)
Return alignment for type.


segmentForConst

java.lang.String segmentForConst()
Return segment for read-only constant.


makeAsmSymbol

java.lang.String makeAsmSymbol(java.lang.String symbol)
Make symbol in assembly language form. Prepend '_' in case of old a.out binary.


makeLabelDef

java.lang.String makeLabelDef(java.lang.String label)
Return label definition


getMachineParams

public MachineParams getMachineParams()
Return machineParams