scale.backend
Class Generator

java.lang.Object
  |
  +--scale.backend.Generator
All Implemented Interfaces:
Predicate
Direct Known Subclasses:
AlphaGenerator, MipsGenerator, PPCGenerator, SparcGenerator

public abstract class Generator
extends java.lang.Object
implements Predicate

This class is the base class for code generators.

$Id: Generator.java,v 1.35 2002/01/03 21:41:30 burrill Exp $

Copyright 2002 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

A generator translates Scribble CFGs into a linear sequence of machine instructions.


Field Summary
protected static int ADD
          Add operation
protected static int ALIGNED
          Item in memory has been aligned on the proper boundary.
protected static int AND
          Bit and operation
protected static int[] argswap
          Map comparison if the arguments are swapped.
protected static int[] brreverse
          Map comparison if branch sense is reversed.
protected  HashMap codeMap
          Map from routine to instructions.
protected static boolean[] commutative
          Is the dyadic operation commutative?
protected static java.lang.String[] compOp
          Map comparison to string.
protected  Displacement[] dataAreaDisp
          Array of data area displacements - indexed by handle.
protected  SpaceAllocation[] dataAreas
          Array of data areas - indexed by handle.
protected static byte DECL_IN_COMMON
          The variable is an EquivalenceDecl.
protected static byte DECL_IN_MEMORY
          The variable is in memory.
protected static byte DECL_IN_REGISTER
          The variable is in a register.
protected static byte DECL_ON_STACK
          The variable is on the stack.
protected static java.lang.String[] declLoc
          Map from variable location to descriptive string.
protected static int DIV
          Divide operation
protected static int EQ
          Equality compare
protected static int[] fieldAlignment
          Map from lower three bits of an offset to the alignment.
protected static int GE
          Greater than or equal compare
protected  boolean genDebugInfo
          True if information for debuggers should be generated.
protected static int GT
          Greater than compare
protected  Instruction lastInstruction
          Last instruction generated.
protected  Label lastLabel
          Last label generated.
protected static int LE
          Less than or equal compare
protected  boolean little
          True if target machine is little-endian.
protected static int LT
          Less than compare
protected  Machine machine
          Machine specific information.
protected static int MUL
          Multiply operation
protected static int NE
          Not equals compare
protected  int nextArea
          Next available in dataAreas.
protected static java.lang.String[] operation
          Map operation to string.
protected static int OR
          Bit or operation
protected  RegisterSet registers
          The register set definition.
protected  int resultReg
          Register containing the last generated expression result.
protected static int SLL
          Shift left logical operation
protected static int SRA
          Shift right arithmetic operation
protected static int SRL
          Shift right logical operation
protected static int SUB
          Subtract operation
protected  boolean trace
          True if tracing requested.
protected static java.lang.String[] trans2Names
          Names of the C library dyadic transcendental functions.
protected static java.lang.String[] transNames
          Names of the C library monadic transcendental functions.
protected static int UNALIGNED
          Item in memory has not been aligned on the proper boundary.
protected  boolean useMemory
          True if programmer variables should be placed in memory.
protected static int XOR
          Bit exclusive or operation
 
Constructor Summary
Generator(CallGraph cg, RegisterSet actualRegisters, Machine machine, boolean genDebugInfo)
          This class is used to convert the Scribble CFG to machine instructions.
 
Method Summary
protected abstract  Displacement allocAggregationElements(AggregationElements ag)
          Place values from an AggregationElements literal in read-only memory.
protected  int allocateBSSArea(java.lang.String name, int area, int size, int alignment)
          Allocate an uninitialized area of memory.
protected  int allocateData(java.lang.String name, int area, int type, int size, boolean readOnly, java.lang.Object data, int reps)
          Allocate an area of memory to contain data.
protected  int allocateData(java.lang.String name, int area, int type, int size, boolean readOnly, java.lang.Object data, int reps, int alignment)
          Allocate an area of memory to contain data.
protected  int allocateTextArea(java.lang.String name, int area)
          Allocate an area of memory to contain instructions.
protected  int allocateWithData(java.lang.String name, Type type, int ts, AggregationElements ag, int area, boolean readOnly, int repeats)
          Allocate an area for the data specified by the Clef AggregationElements expression.
protected  int allocateWithData(java.lang.String name, Type type, int ts, Expression init, int area, boolean readOnly, int reps, int aln)
          Allocate an area for the data specified by the Clef Expression.
protected  void appendInstruction(Instruction inst)
          Append the instruction to the end of the sequence of instructions.
protected  void appendLabel(Label label)
          Append the label to the end of the sequence of instructions.
abstract  void assemble(Emit emit, java.lang.String source, java.util.Enumeration comments)
          Generate assembly language.
 void associateDispWithArea(int handle, Displacement disp)
          Associate a displacement with an area.
 void basicBlockEnd()
          Called after the last CFG node in a basic block is processed.
protected abstract  void calcFieldOffsets(AggregateType at)
          Determine the offsets for fields of a struct or union.
protected abstract  void convertIntRegValue(int src, int srcSize, boolean srcSigned, int dest, int destSize, boolean destSigned)
          Generate instructions to convert an integer value in an integer register to an integer value of a different size.
protected  Label createLabel()
          Create a new Label.
abstract  int dataType(Type type)
          Return the data type as an integer.
protected abstract  void declPass1(Declaration decl, boolean topLevel)
          Process the declarations.
protected  int defineDeclInfo(Declaration decl, byte type, int info, int info2, int info3, Displacement disp)
          Associate information with a Declaration.
protected abstract  Displacement defStringValue(java.lang.String v, int size)
          Return the displacement for a string.
protected abstract  void doBinaryOp(BinaryExpr c, int which)
          Generate instructions to do a comparison of two value.
protected abstract  void doCompareOp(BinaryExpr c, int which)
          Generate instructions to do a comparison of two value.
protected  boolean doNext(Chord nxt)
          Make sure the specified Chord is converted next.
protected  void endModule()
          Called at the end of a call graph (module).
protected abstract  void endRoutineCode(int[] map)
          Called at the end of code generation for a routine.
 Displacement findAreaDisp(int section, int type, boolean readOnly, int size, double value, int alignment)
          Find an allocation of a floating point value.
 Displacement findAreaDisp(int section, int type, boolean readOnly, int size, long value, int alignment)
          Find an allocation of a floating point value.
 Displacement findAreaDisp(int section, int type, boolean readOnly, int size, java.lang.String value, int alignment)
          Find an allocation of a floating point value.
 void generate()
          Generate the machine instructions for each routine in the call graph.
protected  void generateScribble(Scribble scribble)
          Generate the machine instructions for a CFG.
protected abstract  void generateUnconditionalBranch(Label lab)
          Generate an unconditional branch to the label specified.
protected abstract  void genFloorOfReal(int src, int srcSize, int dest, int destSize)
          Generate instructions to compute the floor of a real vaue in a real register to a real register.
protected abstract  void genIfRegister(int which, Expr predicate, Chord tc, Chord fc)
          Generate a branch based on the value of an expression.
protected abstract  void genIfRelational(int which, boolean rflag, BinaryExpr predicate, Chord tc, Chord fc)
          Generate a branch based on a relational expression.
protected abstract  void genIntToReal(int src, int srcSize, int dest, int destSize)
          Convert an integer value in a real register to a real value in a real register.
protected abstract  int genLoadImmediate(double value, int dest, int destSize)
          Generate instructions to load an immediate integer value into a register.
protected abstract  int genLoadImmediate(long value, int dest)
          Generate instructions to load an immediate integer value into a register.
protected abstract  void genRealToInt(int src, int srcSize, int dest, int destSize, boolean destSigned)
          Convert real value in a real register to an integer value in a real register.
protected abstract  void genRealToIntRound(int src, int srcSize, int dest, int destSize)
          Convert integer value in a real register to an integer value in a real register.
protected abstract  void genRealToReal(int src, int srcSize, int dest, int destSize)
          Convert a real value in a real register to a real value in a real register.
protected abstract  void genRegToReg(int src, int dest)
          Generate instructions to move data from one register to another.
protected abstract  void genUnsignedIntToReal(int src, int srcSize, int dest, int destSize)
          Convert an unsigned integer value in an integer register to a real value in a real register.
protected  Label getBranchLabel(Chord location)
          Return the label for a branch location.
protected  Displacement getDeclDisp(int index)
          Return the Displacement associated with the Declaration.
protected  int getDeclInfo(int index)
          Return the first integer value associated with the Declaration.
protected  int getDeclInfo2(int index)
          Return the second integer value associated with the Declaration.
protected  int getDeclInfo3(int index)
          Return the third integer value associated with the Declaration.
protected  int getDeclType(int index)
          Return the type value associated with the Declaration.
protected  Displacement getDisp(int value)
          Generate an integer displacement.
 Label getLabel(int index)
          Return the label whose index is specified.
 Machine getMachine()
          Return the machine definition in use.
abstract  int getMaxAreaIndex()
          Return the maximum area index value.
 java.lang.String getName(int handle)
          Return the name associated with an area of memory.
 SourceLanguage getSourceLanguage()
          Return the source language of the original program.
protected abstract  java.lang.Object getSpillLocation(int reg)
          Obtain the information needed for register spill loads and stores.
protected  Instruction insertInstruction(Instruction inst, Instruction location)
          Insert the instruction after the specified instruction.
protected abstract  Instruction insertSpillLoad(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to restore a spilled register.
protected abstract  Instruction insertSpillStore(int reg, java.lang.Object spillLocation, Instruction after)
          Insert the instruction(s) to save a spilled register.
protected abstract  void layoutParameters(RoutineDecl rd)
          Determine the layout of routine parameters for the call.
protected abstract  void loadAddress(int dest, Displacement disp)
          Load an address into a register.
protected abstract  int loadValue(VariableDecl vd, Type vt)
          Load the value of a variable into a register.
protected  void moveInstructionSequence(Instruction prior, Instruction last, Instruction after)
          Move a sequence of instructions to another position.
protected  void peephole(Instruction first)
          Do peephole optimizations before registers are allocated.
protected  void peephole2(Instruction first)
          Do peephole optimizations after registers are allocated.
static int powerOf2(long value)
          Return x in (value = 2**x) or -1 if value is zero, negative or not a power of two.
protected abstract  void processSourceLine(java.lang.String fileName, int line, int column, int label)
          The user has requested source line information be included.
protected  Type processType(Declaration decl)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Expr expr)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Expression expr)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected  Type processType(Type type)
          Insure that all types have their register types specified and all structure fields have had their offsets determined.
protected abstract  void putAddressInRegister(Declaration decl, int adrReg)
          Put the address of the declaration into a register.
protected abstract  void putAddressInRegister(Declaration decl, int dtype, Displacement disp, int adrReg)
          Load the address of a declaration into a register.
protected  boolean putInRegister(Declaration decl)
          Return true if the declaration is a good candidate for residency in a register.
 java.lang.String registerName(int reg)
          Return the assembler name for the specified register.
 void remapRegisters(int[] map, Instruction first)
          Change the registers in every instruction.
protected  void setDeclInfo3(int index, int value)
          Set the third integer value associated with the Declaration.
protected  void setVisibility(int handle, byte visibility)
          Specify the visibility of an area.
protected  void startModule()
          Called at the beginning of a call graph (module).
protected abstract  Instruction startRoutineCode()
          Called at the start of code generation for a routine.
protected abstract  void storeLdae(LoadDeclAddressExpr lhs, Expr rhs)
          Store a value into a variable.
protected abstract  void storeLdve(LoadDeclValueExpr lhs, Expr rhs)
          Store a value into the location specied by an address in a variable.
protected abstract  void storeLfae(LoadFieldAddressExpr lhs, Expr rhs)
          Store a value into a field of a structure.
protected abstract  void storeLvie(LoadValueIndirectExpr lhs, Expr rhs)
          Store a value into the location specied by the value of an expression.
protected abstract  void storeValue(int src, VariableDecl vd, Type vt)
          Store a variable value into memory from a register.
protected  int valueOf(SizeofLiteral il)
          Return the value of the SizeofLiteral.
 void visitAdditionExpr(Note n)
           
 void visitAllocateExpr(Note n)
           
 void visitAndExpr(Note n)
           
 void visitBinaryExpr(Note n)
           
 void visitBitAndExpr(Note n)
           
 void visitBitOrExpr(Note n)
           
 void visitBitShiftExpr(Note n)
           
 void visitBitXorExpr(Note n)
           
 void visitBranchChord(Note n)
           
 void visitCallExpr(Note n)
           
 void visitCallMethodExpr(Note n)
           
 void visitChord(Note n)
           
 void visitComplexValueExpr(Note n)
           
 void visitConversionExpr(Note n)
           
 void visitDecisionChord(Note n)
           
 void visitDualExpr(Note n)
           
 void visitEqualityExpr(Note n)
           
 void visitEvictChord(Note n)
           
 void visitExpr(Note n)
           
 void visitExprChord(Note n)
           
 void visitExprPhiExpr(Note n)
           
 void visitGotoChord(Note n)
           
 void visitGreaterEqualExpr(Note n)
           
 void visitGreaterExpr(Note n)
           
 void visitIfThenElseChord(Note n)
           
 void visitLeaveChord(Note n)
           
 void visitLessEqualExpr(Note n)
           
 void visitLessExpr(Note n)
           
 void visitLiteralExpr(Note n)
           
 void visitLoadExpr(Note n)
           
 void visitLoopExitChord(Note n)
           
 void visitLoopHeaderChord(Note n)
           
 void visitLoopPreHeaderChord(Note n)
           
 void visitLoopTailChord(Note n)
           
 void visitMaxExpr(Note n)
           
 void visitMayDefExpr(Note n)
           
 void visitMayUseExpr(Note n)
           
 void visitMinExpr(Note n)
           
 void visitNaryExpr(Note n)
           
 void visitNilExpr(Note n)
           
 void visitNote(Note n)
           
 void visitNotEqualExpr(Note n)
           
 void visitNullChord(Note n)
           
 void visitOrExpr(Note n)
           
 void visitPhiExpr(Note n)
           
 void visitPhiExprChord(Note n)
           
 void visitSequentialChord(Note n)
           
 void visitStoreExpr(Note n)
           
 void visitSubscriptExpr(Note n)
           
 void visitSubtractionExpr(Note n)
           
 void visitTernaryExpr(Note n)
           
 void visitUnaryExpr(Note n)
           
 void visitVaEndExpr(Note n)
           
 void visitValueExpr(Note n)
           
 void visitVarArgExpr(Note n)
           
 void visitVaStartExpr(Note n)
           
 void visitVectorExpr(Note n)
           
protected  void whatIsThis(Note n)
          Generate an error.
protected abstract  void zeroFloatRegister(int dest, int destSize)
          Generate code to zero out a floating point register.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scale.score.Predicate
visitAbsoluteValueExpr, visitArrayIndexExpr, visitBeginChord, visitBitComplementExpr, visitCallFunctionExpr, visitCompareExpr, visitDivisionExpr, visitEndChord, visitExitChord, visitExponentiationExpr, visitLoadDeclAddressExpr, visitLoadDeclValueExpr, visitLoadFieldAddressExpr, visitLoadFieldValueExpr, visitLoadValueIndirectExpr, visitMultiplicationExpr, visitNegativeExpr, visitNotExpr, visitRemainderExpr, visitReturnChord, visitSwitchChord, visitTranscendental2Expr, visitTranscendentalExpr, visitVaArgExpr
 

Field Detail

DECL_IN_MEMORY

protected static final byte DECL_IN_MEMORY
The variable is in memory.

DECL_IN_COMMON

protected static final byte DECL_IN_COMMON
The variable is an EquivalenceDecl.

DECL_ON_STACK

protected static final byte DECL_ON_STACK
The variable is on the stack.

DECL_IN_REGISTER

protected static final byte DECL_IN_REGISTER
The variable is in a register.

declLoc

protected static final java.lang.String[] declLoc
Map from variable location to descriptive string.

EQ

protected static final int EQ
Equality compare
See Also:
argswap, brreverse

LE

protected static final int LE
Less than or equal compare
See Also:
argswap, brreverse

LT

protected static final int LT
Less than compare
See Also:
argswap, brreverse

GT

protected static final int GT
Greater than compare
See Also:
argswap, brreverse

GE

protected static final int GE
Greater than or equal compare
See Also:
argswap, brreverse

NE

protected static final int NE
Not equals compare
See Also:
argswap, brreverse

argswap

protected static final int[] argswap
Map comparison if the arguments are swapped.

brreverse

protected static final int[] brreverse
Map comparison if branch sense is reversed.

compOp

protected static final java.lang.String[] compOp
Map comparison to string.

ALIGNED

protected static final int ALIGNED
Item in memory has been aligned on the proper boundary.

UNALIGNED

protected static final int UNALIGNED
Item in memory has not been aligned on the proper boundary.

ADD

protected static final int ADD
Add operation
See Also:
commutative

SUB

protected static final int SUB
Subtract operation
See Also:
commutative

MUL

protected static final int MUL
Multiply operation
See Also:
commutative

DIV

protected static final int DIV
Divide operation
See Also:
commutative

AND

protected static final int AND
Bit and operation
See Also:
commutative

OR

protected static final int OR
Bit or operation
See Also:
commutative

XOR

protected static final int XOR
Bit exclusive or operation
See Also:
commutative

SRA

protected static final int SRA
Shift right arithmetic operation
See Also:
commutative

SRL

protected static final int SRL
Shift right logical operation
See Also:
commutative

SLL

protected static final int SLL
Shift left logical operation
See Also:
commutative

commutative

protected static final boolean[] commutative
Is the dyadic operation commutative?

operation

protected static final java.lang.String[] operation
Map operation to string.

fieldAlignment

protected static int[] fieldAlignment
Map from lower three bits of an offset to the alignment.

transNames

protected static final java.lang.String[] transNames
Names of the C library monadic transcendental functions.

trans2Names

protected static final java.lang.String[] trans2Names
Names of the C library dyadic transcendental functions.

genDebugInfo

protected boolean genDebugInfo
True if information for debuggers should be generated.

trace

protected boolean trace
True if tracing requested.

lastInstruction

protected Instruction lastInstruction
Last instruction generated.

lastLabel

protected Label lastLabel
Last label generated.

registers

protected RegisterSet registers
The register set definition.

dataAreas

protected SpaceAllocation[] dataAreas
Array of data areas - indexed by handle.

dataAreaDisp

protected Displacement[] dataAreaDisp
Array of data area displacements - indexed by handle.

nextArea

protected int nextArea
Next available in dataAreas.

codeMap

protected HashMap codeMap
Map from routine to instructions.

machine

protected Machine machine
Machine specific information.

little

protected boolean little
True if target machine is little-endian.

useMemory

protected boolean useMemory
True if programmer variables should be placed in memory.

resultReg

protected int resultReg
Register containing the last generated expression result. It is very important that the register returned as a result of a visit NEVER be used as the destination of any instruction; It may be the register containing a variable. And, if a source register must be used in multiple instructions, the destination register must not be used for intermediate values.
Constructor Detail

Generator

public Generator(CallGraph cg,
                 RegisterSet actualRegisters,
                 Machine machine,
                 boolean genDebugInfo)
This class is used to convert the Scribble CFG to machine instructions.
Parameters:
cg - is the call graph to be used
actualRegisters - is the register set definition to be used
genDebugInfo - is true if debugging information should be placed in the object module
Method Detail

getMachine

public Machine getMachine()
Return the machine definition in use.

generate

public void generate()
Generate the machine instructions for each routine in the call graph.

startModule

protected void startModule()
Called at the beginning of a call graph (module).

endModule

protected void endModule()
Called at the end of a call graph (module).

generateScribble

protected void generateScribble(Scribble scribble)
Generate the machine instructions for a CFG.

doNext

protected boolean doNext(Chord nxt)
Make sure the specified Chord is converted next. If the Chord has already been processed, the method returns the value false.
Returns:
true if the specified Chord will be processed next

basicBlockEnd

public void basicBlockEnd()
Called after the last CFG node in a basic block is processed.

remapRegisters

public void remapRegisters(int[] map,
                           Instruction first)
Change the registers in every instruction.
Parameters:
map - is the mapping from old register number to new register number
first - is the first instruction in the sequence

peephole

protected void peephole(Instruction first)
Do peephole optimizations before registers are allocated.

peephole2

protected void peephole2(Instruction first)
Do peephole optimizations after registers are allocated.

getSpillLocation

protected abstract java.lang.Object getSpillLocation(int reg)
Obtain the information needed for register spill loads and stores. The Object returned will probably specify a memory location. It will be passed to getSpillLoad() and getSpillStore().
Parameters:
reg - specifies which virtual register will be spilled

insertSpillLoad

protected abstract Instruction insertSpillLoad(int reg,
                                               java.lang.Object spillLocation,
                                               Instruction after)
Insert the instruction(s) to restore a spilled register. At this point, we are using a one-to-one mapping between real registers and virtual registers, so only a single instruction is required.
Parameters:
reg - specifies which virtual register will be loaded
spillLocation - specifies the offset on the stack to the spill location
after - specifies the instruction to insert the load after
Returns:
the last instruction inserted
See Also:
getSpillLocation(int)

insertSpillStore

protected abstract Instruction insertSpillStore(int reg,
                                                java.lang.Object spillLocation,
                                                Instruction after)
Insert the instruction(s) to save a spilled register. At this point, we are using a one-to-one mapping between real registers and virtual registers, so only a single instruction is required.
Parameters:
reg - specifies which virtual register will be stored
spillLocation - specifies the offset on the stack to the spill location
after - specifies the instruction to insert the store after
Returns:
the last instruction inserted
See Also:
getSpillLocation(int)

assemble

public abstract void assemble(Emit emit,
                              java.lang.String source,
                              java.util.Enumeration comments)
Generate assembly language.
Parameters:
emit - is the stream to use.
source - is the source file name
comments - is a list of Strings containing comments

generateUnconditionalBranch

protected abstract void generateUnconditionalBranch(Label lab)
Generate an unconditional branch to the label specified.

processSourceLine

protected abstract void processSourceLine(java.lang.String fileName,
                                          int line,
                                          int column,
                                          int label)
The user has requested source line information be included.

startRoutineCode

protected abstract Instruction startRoutineCode()
Called at the start of code generation for a routine.

endRoutineCode

protected abstract void endRoutineCode(int[] map)
Called at the end of code generation for a routine.

layoutParameters

protected abstract void layoutParameters(RoutineDecl rd)
Determine the layout of routine parameters for the call.

calcFieldOffsets

protected abstract void calcFieldOffsets(AggregateType at)
Determine the offsets for fields of a struct or union.

storeLdae

protected abstract void storeLdae(LoadDeclAddressExpr lhs,
                                  Expr rhs)
Store a value into a variable.
Parameters:
lhs - specifies the variable
rhs - specifies the value

storeLdve

protected abstract void storeLdve(LoadDeclValueExpr lhs,
                                  Expr rhs)
Store a value into the location specied by an address in a variable.
Parameters:
lhs - specifies the variable
rhs - specifies the value

storeLvie

protected abstract void storeLvie(LoadValueIndirectExpr lhs,
                                  Expr rhs)
Store a value into the location specied by the value of an expression.
Parameters:
lhs - specifies the expression
rhs - specifies the value

storeLfae

protected abstract void storeLfae(LoadFieldAddressExpr lhs,
                                  Expr rhs)
Store a value into a field of a structure.
Parameters:
lhs - specifies the field of the structure
rhs - specifies the value

loadValue

protected abstract int loadValue(VariableDecl vd,
                                 Type vt)
Load the value of a variable into a register. If the value can not be loaded into a register, return the 2's complement of the register containing the address of the data.
Parameters:
vd - specifies the variable
vt - specifies the type of the value
Returns:
the register into which the variable value is loaded

storeValue

protected abstract void storeValue(int src,
                                   VariableDecl vd,
                                   Type vt)
Store a variable value into memory from a register.
Parameters:
src - is the source register containing the value
vd - specifies the variable
vt - specifies the type of the value

putAddressInRegister

protected abstract void putAddressInRegister(Declaration decl,
                                             int dtype,
                                             Displacement disp,
                                             int adrReg)
Load the address of a declaration into a register.
Parameters:
decl - specifies the declaration
dtype - specifies where the declaration resides
disp - specifies the declaration displacement
adrReg - specifies the register to receive the address

defStringValue

protected abstract Displacement defStringValue(java.lang.String v,
                                               int size)
Return the displacement for a string.
Parameters:
v - is the string
size - is the length of the string

putAddressInRegister

protected abstract void putAddressInRegister(Declaration decl,
                                             int adrReg)
Put the address of the declaration into a register.

loadAddress

protected abstract void loadAddress(int dest,
                                    Displacement disp)
Load an address into a register.
Parameters:
dest - is the register that is set with the address
disp - specifies the address (should be a SymbolDisplacement or offset of one)

genLoadImmediate

protected abstract int genLoadImmediate(long value,
                                        int dest)
Generate instructions to load an immediate integer value into a register.
Parameters:
value - is the value to load
dest - is the register conatining the result
Returns:
the register containing the value (usually dest but may be a hardware zero register)

genLoadImmediate

protected abstract int genLoadImmediate(double value,
                                        int dest,
                                        int destSize)
Generate instructions to load an immediate integer value into a register.
Parameters:
value - is the value to load
dest - is the register conatining the result
destSize - is the size of the value
Returns:
the register containing the value (usually dest but may be a hardware zero register)

dataType

public abstract int dataType(Type type)
Return the data type as an integer.
Parameters:
type - is the type of the data
Returns:
the data type as an integer
See Also:
SpaceAllocation

genRegToReg

protected abstract void genRegToReg(int src,
                                    int dest)
Generate instructions to move data from one register to another. If one is an integer register and the other is a floating point register, a memory location may be required.
Parameters:
src - specifies the source register
dest - specifies the destination register

genIfRegister

protected abstract void genIfRegister(int which,
                                      Expr predicate,
                                      Chord tc,
                                      Chord fc)
Generate a branch based on the value of an expression.
Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

genIfRelational

protected abstract void genIfRelational(int which,
                                        boolean rflag,
                                        BinaryExpr predicate,
                                        Chord tc,
                                        Chord fc)
Generate a branch based on a relational expression.
Parameters:
which - specifies the branch test (EQ, NE, LT, ...)
rflag - true if the test condition should be reversed
predicate - specifies the relational expression
tc - specifies the path if the test succeeds
fc - specifies the path if the test fails

doBinaryOp

protected abstract void doBinaryOp(BinaryExpr c,
                                   int which)
Generate instructions to do a comparison of two value.
Parameters:
c - is the binary expression
which - specifies the binary operation (ADD, SUB, ...)

doCompareOp

protected abstract void doCompareOp(BinaryExpr c,
                                    int which)
Generate instructions to do a comparison of two value.
Parameters:
c - is the compare expression
which - specifies the compare (EQ, NE, ...)

getMaxAreaIndex

public abstract int getMaxAreaIndex()
Return the maximum area index value.

declPass1

protected abstract void declPass1(Declaration decl,
                                  boolean topLevel)
Process the declarations.
Parameters:
decl - is the declaration
topLevel - is true if this declaration is defined outside of a routine

getDisp

protected final Displacement getDisp(int value)
Generate an integer displacement. Reuse an exisiting one if possible.
Parameters:
value - specifies the value of the displacement
Returns:
the displacement

processType

protected Type processType(Type type)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).
Returns:
the core type

processType

protected Type processType(Declaration decl)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).
Returns:
the core type

processType

protected Type processType(Expr expr)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).
Returns:
the core type

processType

protected Type processType(Expression expr)
Insure that all types have their register types specified and all structure fields have had their offsets determined. The tag field of the Type is set to the register type required to hold an element of that type (or its address).
Returns:
the core type

appendInstruction

protected void appendInstruction(Instruction inst)
Append the instruction to the end of the sequence of instructions.

appendLabel

protected void appendLabel(Label label)
Append the label to the end of the sequence of instructions. Record the last Label appended.`

insertInstruction

protected Instruction insertInstruction(Instruction inst,
                                        Instruction location)
Insert the instruction after the specified instruction.
Returns:
the instruction inserted

moveInstructionSequence

protected void moveInstructionSequence(Instruction prior,
                                       Instruction last,
                                       Instruction after)
Move a sequence of instructions to another position. If the position (after) is null, the instructions are deleted
Parameters:
prior - is the instruction prior to the first instruction in the sequence
last - is the last instruction in the sequence
after - is the instruction to insert the sequence after

putInRegister

protected boolean putInRegister(Declaration decl)
Return true if the declaration is a good candidate for residency in a register.

registerName

public java.lang.String registerName(int reg)
Return the assembler name for the specified register.

createLabel

protected Label createLabel()
Create a new Label.

getLabel

public Label getLabel(int index)
Return the label whose index is specified.

getBranchLabel

protected Label getBranchLabel(Chord location)
Return the label for a branch location.

defineDeclInfo

protected int defineDeclInfo(Declaration decl,
                             byte type,
                             int info,
                             int info2,
                             int info3,
                             Displacement disp)
Associate information with a Declaration. A unique integer value is set into the declaration label. This value can be used to retrieve the information supplied.
Parameters:
type - - memory, stack, or register
info - - handle, offset, or register number
info2 - - integer value associated with declaration
info3 - - integer value associated with declaration
Returns:
the index of the information
See Also:
getDeclDisp(int), getDeclType(int), getDeclInfo(int), getDeclInfo2(int), getDeclInfo3(int)

getDeclType

protected int getDeclType(int index)
Return the type value associated with the Declaration.

getDeclInfo

protected int getDeclInfo(int index)
Return the first integer value associated with the Declaration.

getDeclInfo2

protected int getDeclInfo2(int index)
Return the second integer value associated with the Declaration.

getDeclInfo3

protected int getDeclInfo3(int index)
Return the third integer value associated with the Declaration.

setDeclInfo3

protected void setDeclInfo3(int index,
                            int value)
Set the third integer value associated with the Declaration.

getDeclDisp

protected Displacement getDeclDisp(int index)
Return the Displacement associated with the Declaration.

findAreaDisp

public Displacement findAreaDisp(int section,
                                 int type,
                                 boolean readOnly,
                                 int size,
                                 double value,
                                 int alignment)
Find an allocation of a floating point value. Return the Displacement or null if not found.
Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

findAreaDisp

public Displacement findAreaDisp(int section,
                                 int type,
                                 boolean readOnly,
                                 int size,
                                 long value,
                                 int alignment)
Find an allocation of a floating point value. Return the Displacement or null if not found.
Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

findAreaDisp

public Displacement findAreaDisp(int section,
                                 int type,
                                 boolean readOnly,
                                 int size,
                                 java.lang.String value,
                                 int alignment)
Find an allocation of a floating point value. Return the Displacement or null if not found.
Parameters:
section - specifies the section in which the loader should place the area
type - specifies the type of data
readOnly - is true if the area is read-only
size - is the number of addressable units required
value - is the initial data value for the area
alignment - specifies the address alignment required
Returns:
the index of the area
See Also:
SpaceAllocation

associateDispWithArea

public void associateDispWithArea(int handle,
                                  Displacement disp)
Associate a displacement with an area.

setVisibility

protected void setVisibility(int handle,
                             byte visibility)
Specify the visibility of an area.
See Also:
SpaceAllocation

valueOf

protected int valueOf(SizeofLiteral il)
Return the value of the SizeofLiteral.

allocateWithData

protected int allocateWithData(java.lang.String name,
                               Type type,
                               int ts,
                               Expression init,
                               int area,
                               boolean readOnly,
                               int reps,
                               int aln)
Allocate an area for the data specified by the Clef Expression.
Parameters:
name - is the name of the data
type - is the type of the variable
ts - is the size of the area to allocate
init - is the initial value
area - is the data area to use
readOnly - is true if the data should be read-only
reps - is the number os times to repeat the data to fill the area
aln - is the required alignment for the data
Returns:
data area handle

allocateWithData

protected int allocateWithData(java.lang.String name,
                               Type type,
                               int ts,
                               AggregationElements ag,
                               int area,
                               boolean readOnly,
                               int repeats)
Allocate an area for the data specified by the Clef AggregationElements expression.
Parameters:
name - is the name of the data
type - is the type of the variable
ts - is the size of the area to allocate
init - is the initial value
area - is the data area to use
readOnly - is true if the data should be read-only
reps - is the number os times to repeat the data to fill the area
Returns:
data area handle

allocateBSSArea

protected int allocateBSSArea(java.lang.String name,
                              int area,
                              int size,
                              int alignment)
Allocate an uninitialized area of memory.
Returns:
the area's handle

allocateTextArea

protected int allocateTextArea(java.lang.String name,
                               int area)
Allocate an area of memory to contain instructions.
Returns:
the area's handle

allocateData

protected int allocateData(java.lang.String name,
                           int area,
                           int type,
                           int size,
                           boolean readOnly,
                           java.lang.Object data,
                           int reps)
Allocate an area of memory to contain data.
Parameters:
name - is the name of the area
area - specifies the data area
type - specifies the type of data
data - is the data
size - is the size of each data item in bytes
readOnly - is true if the data is read-only
Returns:
the area's handle

allocateData

protected int allocateData(java.lang.String name,
                           int area,
                           int type,
                           int size,
                           boolean readOnly,
                           java.lang.Object data,
                           int reps,
                           int alignment)
Allocate an area of memory to contain data.
Parameters:
name - is the name of the area
area - specifies the data area
type - specifies the type of data
data - is the data
size - is the size of each data item in bytes
readOnly - is true if the data is read-only
Returns:
the area's handle

getName

public java.lang.String getName(int handle)
Return the name associated with an area of memory.

getSourceLanguage

public final SourceLanguage getSourceLanguage()
Return the source language of the original program.

whatIsThis

protected void whatIsThis(Note n)
Generate an error.

powerOf2

public static int powerOf2(long value)
Return x in (value = 2**x) or -1 if value is zero, negative or not a power of two.

visitExprChord

public void visitExprChord(Note n)
Specified by:
visitExprChord in interface Predicate

visitIfThenElseChord

public void visitIfThenElseChord(Note n)
Specified by:
visitIfThenElseChord in interface Predicate

visitAdditionExpr

public void visitAdditionExpr(Note n)
Specified by:
visitAdditionExpr in interface Predicate

visitAndExpr

public void visitAndExpr(Note n)
Specified by:
visitAndExpr in interface Predicate

visitBitAndExpr

public void visitBitAndExpr(Note n)
Specified by:
visitBitAndExpr in interface Predicate

visitBitOrExpr

public void visitBitOrExpr(Note n)
Specified by:
visitBitOrExpr in interface Predicate

visitBitXorExpr

public void visitBitXorExpr(Note n)
Specified by:
visitBitXorExpr in interface Predicate

visitOrExpr

public void visitOrExpr(Note n)
Specified by:
visitOrExpr in interface Predicate

visitSubtractionExpr

public void visitSubtractionExpr(Note n)
Specified by:
visitSubtractionExpr in interface Predicate

visitBitShiftExpr

public void visitBitShiftExpr(Note n)
Specified by:
visitBitShiftExpr in interface Predicate

visitCallMethodExpr

public void visitCallMethodExpr(Note n)
Specified by:
visitCallMethodExpr in interface Predicate

visitComplexValueExpr

public void visitComplexValueExpr(Note n)
Specified by:
visitComplexValueExpr in interface Predicate

convertIntRegValue

protected abstract void convertIntRegValue(int src,
                                           int srcSize,
                                           boolean srcSigned,
                                           int dest,
                                           int destSize,
                                           boolean destSigned)
Generate instructions to convert an integer value in an integer register to an integer value of a different size. The source and destination may be the same register.
Parameters:
src - is the register containing the source value
srcSize - is the source value size
srcSigned - is true if the source value is signed
dest - is the register containing the result
destSize - is the size of the result value
destSigned - is true if the result value is signed

genRealToInt

protected abstract void genRealToInt(int src,
                                     int srcSize,
                                     int dest,
                                     int destSize,
                                     boolean destSigned)
Convert real value in a real register to an integer value in a real register. The result is rounded down.

genRealToReal

protected abstract void genRealToReal(int src,
                                      int srcSize,
                                      int dest,
                                      int destSize)
Convert a real value in a real register to a real value in a real register.

genIntToReal

protected abstract void genIntToReal(int src,
                                     int srcSize,
                                     int dest,
                                     int destSize)
Convert an integer value in a real register to a real value in a real register.

genUnsignedIntToReal

protected abstract void genUnsignedIntToReal(int src,
                                             int srcSize,
                                             int dest,
                                             int destSize)
Convert an unsigned integer value in an integer register to a real value in a real register.

genRealToIntRound

protected abstract void genRealToIntRound(int src,
                                          int srcSize,
                                          int dest,
                                          int destSize)
Convert integer value in a real register to an integer value in a real register. The result is rounded to the nearest integer.

genFloorOfReal

protected abstract void genFloorOfReal(int src,
                                       int srcSize,
                                       int dest,
                                       int destSize)
Generate instructions to compute the floor of a real vaue in a real register to a real register.

zeroFloatRegister

protected abstract void zeroFloatRegister(int dest,
                                          int destSize)
Generate code to zero out a floating point register.

allocAggregationElements

protected abstract Displacement allocAggregationElements(AggregationElements ag)
Place values from an AggregationElements literal in read-only memory.
Returns:
the Displacement of the data

visitConversionExpr

public void visitConversionExpr(Note n)
Specified by:
visitConversionExpr in interface Predicate

visitDualExpr

public void visitDualExpr(Note n)
Specified by:
visitDualExpr in interface Predicate

visitEqualityExpr

public void visitEqualityExpr(Note n)
Specified by:
visitEqualityExpr in interface Predicate

visitGreaterEqualExpr

public void visitGreaterEqualExpr(Note n)
Specified by:
visitGreaterEqualExpr in interface Predicate

visitGreaterExpr

public void visitGreaterExpr(Note n)
Specified by:
visitGreaterExpr in interface Predicate

visitLessEqualExpr

public void visitLessEqualExpr(Note n)
Specified by:
visitLessEqualExpr in interface Predicate

visitLessExpr

public void visitLessExpr(Note n)
Specified by:
visitLessExpr in interface Predicate

visitNotEqualExpr

public void visitNotEqualExpr(Note n)
Specified by:
visitNotEqualExpr in interface Predicate

visitLeaveChord

public void visitLeaveChord(Note n)

visitLiteralExpr

public void visitLiteralExpr(Note n)
Specified by:
visitLiteralExpr in interface Predicate

visitNilExpr

public void visitNilExpr(Note n)
Specified by:
visitNilExpr in interface Predicate

visitStoreExpr

public void visitStoreExpr(Note n)
Specified by:
visitStoreExpr in interface Predicate

visitVaStartExpr

public void visitVaStartExpr(Note n)
Specified by:
visitVaStartExpr in interface Predicate

visitAllocateExpr

public void visitAllocateExpr(Note n)
Specified by:
visitAllocateExpr in interface Predicate

visitBinaryExpr

public void visitBinaryExpr(Note n)

visitBranchChord

public void visitBranchChord(Note n)

visitCallExpr

public void visitCallExpr(Note n)

visitChord

public void visitChord(Note n)

visitDecisionChord

public void visitDecisionChord(Note n)

visitExpr

public void visitExpr(Note n)

visitExprPhiExpr

public void visitExprPhiExpr(Note n)
Specified by:
visitExprPhiExpr in interface Predicate

visitLoadExpr

public void visitLoadExpr(Note n)

visitMaxExpr

public void visitMaxExpr(Note n)
Specified by:
visitMaxExpr in interface Predicate

visitMinExpr

public void visitMinExpr(Note n)
Specified by:
visitMinExpr in interface Predicate

visitMayDefExpr

public void visitMayDefExpr(Note n)
Specified by:
visitMayDefExpr in interface Predicate

visitMayUseExpr

public void visitMayUseExpr(Note n)
Specified by:
visitMayUseExpr in interface Predicate

visitNaryExpr

public void visitNaryExpr(Note n)

visitNote

public void visitNote(Note n)

visitGotoChord

public void visitGotoChord(Note n)
Specified by:
visitGotoChord in interface Predicate

visitLoopExitChord

public void visitLoopExitChord(Note n)
Specified by:
visitLoopExitChord in interface Predicate

visitLoopHeaderChord

public void visitLoopHeaderChord(Note n)
Specified by:
visitLoopHeaderChord in interface Predicate

visitLoopPreHeaderChord

public void visitLoopPreHeaderChord(Note n)
Specified by:
visitLoopPreHeaderChord in interface Predicate

visitLoopTailChord

public void visitLoopTailChord(Note n)
Specified by:
visitLoopTailChord in interface Predicate

visitNullChord

public void visitNullChord(Note n)
Specified by:
visitNullChord in interface Predicate

visitPhiExpr

public void visitPhiExpr(Note n)
Specified by:
visitPhiExpr in interface Predicate

visitEvictChord

public void visitEvictChord(Note n)
Specified by:
visitEvictChord in interface Predicate

visitPhiExprChord

public void visitPhiExprChord(Note n)
Specified by:
visitPhiExprChord in interface Predicate

visitSequentialChord

public void visitSequentialChord(Note n)

visitSubscriptExpr

public void visitSubscriptExpr(Note n)
Specified by:
visitSubscriptExpr in interface Predicate

visitTernaryExpr

public void visitTernaryExpr(Note n)

visitUnaryExpr

public void visitUnaryExpr(Note n)

visitValueExpr

public void visitValueExpr(Note n)

visitVarArgExpr

public void visitVarArgExpr(Note n)

visitVaEndExpr

public void visitVaEndExpr(Note n)
Specified by:
visitVaEndExpr in interface Predicate

visitVectorExpr

public void visitVectorExpr(Note n)
Specified by:
visitVectorExpr in interface Predicate