net.sf.farrago.fennel.calc
Class CalcProgramBuilder

java.lang.Object
  extended by net.sf.farrago.fennel.calc.CalcProgramBuilder

public class CalcProgramBuilder
extends Object

Constructs a calculator assembly language program based upon a series of calls made by the client.

If you want multi-line programs, call setSeparator(System.getProperty("line.separator").

See tracer.

Since:
Jan 11, 2004
Version:
$Id: //open/dev/farrago/src/net/sf/farrago/fennel/calc/CalcProgramBuilder.java#2 $
Author:
jhyde
"JUnit testcase:"

Nested Class Summary
(package private) static class CalcProgramBuilder.BoolInstructionDef
           
(package private) static class CalcProgramBuilder.BoolNativeInstructionDef
           
(package private) static class CalcProgramBuilder.ComparisonInstructionDef
           
static class CalcProgramBuilder.ExtInstrDef
          Defines an extended instruction.
static class CalcProgramBuilder.ExtInstrSizeDef
          Defines an extended instruction with name depending on the number or operands.
static class CalcProgramBuilder.FunctionCall
          Holds and represents the parameters for a call to an operator
(package private)  class CalcProgramBuilder.Instruction
          Represents an instruction and its operands
(package private) static class CalcProgramBuilder.InstructionDef
          Definition for an instruction.
(package private) static class CalcProgramBuilder.IntegralNativeInstructionDef
           
(package private) static class CalcProgramBuilder.IntegralNativeShift
           
(package private) static class CalcProgramBuilder.JumpInstructionDef
           
static class CalcProgramBuilder.Line
          Reference to a line number
private static class CalcProgramBuilder.LiteralPair
          A key-value pair class to hold
1) Value of a literal and
2) Type of a literal
For use in a hashtable
(package private) static class CalcProgramBuilder.NativeInstructionDef
           
(package private) static interface CalcProgramBuilder.Operand
          Represents an Operand in an opereation e.g.
static class CalcProgramBuilder.OpType
          Enumeration of the types supported by the calculator.
(package private) static class CalcProgramBuilder.PointerBoolInstructionDef
           
static class CalcProgramBuilder.RegisterDescriptor
           
protected  class CalcProgramBuilder.RegisterSets
          A place holder to hold defined register sets
static class CalcProgramBuilder.RegisterSetType
          Enumeration of register types
 
Field Summary
static CalcProgramBuilder.InstructionDef[] allInstrDefs
           
static CalcProgramBuilder.InstructionDef boolAnd
           
static CalcProgramBuilder.InstructionDef boolEqual
           
static CalcProgramBuilder.InstructionDef boolGreaterOrEqualThan
           
static CalcProgramBuilder.InstructionDef boolGreaterThan
           
static CalcProgramBuilder.InstructionDef boolIsNotNull
           
static CalcProgramBuilder.InstructionDef boolIsNull
           
static CalcProgramBuilder.InstructionDef boolLessOrEqualThan
           
static CalcProgramBuilder.InstructionDef boolLessThan
           
static CalcProgramBuilder.InstructionDef boolMove
           
static CalcProgramBuilder.InstructionDef boolNativeEqual
           
static CalcProgramBuilder.InstructionDef boolNativeGreaterOrEqualThan
           
static CalcProgramBuilder.InstructionDef boolNativeGreaterThan
           
static CalcProgramBuilder.InstructionDef boolNativeIsNotNull
           
static CalcProgramBuilder.InstructionDef boolNativeIsNull
           
static CalcProgramBuilder.InstructionDef boolNativeLessOrEqualThan
           
static CalcProgramBuilder.InstructionDef boolNativeLessThan
           
static CalcProgramBuilder.InstructionDef boolNativeNotEqual
           
static CalcProgramBuilder.InstructionDef boolNot
           
static CalcProgramBuilder.InstructionDef boolNotEqual
           
static CalcProgramBuilder.InstructionDef boolOr
           
static CalcProgramBuilder.InstructionDef call
           
static CalcProgramBuilder.InstructionDef cast
           
protected  List<CalcProgramBuilder.Instruction> instructions
           
static CalcProgramBuilder.InstructionDef integralNativeAnd
           
static CalcProgramBuilder.InstructionDef integralNativeMod
          Integral modulo instruction.
static CalcProgramBuilder.InstructionDef integralNativeMul
           
static CalcProgramBuilder.InstructionDef integralNativeOr
           
static CalcProgramBuilder.InstructionDef integralNativeShiftLeft
           
static CalcProgramBuilder.InstructionDef integralNativeShiftRight
           
static CalcProgramBuilder.InstructionDef integralNativeXor
           
static CalcProgramBuilder.JumpInstructionDef jumpFalseInstruction
           
static CalcProgramBuilder.JumpInstructionDef jumpInstruction
           
static CalcProgramBuilder.JumpInstructionDef jumpNotNullInstruction
           
static CalcProgramBuilder.JumpInstructionDef jumpNullInstruction
           
static CalcProgramBuilder.JumpInstructionDef jumpTrueInstruction
           
protected  Map<String,Integer> labels
           
protected  Map<CalcProgramBuilder.LiteralPair,CalcReg> literals
           
static CalcProgramBuilder.InstructionDef move
           
static CalcProgramBuilder.InstructionDef nativeAdd
           
static CalcProgramBuilder.InstructionDef nativeDiv
           
static CalcProgramBuilder.InstructionDef nativeMinus
           
static CalcProgramBuilder.InstructionDef nativeMove
           
static CalcProgramBuilder.InstructionDef nativeNeg
           
private static String NL
           
private  boolean outputComments
           
static CalcProgramBuilder.InstructionDef pointerAdd
           
static CalcProgramBuilder.InstructionDef pointerBoolEqual
           
static CalcProgramBuilder.InstructionDef pointerBoolGreaterOrEqualThan
           
static CalcProgramBuilder.InstructionDef pointerBoolGreaterThan
           
static CalcProgramBuilder.InstructionDef pointerBoolIsNotNull
           
static CalcProgramBuilder.InstructionDef pointerBoolIsNull
           
static CalcProgramBuilder.InstructionDef pointerBoolLessOrEqualThan
           
static CalcProgramBuilder.InstructionDef pointerBoolLessThan
           
static CalcProgramBuilder.InstructionDef pointerBoolNotEqual
           
static CalcProgramBuilder.InstructionDef pointerMove
           
static CalcProgramBuilder.InstructionDef raise
           
static CalcProgramBuilder.InstructionDef refInstruction
           
protected  CalcProgramBuilder.RegisterSets registerSets
           
static CalcProgramBuilder.InstructionDef returnInstruction
           
static CalcProgramBuilder.InstructionDef round
          Rounds approximate types to nearest integer but remains same type
protected  String separator
           
static String SEPARATOR_NEWLINE
           
static String SEPARATOR_SEMICOLON
           
static String SEPARATOR_SEMICOLON_NEWLINE
           
private static Logger tracer
           
private static BigInteger Uint4_MAX
           
private static BigInteger Uint8_MAX
           
 
Constructor Summary
CalcProgramBuilder()
          Creates a CalcProgramBuilder.
 
Method Summary
protected  void addComment(String comment)
          Adds an comment string to the last instruction.
protected  void addInstruction(CalcProgramBuilder.InstructionDef instrDef, CalcProgramBuilder.Operand... operands)
          For internal use only.
protected  void addJumpBooleanWithCondition(CalcProgramBuilder.JumpInstructionDef op, int line, CalcReg reg)
           
 void addJumpFalse(int line, CalcReg reg)
           
 void addJumpNotNull(int line, CalcReg reg)
           
 void addJumpNull(int line, CalcReg reg)
           
 void addJumpTrue(int line, CalcReg reg)
          Adds an condtional JMP instruction.
 void addLabel(String label)
           
 void addLabelJump(String label)
           
 void addLabelJumpFalse(String label, CalcReg reg)
           
 void addLabelJumpNotNull(String label, CalcReg reg)
           
 void addLabelJumpNull(String label, CalcReg reg)
           
 void addLabelJumpTrue(String label, CalcReg reg)
           
 void addRef(CalcReg outputRegister, CalcReg src)
          Adds a REF instruction.
 void addReturn()
           
protected  void assertIsNativeType(CalcReg reg)
          Asserts input is of native type except booleans
protected  void assertIsVarchar(CalcReg reg)
          Asserts input is of type CalcProgramBuilder.OpType.Varchar
protected  void assertNotDivideByZero(CalcReg reg)
          Asserts that Register is nothing of the following, all at once of Literal type of Integer type its value is zero
protected  void assertOperandsNotNull(CalcProgramBuilder.Operand[] operands)
          Asserts that all operands are not null.
protected  void assertRegisterBool(CalcReg reg)
          Asserts that the register is declared as CalcProgramBuilder.OpType.Bool
protected  void assertRegisterInteger(CalcReg reg)
          Asserts that the register is declared as integer.
protected  void assertRegisterIsPointer(CalcReg reg)
          Asserts that the register is declared as a pointer.
protected  void assertRegisterLiteral(CalcReg reg)
          Asserts that the register is declared as CalcProgramBuilder.RegisterSetType.Literal
protected  void assertRegisterNotConstant(CalcReg reg)
          Asserts that the register is not declared as CalcProgramBuilder.RegisterSetType.Literal or CalcProgramBuilder.RegisterSetType.Input.
private  void bindReferences()
          Replaces a label with a line number
 void clear()
          Re-initializes a CalcProgramBuilder.
protected  void compilationAssert(boolean cond)
           
protected  void compilationAssert(boolean cond, String msg)
           
(package private) static String formatComment(String comment)
          Formats a "logical" comment into a "physical" comment the calculator recognises.
private  void generateRegDeclarations(PrintWriter writer, CalcProgramBuilder.RegisterSetType registerSetType)
           
private  void generateRegValues(PrintWriter writer)
           
 int getCurrentLineNumber()
          Returns the number of existing lines of instructions - 1
protected  void getInstructions(PrintWriter writer)
          See getProgram()
 String getProgram()
          A program consists of two parts, its instructions and the user defined registers with its value.
(package private)  CalcReg getRegister(int ordinal, CalcProgramBuilder.RegisterSetType registerType)
          Returns the register of a given ordinal and type.
protected  void getRegisterSetsLayout(PrintWriter writer)
          Outputs register declarations.
 CalcReg newBoolLiteral(boolean b)
           
 CalcReg newDoubleLiteral(double d)
           
 CalcReg newFloatLiteral(float f)
           
 CalcReg newInput(CalcProgramBuilder.OpType type, int storageBytes)
          Creates a register in the input set and returns its reference
 CalcReg newInput(CalcProgramBuilder.RegisterDescriptor desc)
           
 CalcReg newInt4Literal(int i)
           
 CalcReg newInt8Literal(long i)
           
private  CalcReg newLiteral(CalcProgramBuilder.OpType type, Object value, int storageBytes)
          Generates a reference to a constant register.
 CalcReg newLiteral(CalcProgramBuilder.RegisterDescriptor desc, Object value)
           
 CalcReg newLocal(CalcProgramBuilder.OpType type, int storageBytes)
          Creates a register in the local set and returns its reference
 CalcReg newLocal(CalcProgramBuilder.RegisterDescriptor desc)
          Creates a register in the local set and returns its reference
 CalcReg newOutput(CalcProgramBuilder.OpType type, int storageBytes)
          Generates a reference to an output register.
 CalcReg newOutput(CalcProgramBuilder.RegisterDescriptor desc)
          Generates a reference to an output register.
 CalcReg newStatus(CalcProgramBuilder.OpType type, int storageBytes)
          Creates a register in the status set and returns its reference
 CalcReg newUint4Literal(BigInteger i)
           
 CalcReg newUint8Literal(BigInteger i)
           
 CalcReg newVarbinaryLiteral(byte[] bytes)
           
 CalcReg newVarcharLiteral(String s)
          Generates a reference to a string literal.
 CalcReg newVarcharLiteral(String s, int length)
          Generates a reference to a string literal.
private  void optimize()
          Tries to optimize the program.
private  String prettyPrint(String program)
          Introduces NL's for prettiness.
private  void printOperands(PrintWriter writer, CalcProgramBuilder.Operand[] operands)
           
 void setOutputComments(boolean outputComments)
           
 void setSeparator(String separator)
          Sets the separator between instructions in the generated program.
static int stringByteCount(int i)
          Returns the number of bytes storage required for a string.
static int stringByteCount(String s)
          Returns the number of bytes storage required for a string.
private  void validate()
          Validates the program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NL

private static final String NL

SEPARATOR_SEMICOLON

public static final String SEPARATOR_SEMICOLON
See Also:
Constant Field Values

SEPARATOR_NEWLINE

public static final String SEPARATOR_NEWLINE

SEPARATOR_SEMICOLON_NEWLINE

public static final String SEPARATOR_SEMICOLON_NEWLINE

tracer

private static final Logger tracer

Uint4_MAX

private static final BigInteger Uint4_MAX

Uint8_MAX

private static final BigInteger Uint8_MAX

refInstruction

public static final CalcProgramBuilder.InstructionDef refInstruction

jumpInstruction

public static final CalcProgramBuilder.JumpInstructionDef jumpInstruction

jumpTrueInstruction

public static final CalcProgramBuilder.JumpInstructionDef jumpTrueInstruction

jumpFalseInstruction

public static final CalcProgramBuilder.JumpInstructionDef jumpFalseInstruction

jumpNullInstruction

public static final CalcProgramBuilder.JumpInstructionDef jumpNullInstruction

jumpNotNullInstruction

public static final CalcProgramBuilder.JumpInstructionDef jumpNotNullInstruction

returnInstruction

public static final CalcProgramBuilder.InstructionDef returnInstruction

nativeAdd

public static final CalcProgramBuilder.InstructionDef nativeAdd

pointerAdd

public static final CalcProgramBuilder.InstructionDef pointerAdd

boolAnd

public static final CalcProgramBuilder.InstructionDef boolAnd

integralNativeAnd

public static final CalcProgramBuilder.InstructionDef integralNativeAnd

cast

public static final CalcProgramBuilder.InstructionDef cast

call

public static final CalcProgramBuilder.InstructionDef call

nativeDiv

public static final CalcProgramBuilder.InstructionDef nativeDiv

boolNativeEqual

public static final CalcProgramBuilder.InstructionDef boolNativeEqual

boolEqual

public static final CalcProgramBuilder.InstructionDef boolEqual

pointerBoolEqual

public static final CalcProgramBuilder.InstructionDef pointerBoolEqual

boolGreaterThan

public static final CalcProgramBuilder.InstructionDef boolGreaterThan

boolNativeGreaterThan

public static final CalcProgramBuilder.InstructionDef boolNativeGreaterThan

pointerBoolGreaterThan

public static final CalcProgramBuilder.InstructionDef pointerBoolGreaterThan

boolGreaterOrEqualThan

public static final CalcProgramBuilder.InstructionDef boolGreaterOrEqualThan

boolNativeGreaterOrEqualThan

public static final CalcProgramBuilder.InstructionDef boolNativeGreaterOrEqualThan

pointerBoolGreaterOrEqualThan

public static final CalcProgramBuilder.InstructionDef pointerBoolGreaterOrEqualThan

boolNativeIsNull

public static final CalcProgramBuilder.InstructionDef boolNativeIsNull

boolIsNull

public static final CalcProgramBuilder.InstructionDef boolIsNull

pointerBoolIsNull

public static final CalcProgramBuilder.InstructionDef pointerBoolIsNull

boolNativeIsNotNull

public static final CalcProgramBuilder.InstructionDef boolNativeIsNotNull

boolIsNotNull

public static final CalcProgramBuilder.InstructionDef boolIsNotNull

pointerBoolIsNotNull

public static final CalcProgramBuilder.InstructionDef pointerBoolIsNotNull

boolLessThan

public static final CalcProgramBuilder.InstructionDef boolLessThan

boolNativeLessThan

public static final CalcProgramBuilder.InstructionDef boolNativeLessThan

pointerBoolLessThan

public static final CalcProgramBuilder.InstructionDef pointerBoolLessThan

boolLessOrEqualThan

public static final CalcProgramBuilder.InstructionDef boolLessOrEqualThan

boolNativeLessOrEqualThan

public static final CalcProgramBuilder.InstructionDef boolNativeLessOrEqualThan

pointerBoolLessOrEqualThan

public static final CalcProgramBuilder.InstructionDef pointerBoolLessOrEqualThan

nativeMinus

public static final CalcProgramBuilder.InstructionDef nativeMinus

integralNativeMod

public static final CalcProgramBuilder.InstructionDef integralNativeMod
Integral modulo instruction. Per C++, returns negative values when applied to negative values. For example, 10 % 3 = 1, -10 % 3 = -1.


move

public static final CalcProgramBuilder.InstructionDef move

boolMove

public static final CalcProgramBuilder.InstructionDef boolMove

nativeMove

public static final CalcProgramBuilder.InstructionDef nativeMove

pointerMove

public static final CalcProgramBuilder.InstructionDef pointerMove

integralNativeMul

public static final CalcProgramBuilder.InstructionDef integralNativeMul

boolNot

public static final CalcProgramBuilder.InstructionDef boolNot

boolNativeNotEqual

public static final CalcProgramBuilder.InstructionDef boolNativeNotEqual

boolNotEqual

public static final CalcProgramBuilder.InstructionDef boolNotEqual

pointerBoolNotEqual

public static final CalcProgramBuilder.InstructionDef pointerBoolNotEqual

boolOr

public static final CalcProgramBuilder.InstructionDef boolOr

integralNativeOr

public static final CalcProgramBuilder.InstructionDef integralNativeOr

nativeNeg

public static final CalcProgramBuilder.InstructionDef nativeNeg

raise

public static final CalcProgramBuilder.InstructionDef raise

round

public static final CalcProgramBuilder.InstructionDef round
Rounds approximate types to nearest integer but remains same type


integralNativeShiftLeft

public static final CalcProgramBuilder.InstructionDef integralNativeShiftLeft

integralNativeShiftRight

public static final CalcProgramBuilder.InstructionDef integralNativeShiftRight

integralNativeXor

public static final CalcProgramBuilder.InstructionDef integralNativeXor

allInstrDefs

public static final CalcProgramBuilder.InstructionDef[] allInstrDefs

separator

protected String separator

instructions

protected final List<CalcProgramBuilder.Instruction> instructions

registerSets

protected CalcProgramBuilder.RegisterSets registerSets

literals

protected final Map<CalcProgramBuilder.LiteralPair,CalcReg> literals

labels

protected final Map<String,Integer> labels

outputComments

private boolean outputComments
Constructor Detail

CalcProgramBuilder

public CalcProgramBuilder()
Creates a CalcProgramBuilder.

Method Detail

clear

public void clear()
Re-initializes a CalcProgramBuilder.


setSeparator

public void setSeparator(String separator)
Sets the separator between instructions in the generated program. Can be either ';' or '\n' or ";\n"


setOutputComments

public void setOutputComments(boolean outputComments)

compilationAssert

protected void compilationAssert(boolean cond,
                                 String msg)

compilationAssert

protected void compilationAssert(boolean cond)

getProgram

public String getProgram()
A program consists of two parts, its instructions and the user defined registers with its value. The string representation of the program will be in the following format See getRegisterSetsLayout(java.io.PrintWriter)
<"\n">
See getInstructions(java.io.PrintWriter)


prettyPrint

private String prettyPrint(String program)
Introduces NL's for prettiness. Comments would be nice too.


getRegister

CalcReg getRegister(int ordinal,
                    CalcProgramBuilder.RegisterSetType registerType)
Returns the register of a given ordinal and type.


bindReferences

private void bindReferences()
Replaces a label with a line number


getCurrentLineNumber

public int getCurrentLineNumber()
Returns the number of existing lines of instructions - 1


getRegisterSetsLayout

protected void getRegisterSetsLayout(PrintWriter writer)
Outputs register declarations. The results look like this:
 O vc,20;
 I vc,30;
 C u1, u1, vc,22, vc,12, vc,30, s4;
 V 1, 0, 'ISO-8859-1', 'WILMA', 'ISO-8859-1$en', 0;
 L vc,30, u1, s4;
 S u1;

Parameters:
writer -

generateRegDeclarations

private void generateRegDeclarations(PrintWriter writer,
                                     CalcProgramBuilder.RegisterSetType registerSetType)

generateRegValues

private void generateRegValues(PrintWriter writer)

getInstructions

protected void getInstructions(PrintWriter writer)
See getProgram()

Parameters:
writer -

optimize

private void optimize()
Tries to optimize the program.


validate

private void validate()
Validates the program. Some errors are:


printOperands

private void printOperands(PrintWriter writer,
                           CalcProgramBuilder.Operand[] operands)

newOutput

public CalcReg newOutput(CalcProgramBuilder.OpType type,
                         int storageBytes)
Generates a reference to an output register.


newOutput

public CalcReg newOutput(CalcProgramBuilder.RegisterDescriptor desc)
Generates a reference to an output register.


newLiteral

private CalcReg newLiteral(CalcProgramBuilder.OpType type,
                           Object value,
                           int storageBytes)
Generates a reference to a constant register. If the the constant value already has been defined, the existing reference for that value will silently be returned instead of creating a new one

Parameters:
type - CalcProgramBuilder.OpType Type of value
value - Value

newLiteral

public CalcReg newLiteral(CalcProgramBuilder.RegisterDescriptor desc,
                          Object value)

newBoolLiteral

public CalcReg newBoolLiteral(boolean b)

newInt4Literal

public CalcReg newInt4Literal(int i)

newInt8Literal

public CalcReg newInt8Literal(long i)

newUint4Literal

public CalcReg newUint4Literal(BigInteger i)

newUint8Literal

public CalcReg newUint8Literal(BigInteger i)

newFloatLiteral

public CalcReg newFloatLiteral(float f)

newDoubleLiteral

public CalcReg newDoubleLiteral(double d)

newVarbinaryLiteral

public CalcReg newVarbinaryLiteral(byte[] bytes)

newVarcharLiteral

public CalcReg newVarcharLiteral(String s)
Generates a reference to a string literal. The actual value will be a pointer to an array of bytes.


newVarcharLiteral

public CalcReg newVarcharLiteral(String s,
                                 int length)
Generates a reference to a string literal. The actual value will be a pointer to an array of bytes. This methods is just here temporary until newVarcharLiteral(string) can distinguise between ascii and non-ascii strings and should not be used in places of general code. Only very specific code where you know for a dead fact the string is the right length.


stringByteCount

public static int stringByteCount(String s)
Returns the number of bytes storage required for a string. TODO: There is already a utility function somewhere which does this.


stringByteCount

public static int stringByteCount(int i)
Returns the number of bytes storage required for a string. TODO: There is already a utility function somewhere which does this.


newInput

public CalcReg newInput(CalcProgramBuilder.OpType type,
                        int storageBytes)
Creates a register in the input set and returns its reference


newInput

public CalcReg newInput(CalcProgramBuilder.RegisterDescriptor desc)

newLocal

public CalcReg newLocal(CalcProgramBuilder.OpType type,
                        int storageBytes)
Creates a register in the local set and returns its reference


newLocal

public CalcReg newLocal(CalcProgramBuilder.RegisterDescriptor desc)
Creates a register in the local set and returns its reference


newStatus

public CalcReg newStatus(CalcProgramBuilder.OpType type,
                         int storageBytes)
Creates a register in the status set and returns its reference


addInstruction

protected void addInstruction(CalcProgramBuilder.InstructionDef instrDef,
                              CalcProgramBuilder.Operand... operands)
For internal use only. Applications should call instruction.add(builder, operand0, operand1, ...).

Parameters:
instrDef - Instruction defn
operands - Operands

addComment

protected void addComment(String comment)
Adds an comment string to the last instruction. Some special character sequences are modified, see formatComment(java.lang.String)

Parameters:
comment -
"Precondition:"
at least one instruction needs to have been added prior to calling this function.

formatComment

static String formatComment(String comment)
Formats a "logical" comment into a "physical" comment the calculator recognises. E.g.
formatCommnet("yo wassup?") outputs
' /* yo wassup? */' NB the inital space.
If comment contains the character sequences '/*' or '*/' they will be replace by \* and *\ respectively.


assertRegisterNotConstant

protected void assertRegisterNotConstant(CalcReg reg)
Asserts that the register is not declared as CalcProgramBuilder.RegisterSetType.Literal or CalcProgramBuilder.RegisterSetType.Input.

Parameters:
reg - Register

assertRegisterLiteral

protected void assertRegisterLiteral(CalcReg reg)
Asserts that the register is declared as CalcProgramBuilder.RegisterSetType.Literal

Parameters:
reg - Register

assertRegisterBool

protected void assertRegisterBool(CalcReg reg)
Asserts that the register is declared as CalcProgramBuilder.OpType.Bool

Parameters:
reg - Register

assertRegisterIsPointer

protected void assertRegisterIsPointer(CalcReg reg)
Asserts that the register is declared as a pointer. Pointers are CalcProgramBuilder.OpType.Varchar,CalcProgramBuilder.OpType.Varbinary

Parameters:
reg - Register

assertRegisterInteger

protected void assertRegisterInteger(CalcReg reg)
Asserts that the register is declared as integer. Integers are CalcProgramBuilder.OpType.Int4, CalcProgramBuilder.OpType.Int8, CalcProgramBuilder.OpType.Uint4,CalcProgramBuilder.OpType.Uint8

Parameters:
reg - Register

assertNotDivideByZero

protected void assertNotDivideByZero(CalcReg reg)
Asserts that Register is nothing of the following, all at once

Parameters:
reg - Register

assertIsNativeType

protected void assertIsNativeType(CalcReg reg)
Asserts input is of native type except booleans

Parameters:
reg - Register

assertIsVarchar

protected void assertIsVarchar(CalcReg reg)
Asserts input is of type CalcProgramBuilder.OpType.Varchar

Parameters:
reg - Register

assertOperandsNotNull

protected void assertOperandsNotNull(CalcProgramBuilder.Operand[] operands)
Asserts that all operands are not null.

Parameters:
operands - Operands

addRef

public void addRef(CalcReg outputRegister,
                   CalcReg src)
Adds a REF instruction.


addJumpBooleanWithCondition

protected void addJumpBooleanWithCondition(CalcProgramBuilder.JumpInstructionDef op,
                                           int line,
                                           CalcReg reg)

addJumpTrue

public void addJumpTrue(int line,
                        CalcReg reg)
Adds an condtional JMP instruction. Jumps to line if the value in reg is TRUE.

"Precondition:"
reg of Boolean Type, line>=0
"Postcondition:"
line < number of calls to addXxxInstruction methods

addJumpFalse

public void addJumpFalse(int line,
                         CalcReg reg)

addJumpNull

public void addJumpNull(int line,
                        CalcReg reg)

addJumpNotNull

public void addJumpNotNull(int line,
                           CalcReg reg)

addReturn

public void addReturn()

addLabelJump

public void addLabelJump(String label)

addLabelJumpTrue

public void addLabelJumpTrue(String label,
                             CalcReg reg)

addLabelJumpFalse

public void addLabelJumpFalse(String label,
                              CalcReg reg)

addLabelJumpNull

public void addLabelJumpNull(String label,
                             CalcReg reg)

addLabelJumpNotNull

public void addLabelJumpNotNull(String label,
                                CalcReg reg)

addLabel

public void addLabel(String label)