Instances of this class may be used, e.g., to generate typed
versions of instructions. Its main purpose is to be used as the
byte code generating backend of a compiler. You can subclass it to
add your own create methods.
createArrayLoad
public static ArrayInstruction createArrayLoad(Type type)
type
- type of elements of array, i.e., array.getElementType()
createArrayStore
public static ArrayInstruction createArrayStore(Type type)
type
- type of elements of array, i.e., array.getElementType()
createBinaryOperation
public static ArithmeticInstruction createBinaryOperation(String op,
Type type)
Create binary operation for simple basic types, such as int and float.
op
- operation, such as "+", "*", "<<", etc.
createBranchInstruction
public static BranchInstruction createBranchInstruction(short opcode,
InstructionHandle target)
Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.
For those you should use the SWITCH compound instruction.
createCast
public Instruction createCast(Type src_type,
Type dest_type)
Create conversion operation for two stack operands, this may be an I2C, instruction, e.g.,
if the operands are basic types and CHECKCAST if they are reference types.
createConstant
public Instruction createConstant(Object value)
Uses PUSH to push a constant value onto the stack.
value
- must be of type Number, Boolean, Character or String
createDup
public static StackInstruction createDup(int size)
size
- size of operand, either 1 (int, e.g.) or 2 (double)
createDup_1
public static StackInstruction createDup_1(int size)
size
- size of operand, either 1 (int, e.g.) or 2 (double)
createDup_2
public static StackInstruction createDup_2(int size)
size
- size of operand, either 1 (int, e.g.) or 2 (double)
createFieldAccess
public FieldInstruction createFieldAccess(String class_name,
String name,
Type type,
short kind)
Create a field instruction.
class_name
- name of the accessed classname
- name of the referenced fieldtype
- type of fieldkind
- how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
createGetField
public GETFIELD createGetField(String class_name,
String name,
Type t)
createGetStatic
public GETSTATIC createGetStatic(String class_name,
String name,
Type t)
createInvoke
public InvokeInstruction createInvoke(String class_name,
String name,
Type ret_type,
Type[] arg_types,
short kind)
Create an invoke instruction.
class_name
- name of the called classname
- name of the called methodret_type
- return type of methodarg_types
- argument types of methodkind
- how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL,
or INVOKESPECIAL
createNew
public NEW createNew(String s)
createNewArray
public Instruction createNewArray(Type t,
short dim)
Create new array of given size and type.
- an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction
createNull
public static Instruction createNull(Type type)
Create "null" value for reference types, 0 for basic types like int
createPop
public static StackInstruction createPop(int size)
size
- size of operand, either 1 (int, e.g.) or 2 (double)
createPrintln
public InstructionList createPrintln(String s)
Create a call to the most popular System.out.println() method.
createPutField
public PUTFIELD createPutField(String class_name,
String name,
Type t)
createPutStatic
public PUTSTATIC createPutStatic(String class_name,
String name,
Type t)
createThis
public static Instruction createThis()
Create reference to `this'
getClassGen
public ClassGen getClassGen()
setClassGen
public void setClassGen(ClassGen c)