cfg
Class TACInst

java.lang.Object
  extended by cfg.TACInst
Direct Known Subclasses:
BinaryInst, CallInst, IfInst, LoadInst, ParamInst, PhiInst, ReturnInst, StoreEntryInst, UnaryInst

public abstract class TACInst
extends java.lang.Object

A class representing an individual Three-Adress Code (TAC) instruction. This is a generic abstract class, which is extended by the specific instructions: IfInst, CallInst (which is extended by InDirCallInst and DirCallInst), ReturnInst, ParamInst (which is extended by StdParamInst, RefParamInst, and ErrParamInst), LoadInst (which is extended by LoadVarInst, LoadConstInst, LoadAddrInst, LoadEntryInst), StoreEntryInst, UnaryInst (which is extended by UnaryNegInst and UnaryNotInst), and BinaryInst (which is extended by BinaryAddInst, BinarySubInst, BinaryMulInst, BinaryDivInst, BinaryModInst, BinaryAndInst, and BinaryOrInst). A TACInst contains an opcode and some comments associated with that instruction.

Author:
Marc Corliss and Lori Pietraszek

Field Summary
static int BINADD
          Binary (integer) addition opcode
static int BINAND
          Binary (boolean) AND opcode
static int BINDIV
          Binary (integer) division opcode
static int BINMOD
          Binary (integer) modulus opcode
static int BINMUL
          Binary (integer) multiplication opcode
static int BINOR
          Binary (boolean) OR opcode
static int BINSUB
          Binary (integer) subtraction opcode
protected  java.lang.String comments
          Comments for instruction
static int DIRCALL
          Call opcode -- used with non-dispatches (e.g., calls to error subroutines)
static int ERRPARAM
          Error handling parameter opcode
static int IF
          If opcode
static int INDIRCALL
          Call opcode -- used with dispatches
static int LDADDR
          Load address (i.e., label) opcode
static int LDCONST
          Load constant opcode
static int LDENTRY
          Load entry (i.e., read an entry in an object) opcode
static int LDVAR
          Load variable (move) opcode
static int NUM_INSN_TYPES
          Number of instruction types
protected  int opcode
          Instruction operation
static int PHI
          Binary (boolean) OR opcode
static int REFPARAM
          Reference parameter opcode
static int RETN
          Return opcode
static int STDPARAM
          Parameter opcode
static int STENTRY
          Store entry (i.e., write an entry in an object) opcode
static int UNNEG
          Unary (integer) negation opcode
static int UNNOT
          Unary (boolean) not opcode
 
Constructor Summary
TACInst(int opcode)
          TACInst constructor
 
Method Summary
abstract
<ReturnType,ArgumentType>
ReturnType
accept(TACInstVisitor<ReturnType,ArgumentType> visitor, ArgumentType o)
          Abstract visitor method.
 void addComment(java.lang.String comment)
          Add a comment to instruction (for debugging) (this can be called multiple times for multi-line comments)
static boolean checkBoolConst(java.lang.String str)
          Check that string is boolean constant
static boolean checkConst(java.lang.String str)
          Check that string is a constant (int, boolean, String, or null)
static boolean checkIntConst(java.lang.String str)
          Check that string is int constant
static boolean checkLabel(java.lang.String label)
          Check that a label is legal
static boolean checkStrConst(java.lang.String str)
          Check that string is String constant
static boolean checkVar(java.lang.String var)
          Check that a variable name is legal
abstract  boolean equals(java.lang.Object o)
          Compares this object with the parameter object
static int getBinaryOpcode(java.lang.String op)
          Convert string representation of binary operator to an opcode (doesn't work for other operators)
 java.lang.String getComments()
          Get comments for instruction
 java.lang.String getOp()
          Get the instruction operator as a string Only works for unary and binary operators (no control flow or load operators)
 int getOpcode()
          Get opcode of instruction
abstract  java.lang.String getString()
          Get string representation of instruction (without comments) (note: in general, you want to use toString() to get instruction string)
static int getUnaryOpcode(java.lang.String op)
          Convert string representation of unary operator to an opcode (doesn't work for other operators)
 boolean isBinary()
          Is this a binary instruction?
 boolean isCall()
          Is this a call instruction?
 boolean isIf()
          Is this an if instruction?
 boolean isLoad()
          Is this a load instruction?
 boolean isParam()
          Is this a parameter instruction?
 boolean isReturn()
          Is this a return instruction?
 boolean isStore()
          Is this a store instruction?
 boolean isUnary()
          Is this an unary instruction?
static boolean isValidID(java.lang.String s)
          Is this string a legal Bantam Java identifier?
 void removeComments()
          Remove comments from an instruction
 java.lang.String toString()
          Convert to a string
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IF

public static final int IF
If opcode

See Also:
Constant Field Values

INDIRCALL

public static final int INDIRCALL
Call opcode -- used with dispatches

See Also:
Constant Field Values

DIRCALL

public static final int DIRCALL
Call opcode -- used with non-dispatches (e.g., calls to error subroutines)

See Also:
Constant Field Values

RETN

public static final int RETN
Return opcode

See Also:
Constant Field Values

STDPARAM

public static final int STDPARAM
Parameter opcode

See Also:
Constant Field Values

REFPARAM

public static final int REFPARAM
Reference parameter opcode

See Also:
Constant Field Values

ERRPARAM

public static final int ERRPARAM
Error handling parameter opcode

See Also:
Constant Field Values

LDVAR

public static final int LDVAR
Load variable (move) opcode

See Also:
Constant Field Values

LDCONST

public static final int LDCONST
Load constant opcode

See Also:
Constant Field Values

LDADDR

public static final int LDADDR
Load address (i.e., label) opcode

See Also:
Constant Field Values

LDENTRY

public static final int LDENTRY
Load entry (i.e., read an entry in an object) opcode

See Also:
Constant Field Values

STENTRY

public static final int STENTRY
Store entry (i.e., write an entry in an object) opcode

See Also:
Constant Field Values

UNNEG

public static final int UNNEG
Unary (integer) negation opcode

See Also:
Constant Field Values

UNNOT

public static final int UNNOT
Unary (boolean) not opcode

See Also:
Constant Field Values

BINADD

public static final int BINADD
Binary (integer) addition opcode

See Also:
Constant Field Values

BINSUB

public static final int BINSUB
Binary (integer) subtraction opcode

See Also:
Constant Field Values

BINMUL

public static final int BINMUL
Binary (integer) multiplication opcode

See Also:
Constant Field Values

BINDIV

public static final int BINDIV
Binary (integer) division opcode

See Also:
Constant Field Values

BINMOD

public static final int BINMOD
Binary (integer) modulus opcode

See Also:
Constant Field Values

BINAND

public static final int BINAND
Binary (boolean) AND opcode

See Also:
Constant Field Values

BINOR

public static final int BINOR
Binary (boolean) OR opcode

See Also:
Constant Field Values

PHI

public static final int PHI
Binary (boolean) OR opcode

See Also:
Constant Field Values

NUM_INSN_TYPES

public static final int NUM_INSN_TYPES
Number of instruction types

See Also:
Constant Field Values

opcode

protected int opcode
Instruction operation


comments

protected java.lang.String comments
Comments for instruction

Constructor Detail

TACInst

public TACInst(int opcode)
TACInst constructor

Parameters:
opcode - opcode of instruction
Method Detail

accept

public abstract <ReturnType,ArgumentType> ReturnType accept(TACInstVisitor<ReturnType,ArgumentType> visitor,
                                                            ArgumentType o)
Abstract visitor method.

Parameters:
visitor - TACInstVisitor.
o - Data to pass down.
Returns:
return value of visitor.

isIf

public boolean isIf()
Is this an if instruction?

Returns:
flag indicating whether if

isCall

public boolean isCall()
Is this a call instruction?

Returns:
flag indicating whether call

isReturn

public boolean isReturn()
Is this a return instruction?

Returns:
flag indicating whether return

isParam

public boolean isParam()
Is this a parameter instruction?

Returns:
flag indicating whether parameter

isLoad

public boolean isLoad()
Is this a load instruction?

Returns:
flag indicating whether load

isStore

public boolean isStore()
Is this a store instruction?

Returns:
flag indicating whether store

isUnary

public boolean isUnary()
Is this an unary instruction?

Returns:
flag indicating whether unary

isBinary

public boolean isBinary()
Is this a binary instruction?

Returns:
flag indicating whether binary

getOpcode

public int getOpcode()
Get opcode of instruction

Returns:
opcode

getOp

public java.lang.String getOp()
Get the instruction operator as a string Only works for unary and binary operators (no control flow or load operators)

Returns:
instruction operator

getUnaryOpcode

public static int getUnaryOpcode(java.lang.String op)
Convert string representation of unary operator to an opcode (doesn't work for other operators)

Returns:
instruction opcode

getBinaryOpcode

public static int getBinaryOpcode(java.lang.String op)
Convert string representation of binary operator to an opcode (doesn't work for other operators)

Returns:
instruction opcode

getComments

public java.lang.String getComments()
Get comments for instruction

Returns:
comments for instruction

addComment

public void addComment(java.lang.String comment)
Add a comment to instruction (for debugging) (this can be called multiple times for multi-line comments)

Parameters:
comment - comment to add

removeComments

public void removeComments()
Remove comments from an instruction


checkLabel

public static boolean checkLabel(java.lang.String label)
Check that a label is legal

Parameters:
label - label to check
Returns:
boolean indicating whether label is legal

checkVar

public static boolean checkVar(java.lang.String var)
Check that a variable name is legal

Parameters:
var - variable to check
Returns:
boolean indicating whether variable is legal

checkIntConst

public static boolean checkIntConst(java.lang.String str)
Check that string is int constant

Parameters:
str - string to check
Returns:
boolean indicating whether string is an int

checkBoolConst

public static boolean checkBoolConst(java.lang.String str)
Check that string is boolean constant

Parameters:
str - string to check
Returns:
boolean indicating whether string is a boolean

checkStrConst

public static boolean checkStrConst(java.lang.String str)
Check that string is String constant

Parameters:
str - string to check
Returns:
boolean indicating whether string is a String

checkConst

public static boolean checkConst(java.lang.String str)
Check that string is a constant (int, boolean, String, or null)

Parameters:
str - string to check
Returns:
boolean indicating whether string is a constant

isValidID

public static boolean isValidID(java.lang.String s)
Is this string a legal Bantam Java identifier?

Parameters:
s - string to check
Returns:
boolean indicating whether string is legal ID

equals

public abstract boolean equals(java.lang.Object o)
Compares this object with the parameter object

Overrides:
equals in class java.lang.Object
Parameters:
o - object to compare the reference object with
Returns:
boolean indicating whether the objects are equivalent

getString

public abstract java.lang.String getString()
Get string representation of instruction (without comments) (note: in general, you want to use toString() to get instruction string)

Returns:
string representation of three address code instruction (without comments)

toString

public java.lang.String toString()
Convert to a string

Overrides:
toString in class java.lang.Object
Returns:
string representation of three address code instruction