Class CgenSupport

java.lang.Object
  extended byCgenSupport

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

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


gcCollectNames

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


MAXINT

static final int MAXINT
See Also:
Constant Field Values

WORD_SIZE

static final int WORD_SIZE
See Also:
Constant Field Values

LOG_WORD_SIZE

static final int LOG_WORD_SIZE
See Also:
Constant Field Values

CLASSNAMETAB

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

CLASSOBJTAB

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

INTTAG

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

BOOLTAG

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

STRINGTAG

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

HEAP_START

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

DISPTAB_SUFFIX

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

METHOD_SEP

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

CLASSINIT_SUFFIX

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

PROTOBJ_SUFFIX

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

OBJECTPROTOBJ

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

INTCONST_PREFIX

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

STRCONST_PREFIX

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

BOOLCONST_PREFIX

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

EMPTYSLOT

static final int EMPTYSLOT
See Also:
Constant Field Values

LABEL

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

DEFAULT_OBJFIELDS

static final int DEFAULT_OBJFIELDS
See Also:
Constant Field Values

TAG_OFFSET

static final int TAG_OFFSET
See Also:
Constant Field Values

SIZE_OFFSET

static final int SIZE_OFFSET
See Also:
Constant Field Values

DISPTABLE_OFFSET

static final int DISPTABLE_OFFSET
See Also:
Constant Field Values

STRING_SLOTS

static final int STRING_SLOTS
See Also:
Constant Field Values

INT_SLOTS

static final int INT_SLOTS
See Also:
Constant Field Values

BOOL_SLOTS

static final int BOOL_SLOTS
See Also:
Constant Field Values

GLOBAL

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

ALIGN

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

WORD

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

ZERO

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

ACC

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

A1

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

SELF

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

T1

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

T2

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

T3

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

SP

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

FP

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

RA

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

JALR

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

JAL

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

RET

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

SW

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

LW

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

LI

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

LA

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

MOVE

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

NEG

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

ADD

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

ADDI

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

ADDU

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

ADDIU

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

DIV

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

MUL

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

SUB

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

SLL

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

BEQZ

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

BRANCH

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

BEQ

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

BNE

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

BLEQ

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

BLT

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

BGT

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

ascii

private static boolean ascii
Constructor Detail

CgenSupport

CgenSupport()
Method Detail

emitLoad

static void emitLoad(java.lang.String dest_reg,
                     int offset,
                     java.lang.String source_reg,
                     java.io.PrintStream 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

static void emitStore(java.lang.String source_reg,
                      int offset,
                      java.lang.String dest_reg,
                      java.io.PrintStream 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

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

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

emitLoadAddress

static void emitLoadAddress(java.lang.String dest_reg,
                            java.lang.String address,
                            java.io.PrintStream 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

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

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

emitLoadBool

static void emitLoadBool(java.lang.String dest_reg,
                         BoolConst b,
                         java.io.PrintStream 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

static void emitLoadString(java.lang.String dest_reg,
                           StringSymbol str,
                           java.io.PrintStream 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

static void emitLoadInt(java.lang.String dest_reg,
                        IntSymbol i,
                        java.io.PrintStream 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

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

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

emitNeg

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

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

emitAdd

static void emitAdd(java.lang.String dest_reg,
                    java.lang.String src1,
                    java.lang.String src2,
                    java.io.PrintStream 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

static void emitAddu(java.lang.String dest_reg,
                     java.lang.String src1,
                     java.lang.String src2,
                     java.io.PrintStream 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

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

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

emitDiv

static void emitDiv(java.lang.String dest_reg,
                    java.lang.String src1,
                    java.lang.String src2,
                    java.io.PrintStream 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

static void emitMul(java.lang.String dest_reg,
                    java.lang.String src1,
                    java.lang.String src2,
                    java.io.PrintStream 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

static void emitSub(java.lang.String dest_reg,
                    java.lang.String src1,
                    java.lang.String src2,
                    java.io.PrintStream 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

static void emitSll(java.lang.String dest_reg,
                    java.lang.String src1,
                    int num,
                    java.io.PrintStream 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

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

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

emitJal

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

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

emitReturn

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

Parameters:
s - the output stream

emitGCAssign

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

Parameters:
s - the output stream

emitDispTableRef

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

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

emitInitRef

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

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

emitProtObjRef

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

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

emitMethodRef

static void emitMethodRef(AbstractSymbol classname,
                          AbstractSymbol methodname,
                          java.io.PrintStream 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

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

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

emitLabelDef

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

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

emitBeqz

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

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

emitBeq

static void emitBeq(java.lang.String src1,
                    java.lang.String src2,
                    int label,
                    java.io.PrintStream 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

static void emitBne(java.lang.String src1,
                    java.lang.String src2,
                    int label,
                    java.io.PrintStream 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

static void emitBleq(java.lang.String src1,
                     java.lang.String src2,
                     int label,
                     java.io.PrintStream 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

static void emitBlt(java.lang.String src1,
                    java.lang.String src2,
                    int label,
                    java.io.PrintStream 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

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

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

emitBgti

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

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

emitBranch

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

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

emitPush

static void emitPush(java.lang.String reg,
                     java.io.PrintStream 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

static void emitFetchInt(java.lang.String dest,
                         java.lang.String source,
                         java.io.PrintStream 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

static void emitStoreInt(java.lang.String source,
                         java.lang.String dest,
                         java.io.PrintStream 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

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

Parameters:
s - the output stream

emitGCCheck

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

Parameters:
s - the output stream

asciiMode

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

Parameters:
s - the output stream

byteMode

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

Parameters:
s - the output stream

emitStringConstant

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

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