codeGeneration
Class CgenSupport

java.lang.Object
  extended by codeGeneration.CgenSupport

public class CgenSupport
extends java.lang.Object

This class aggregates all kinds of support routines and constants for the code generator; all routines are statics, so no instance of this class is even created.


Field Summary
static java.lang.String A1
           
static java.lang.String ACC
           
static java.lang.String ADD
           
static java.lang.String ADDI
           
static java.lang.String ADDIU
           
static java.lang.String ADDU
           
static java.lang.String ALIGN
           
static java.lang.String BEQ
           
static java.lang.String BEQZ
           
static java.lang.String BGT
           
static java.lang.String BLEQ
           
static java.lang.String BLT
           
static java.lang.String BNE
           
static int BOOL_SLOTS
           
static java.lang.String BOOLCONST_PREFIX
           
static java.lang.String BOOLTAG
           
static java.lang.String BRANCH
           
static java.lang.String CLASSINIT_SUFFIX
           
static java.lang.String CLASSNAMETAB
           
static java.lang.String CLASSOBJTAB
           
static int DEFAULT_OBJFIELDS
           
static java.lang.String DISPTAB_SUFFIX
           
static int DISPTABLE_OFFSET
           
static java.lang.String DIV
           
static int EMPTYSLOT
           
static java.lang.String FP
           
static java.lang.String[] gcCollectNames
          Runtime constants for controlling the garbage collector.
static java.lang.String[] gcInitNames
          Runtime constants for controlling the garbage collector.
static java.lang.String GLOBAL
           
static java.lang.String HEAP_START
           
static int INT_SLOTS
           
static java.lang.String INTCONST_PREFIX
           
static java.lang.String INTTAG
           
static java.lang.String JAL
           
static java.lang.String JALR
           
static java.lang.String LA
           
static java.lang.String LABEL
           
static java.lang.String LI
           
static int LOG_WORD_SIZE
           
static java.lang.String LW
           
static int MAXINT
           
static java.lang.String METHOD_SEP
           
static java.lang.String MOVE
           
static java.lang.String MUL
           
static java.lang.String NEG
           
static java.lang.String OBJECTPROTOBJ
           
static java.lang.String PROTOBJ_SUFFIX
           
static java.lang.String RA
           
static java.lang.String RET
           
static java.lang.String SELF
           
static int SIZE_OFFSET
           
static java.lang.String SLL
           
static java.lang.String SP
           
static java.lang.String STRCONST_PREFIX
           
static int STRING_SLOTS
           
static java.lang.String STRINGTAG
           
static java.lang.String SUB
           
static java.lang.String SW
           
static java.lang.String T1
           
static java.lang.String T2
           
static java.lang.String T3
           
static int TAG_OFFSET
           
static java.lang.String WORD
           
static int WORD_SIZE
           
static java.lang.String ZERO
           
 
Constructor Summary
CgenSupport()
           
 
Method Summary
static void asciiMode(java.io.PrintWriter s)
          Switch output mode to ASCII.
static void byteMode(java.io.PrintWriter s)
          Switch output mode to BYTE
static void emitAdd(java.lang.String dest_reg, java.lang.String src1, java.lang.String src2, java.io.PrintWriter s)
          Emits an ADD instruction.
static void emitAddiu(java.lang.String dest_reg, java.lang.String src, int imm, java.io.PrintWriter s)
          Emits an ADDIU instruction.
static void emitAddu(java.lang.String dest_reg, java.lang.String src1, java.lang.String src2, java.io.PrintWriter s)
          Emits an ADDU instruction.
static void emitBeq(java.lang.String src1, java.lang.String src2, int label, java.io.PrintWriter s)
          Emits a BEQ instruction.
static void emitBeqz(java.lang.String src, int label, java.io.PrintWriter s)
          Emits a BEQZ instruction.
static void emitBgti(java.lang.String src, int imm, int label, java.io.PrintWriter s)
          Emits a BGTI instruction.
static void emitBleq(java.lang.String src1, java.lang.String src2, int label, java.io.PrintWriter s)
          Emits a BLEQ instruction.
static void emitBlt(java.lang.String src1, java.lang.String src2, int label, java.io.PrintWriter s)
          Emits a BLT instruction.
static void emitBlti(java.lang.String src, int imm, int label, java.io.PrintWriter s)
          Emits a BLTI instruction.
static void emitBne(java.lang.String src1, java.lang.String src2, int label, java.io.PrintWriter s)
          Emits a BNE instruction.
static void emitBranch(int label, java.io.PrintWriter s)
          Emits a BRANCH instruction.
static void emitDispTableRef(AbstractSymbol sym, java.io.PrintWriter s)
          Emits a reference to dispatch table.
static void emitDiv(java.lang.String dest_reg, java.lang.String src1, java.lang.String src2, java.io.PrintWriter s)
          Emits a DIV instruction.
static void emitFetchInt(java.lang.String dest, java.lang.String source, java.io.PrintWriter s)
          Emits code to fetch the integer value of the Integer object.
static void emitGCAssign(java.io.PrintWriter s)
          Emits a call to gc_assign.
static void emitGCCheck(java.lang.String source, java.io.PrintWriter s)
          Emits code to check the garbage collector
static void emitInitRef(AbstractSymbol sym, java.io.PrintWriter s)
          Emits a reference to class' init() method.
static void emitJal(java.lang.String dest, java.io.PrintWriter s)
          Emits a JAL instruction.
static void emitJalr(java.lang.String dest_reg, java.io.PrintWriter s)
          Emits a JALR instruction.
static void emitLabelDef(int label, java.io.PrintWriter s)
          Emits a definition of a label
static void emitLabelRef(int label, java.io.PrintWriter s)
          Emits a reference to a label
static void emitLoad(java.lang.String dest_reg, int offset, java.lang.String source_reg, java.io.PrintWriter s)
          Emits an LW instruction.
static void emitLoadAddress(java.lang.String dest_reg, java.lang.String address, java.io.PrintWriter s)
          Emits an LA instruction.
static void emitLoadBool(java.lang.String dest_reg, BoolConst b, java.io.PrintWriter s)
          Emits an instruction to load a boolean constant into a register.
static void emitLoadImm(java.lang.String dest_reg, int val, java.io.PrintWriter s)
          Emits the LI instruction.
static void emitLoadInt(java.lang.String dest_reg, IntSymbol i, java.io.PrintWriter s)
          Emits an instruction to load an integer constant into a register.
static void emitLoadString(java.lang.String dest_reg, StringSymbol str, java.io.PrintWriter s)
          Emits an instruction to load a string constant into a register.
static void emitMethodRef(AbstractSymbol classname, AbstractSymbol methodname, java.io.PrintWriter s)
          Emits a reference to a method in a class
static void emitMove(java.lang.String dest_reg, java.lang.String source_reg, java.io.PrintWriter s)
          Emits a MOVE instruction.
static void emitMul(java.lang.String dest_reg, java.lang.String src1, java.lang.String src2, java.io.PrintWriter s)
          Emits a MUL instruction.
static void emitNeg(java.lang.String dest_reg, java.lang.String source_reg, java.io.PrintWriter s)
          Emits a NEG instruction.
static void emitPartialLoadAddress(java.lang.String dest_reg, java.io.PrintWriter s)
          Emits an LA instruction without the address part.
static void emitProtObjRef(AbstractSymbol sym, java.io.PrintWriter s)
          Emits a reference to class' prototype object.
static void emitPush(java.lang.String reg, java.io.PrintWriter s)
          Emit a sequence of instructions to push a register onto stack.
static void emitReturn(java.io.PrintWriter s)
          Emits a RET instruction.
static void emitSll(java.lang.String dest_reg, java.lang.String src1, int num, java.io.PrintWriter s)
          Emits an SLL instruction.
static void emitStore(java.lang.String source_reg, int offset, java.lang.String dest_reg, java.io.PrintWriter s)
          Emits an SW instruction.
static void emitStoreInt(java.lang.String source, java.lang.String dest, java.io.PrintWriter s)
          Emits code to store the integer value of the Integer object.
static void emitStringConstant(java.lang.String str, java.io.PrintWriter s)
          Emits a string constant.
static void emitSub(java.lang.String dest_reg, java.lang.String src1, java.lang.String src2, java.io.PrintWriter s)
          Emits a SUB instruction.
static void emitTestCollector(java.io.PrintWriter s)
          Emits code to manipulate garbage collector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gcInitNames

public static final java.lang.String[] gcInitNames
Runtime constants for controlling the garbage collector.


gcCollectNames

public static final java.lang.String[] gcCollectNames
Runtime constants for controlling the garbage collector.


MAXINT

public static final int MAXINT
See Also:
Constant Field Values

WORD_SIZE

public static final int WORD_SIZE
See Also:
Constant Field Values

LOG_WORD_SIZE

public static final int LOG_WORD_SIZE
See Also:
Constant Field Values

CLASSNAMETAB

public static final java.lang.String CLASSNAMETAB
See Also:
Constant Field Values

CLASSOBJTAB

public static final java.lang.String CLASSOBJTAB
See Also:
Constant Field Values

INTTAG

public static final java.lang.String INTTAG
See Also:
Constant Field Values

BOOLTAG

public static final java.lang.String BOOLTAG
See Also:
Constant Field Values

STRINGTAG

public static final java.lang.String STRINGTAG
See Also:
Constant Field Values

HEAP_START

public static final java.lang.String HEAP_START
See Also:
Constant Field Values

DISPTAB_SUFFIX

public static final java.lang.String DISPTAB_SUFFIX
See Also:
Constant Field Values

METHOD_SEP

public static final java.lang.String METHOD_SEP
See Also:
Constant Field Values

CLASSINIT_SUFFIX

public static final java.lang.String CLASSINIT_SUFFIX
See Also:
Constant Field Values

PROTOBJ_SUFFIX

public static final java.lang.String PROTOBJ_SUFFIX
See Also:
Constant Field Values

OBJECTPROTOBJ

public static final java.lang.String OBJECTPROTOBJ
See Also:
Constant Field Values

INTCONST_PREFIX

public static final java.lang.String INTCONST_PREFIX
See Also:
Constant Field Values

STRCONST_PREFIX

public static final java.lang.String STRCONST_PREFIX
See Also:
Constant Field Values

BOOLCONST_PREFIX

public static final java.lang.String BOOLCONST_PREFIX
See Also:
Constant Field Values

EMPTYSLOT

public static final int EMPTYSLOT
See Also:
Constant Field Values

LABEL

public static final java.lang.String LABEL
See Also:
Constant Field Values

DEFAULT_OBJFIELDS

public static final int DEFAULT_OBJFIELDS
See Also:
Constant Field Values

TAG_OFFSET

public static final int TAG_OFFSET
See Also:
Constant Field Values

SIZE_OFFSET

public static final int SIZE_OFFSET
See Also:
Constant Field Values

DISPTABLE_OFFSET

public static final int DISPTABLE_OFFSET
See Also:
Constant Field Values

STRING_SLOTS

public static final int STRING_SLOTS
See Also:
Constant Field Values

INT_SLOTS

public static final int INT_SLOTS
See Also:
Constant Field Values

BOOL_SLOTS

public static final int BOOL_SLOTS
See Also:
Constant Field Values

GLOBAL

public static final java.lang.String GLOBAL
See Also:
Constant Field Values

ALIGN

public static final java.lang.String ALIGN
See Also:
Constant Field Values

WORD

public static final java.lang.String WORD
See Also:
Constant Field Values

ZERO

public static final java.lang.String ZERO
See Also:
Constant Field Values

ACC

public static final java.lang.String ACC
See Also:
Constant Field Values

A1

public static final java.lang.String A1
See Also:
Constant Field Values

SELF

public static final java.lang.String SELF
See Also:
Constant Field Values

T1

public static final java.lang.String T1
See Also:
Constant Field Values

T2

public static final java.lang.String T2
See Also:
Constant Field Values

T3

public static final java.lang.String T3
See Also:
Constant Field Values

SP

public static final java.lang.String SP
See Also:
Constant Field Values

FP

public static final java.lang.String FP
See Also:
Constant Field Values

RA

public static final java.lang.String RA
See Also:
Constant Field Values

JALR

public static final java.lang.String JALR
See Also:
Constant Field Values

JAL

public static final java.lang.String JAL
See Also:
Constant Field Values

RET

public static final java.lang.String RET
See Also:
Constant Field Values

SW

public static final java.lang.String SW
See Also:
Constant Field Values

LW

public static final java.lang.String LW
See Also:
Constant Field Values

LI

public static final java.lang.String LI
See Also:
Constant Field Values

LA

public static final java.lang.String LA
See Also:
Constant Field Values

MOVE

public static final java.lang.String MOVE
See Also:
Constant Field Values

NEG

public static final java.lang.String NEG
See Also:
Constant Field Values

ADD

public static final java.lang.String ADD
See Also:
Constant Field Values

ADDI

public static final java.lang.String ADDI
See Also:
Constant Field Values

ADDU

public static final java.lang.String ADDU
See Also:
Constant Field Values

ADDIU

public static final java.lang.String ADDIU
See Also:
Constant Field Values

DIV

public static final java.lang.String DIV
See Also:
Constant Field Values

MUL

public static final java.lang.String MUL
See Also:
Constant Field Values

SUB

public static final java.lang.String SUB
See Also:
Constant Field Values

SLL

public static final java.lang.String SLL
See Also:
Constant Field Values

BEQZ

public static final java.lang.String BEQZ
See Also:
Constant Field Values

BRANCH

public static final java.lang.String BRANCH
See Also:
Constant Field Values

BEQ

public static final java.lang.String BEQ
See Also:
Constant Field Values

BNE

public static final java.lang.String BNE
See Also:
Constant Field Values

BLEQ

public static final java.lang.String BLEQ
See Also:
Constant Field Values

BLT

public static final java.lang.String BLT
See Also:
Constant Field Values

BGT

public static final java.lang.String BGT
See Also:
Constant Field Values
Constructor Detail

CgenSupport

public CgenSupport()
Method Detail

emitLoad

public static void emitLoad(java.lang.String dest_reg,
                            int offset,
                            java.lang.String source_reg,
                            java.io.PrintWriter s)
Emits an LW instruction.

Parameters:
dest_reg - the destination register
offset - the word offset from source register
source_reg - the source register
s - the output stream

emitStore

public static void emitStore(java.lang.String source_reg,
                             int offset,
                             java.lang.String dest_reg,
                             java.io.PrintWriter s)
Emits an SW instruction.

Parameters:
dest_reg - the destination register
offset - the word offset from source register
source_reg - the source register
s - the output stream

emitLoadImm

public static void emitLoadImm(java.lang.String dest_reg,
                               int val,
                               java.io.PrintWriter s)
Emits the LI instruction.

Parameters:
dest_reg - the destination register
val - the integer value
s - the output stream

emitLoadAddress

public static void emitLoadAddress(java.lang.String dest_reg,
                                   java.lang.String address,
                                   java.io.PrintWriter s)
Emits an LA instruction.

Parameters:
dest_reg - the destination register
address - the address from which a word is loaded
s - the output stream

emitPartialLoadAddress

public static void emitPartialLoadAddress(java.lang.String dest_reg,
                                          java.io.PrintWriter s)
Emits an LA instruction without the address part.

Parameters:
dest_reg - the destination register
s - the output stream

emitLoadBool

public static void emitLoadBool(java.lang.String dest_reg,
                                BoolConst b,
                                java.io.PrintWriter s)
Emits an instruction to load a boolean constant into a register.

Parameters:
dest_reg - the destination register
b - the boolean constant
s - the output stream

emitLoadString

public static void emitLoadString(java.lang.String dest_reg,
                                  StringSymbol str,
                                  java.io.PrintWriter s)
Emits an instruction to load a string constant into a register.

Parameters:
dest_reg - the destination register
str - the string constant
s - the output stream

emitLoadInt

public static void emitLoadInt(java.lang.String dest_reg,
                               IntSymbol i,
                               java.io.PrintWriter s)
Emits an instruction to load an integer constant into a register.

Parameters:
dest_reg - the destination register
i - the integer constant
s - the output stream

emitMove

public static void emitMove(java.lang.String dest_reg,
                            java.lang.String source_reg,
                            java.io.PrintWriter s)
Emits a MOVE instruction.

Parameters:
dest_reg - the destination register
source_reg - the source register
s - the output stream

emitNeg

public static void emitNeg(java.lang.String dest_reg,
                           java.lang.String source_reg,
                           java.io.PrintWriter s)
Emits a NEG instruction.

Parameters:
dest_reg - the destination register
source_reg - the source register
s - the output stream

emitAdd

public static void emitAdd(java.lang.String dest_reg,
                           java.lang.String src1,
                           java.lang.String src2,
                           java.io.PrintWriter s)
Emits an ADD instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
src2 - the source register 2
s - the output stream

emitAddu

public static void emitAddu(java.lang.String dest_reg,
                            java.lang.String src1,
                            java.lang.String src2,
                            java.io.PrintWriter s)
Emits an ADDU instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
src2 - the source register 2
s - the output stream

emitAddiu

public static void emitAddiu(java.lang.String dest_reg,
                             java.lang.String src,
                             int imm,
                             java.io.PrintWriter s)
Emits an ADDIU instruction.

Parameters:
dest_reg - the destination register
src - the source register
imm - the immediate
s - the output stream

emitDiv

public static void emitDiv(java.lang.String dest_reg,
                           java.lang.String src1,
                           java.lang.String src2,
                           java.io.PrintWriter s)
Emits a DIV instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
src2 - the source register 2
s - the output stream

emitMul

public static void emitMul(java.lang.String dest_reg,
                           java.lang.String src1,
                           java.lang.String src2,
                           java.io.PrintWriter s)
Emits a MUL instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
src2 - the source register 2
s - the output stream

emitSub

public static void emitSub(java.lang.String dest_reg,
                           java.lang.String src1,
                           java.lang.String src2,
                           java.io.PrintWriter s)
Emits a SUB instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
src2 - the source register 2
s - the output stream

emitSll

public static void emitSll(java.lang.String dest_reg,
                           java.lang.String src1,
                           int num,
                           java.io.PrintWriter s)
Emits an SLL instruction.

Parameters:
dest_reg - the destination register
src1 - the source register 1
num - the number of bits to shift
s - the output stream

emitJalr

public static void emitJalr(java.lang.String dest_reg,
                            java.io.PrintWriter s)
Emits a JALR instruction.

Parameters:
dest_reg - the register with target address
s - the output stream

emitJal

public static void emitJal(java.lang.String dest,
                           java.io.PrintWriter s)
Emits a JAL instruction.

Parameters:
dest - the target address or label
s - the output stream

emitReturn

public static void emitReturn(java.io.PrintWriter s)
Emits a RET instruction.

Parameters:
s - the output stream

emitGCAssign

public static void emitGCAssign(java.io.PrintWriter s)
Emits a call to gc_assign.

Parameters:
s - the output stream

emitDispTableRef

public static void emitDispTableRef(AbstractSymbol sym,
                                    java.io.PrintWriter s)
Emits a reference to dispatch table.

Parameters:
sym - the name of the class
s - the output stream

emitInitRef

public static void emitInitRef(AbstractSymbol sym,
                               java.io.PrintWriter s)
Emits a reference to class' init() method.

Parameters:
sym - the name of the class
s - the output stream

emitProtObjRef

public static void emitProtObjRef(AbstractSymbol sym,
                                  java.io.PrintWriter s)
Emits a reference to class' prototype object.

Parameters:
sym - the name of the class
s - the output stream

emitMethodRef

public static void emitMethodRef(AbstractSymbol classname,
                                 AbstractSymbol methodname,
                                 java.io.PrintWriter s)
Emits a reference to a method in a class

Parameters:
classname - the name of the class
methodname - the name of the method
s - the output stream

emitLabelRef

public static void emitLabelRef(int label,
                                java.io.PrintWriter s)
Emits a reference to a label

Parameters:
label - the label number
s - the output stream

emitLabelDef

public static void emitLabelDef(int label,
                                java.io.PrintWriter s)
Emits a definition of a label

Parameters:
label - the label number
s - the output stream

emitBeqz

public static void emitBeqz(java.lang.String src,
                            int label,
                            java.io.PrintWriter s)
Emits a BEQZ instruction.

Parameters:
src - the source register
label - the label number
s - the output stream

emitBeq

public static void emitBeq(java.lang.String src1,
                           java.lang.String src2,
                           int label,
                           java.io.PrintWriter s)
Emits a BEQ instruction.

Parameters:
src1 - the source register 1
src2 - the source register 2
label - the label number
s - the output stream

emitBne

public static void emitBne(java.lang.String src1,
                           java.lang.String src2,
                           int label,
                           java.io.PrintWriter s)
Emits a BNE instruction.

Parameters:
src1 - the source register 1
src2 - the source register 2
label - the label number
s - the output stream

emitBleq

public static void emitBleq(java.lang.String src1,
                            java.lang.String src2,
                            int label,
                            java.io.PrintWriter s)
Emits a BLEQ instruction.

Parameters:
src1 - the source register 1
src2 - the source register 2
label - the label number
s - the output stream

emitBlt

public static void emitBlt(java.lang.String src1,
                           java.lang.String src2,
                           int label,
                           java.io.PrintWriter s)
Emits a BLT instruction.

Parameters:
src1 - the source register 1
src2 - the source register 2
label - the label number
s - the output stream

emitBlti

public static void emitBlti(java.lang.String src,
                            int imm,
                            int label,
                            java.io.PrintWriter s)
Emits a BLTI instruction.

Parameters:
src - the source register
imm - the immediate
label - the label number
s - the output stream

emitBgti

public static void emitBgti(java.lang.String src,
                            int imm,
                            int label,
                            java.io.PrintWriter s)
Emits a BGTI instruction.

Parameters:
src - the source register
imm - the immediate
label - the label number
s - the output stream

emitBranch

public static void emitBranch(int label,
                              java.io.PrintWriter s)
Emits a BRANCH instruction.

Parameters:
label - the label number
s - the output stream

emitPush

public static void emitPush(java.lang.String reg,
                            java.io.PrintWriter s)
Emit a sequence of instructions to push a register onto stack. Stack grows toward smaller addresses.

Parameters:
reg - the register
s - the output stream

emitFetchInt

public static void emitFetchInt(java.lang.String dest,
                                java.lang.String source,
                                java.io.PrintWriter s)
Emits code to fetch the integer value of the Integer object.

Parameters:
source - a pointer to the Integer object
dest - the destination register for the value
s - the output stream

emitStoreInt

public static void emitStoreInt(java.lang.String source,
                                java.lang.String dest,
                                java.io.PrintWriter s)
Emits code to store the integer value of the Integer object.

Parameters:
source - an integer value
dest - the pointer to an Integer object
s - the output stream

emitTestCollector

public static void emitTestCollector(java.io.PrintWriter s)
Emits code to manipulate garbage collector

Parameters:
s - the output stream

emitGCCheck

public static void emitGCCheck(java.lang.String source,
                               java.io.PrintWriter s)
Emits code to check the garbage collector

Parameters:
s - the output stream

asciiMode

public static void asciiMode(java.io.PrintWriter s)
Switch output mode to ASCII.

Parameters:
s - the output stream

byteMode

public static void byteMode(java.io.PrintWriter s)
Switch output mode to BYTE

Parameters:
s - the output stream

emitStringConstant

public static void emitStringConstant(java.lang.String str,
                                      java.io.PrintWriter s)
Emits a string constant.

Parameters:
str - the string constant
s - the output stream