org.aspectj.apache.bcel.generic
Class InstructionFactory

java.lang.Object
  extended by org.aspectj.apache.bcel.generic.InstructionFactory
All Implemented Interfaces:
InstructionConstants

public class InstructionFactory
extends java.lang.Object
implements InstructionConstants

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.

See Also:
Constants

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.aspectj.apache.bcel.generic.InstructionConstants
InstructionConstants.Clinit
 
Field Summary
protected  ClassGen cg
           
protected  ConstantPool cp
           
 
Fields inherited from interface org.aspectj.apache.bcel.generic.InstructionConstants
AALOAD, AASTORE, ACONST_NULL, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ARETURN, ARRAYLENGTH, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, bla, CALOAD, CASTORE, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMPDEP1, IMPDEP2, IMUL, INEG, INSTRUCTIONS, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDIV, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, NOP, POP, POP2, RETURN, SALOAD, SASTORE, SWAP, THIS
 
Constructor Summary
InstructionFactory(ClassGen cg)
           
InstructionFactory(ClassGen cg, ConstantPool cp)
           
InstructionFactory(ConstantPool cp)
           
 
Method Summary
static Instruction createALOAD(int n)
           
static Instruction createArrayLoad(Type type)
           
static Instruction createArrayStore(Type type)
           
static Instruction createASTORE(int n)
           
static InstructionBranch createBranchInstruction(short opcode, InstructionHandle target)
          Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.
 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.
 Instruction createCheckCast(ReferenceType t)
           
 Instruction createConstant(java.lang.Object value)
          Uses PUSH to push a constant value onto the stack.
static Instruction createDup_1(int size)
           
static Instruction createDup_2(int size)
           
static Instruction createDup(int size)
           
 FieldInstruction createFieldAccess(java.lang.String class_name, java.lang.String name, Type type, short kind)
          Create a field instruction.
 FieldInstruction createGetField(java.lang.String class_name, java.lang.String name, Type t)
           
 FieldInstruction createGetStatic(java.lang.String class_name, java.lang.String name, Type t)
           
 Instruction createInstanceOf(ReferenceType t)
           
 InvokeInstruction createInvoke(java.lang.String class_name, java.lang.String name, java.lang.String signature, short kind)
           
 InvokeInstruction createInvoke(java.lang.String class_name, java.lang.String name, Type ret_type, Type[] arg_types, short kind)
          Create an invoke instruction.
static InstructionLV createLoad(Type type, int index)
           
 Instruction createNew(ObjectType t)
           
 Instruction createNew(java.lang.String s)
           
 Instruction createNewArray(Type t, short dim)
          Create new array of given size and type.
static Instruction createNull(Type type)
          Create "null" value for reference types, 0 for basic types like int
static Instruction createPop(int size)
           
 FieldInstruction createPutField(java.lang.String class_name, java.lang.String name, Type t)
           
 FieldInstruction createPutStatic(java.lang.String class_name, java.lang.String name, Type t)
           
static Instruction createReturn(Type type)
          Create typed return
static InstructionLV createStore(Type type, int index)
           
static Instruction createThis()
          Create reference to `this'
 ClassGen getClassGen()
           
 ConstantPool getConstantPool()
           
static Instruction PUSH(ConstantPool cp, boolean value)
           
static Instruction PUSH(ConstantPool cp, java.lang.Boolean value)
           
static Instruction PUSH(ConstantPool cp, java.lang.Character value)
           
static Instruction PUSH(ConstantPool cp, double value)
           
static Instruction PUSH(ConstantPool cp, float value)
           
static Instruction PUSH(ConstantPool cp, int value)
          Returns the right instruction for putting whatever you want onto the stack
static Instruction PUSH(ConstantPool cp, long value)
           
static Instruction PUSH(ConstantPool cp, java.lang.Number value)
           
static Instruction PUSH(ConstantPool cp, ObjectType t)
           
static Instruction PUSH(ConstantPool cp, java.lang.String value)
           
 InstructionList PUSHCLASS(ConstantPool cp, java.lang.String className)
          Return a list that will load the Class object - on 1.5 or later use the class variant of ldc, whilst on earlier JVMs use the regular Class.forName.
 void setClassGen(ClassGen c)
           
 void setConstantPool(ConstantPool c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cg

protected ClassGen cg

cp

protected ConstantPool cp
Constructor Detail

InstructionFactory

public InstructionFactory(ClassGen cg,
                          ConstantPool cp)

InstructionFactory

public InstructionFactory(ClassGen cg)

InstructionFactory

public InstructionFactory(ConstantPool cp)
Method Detail

createInvoke

public InvokeInstruction createInvoke(java.lang.String class_name,
                                      java.lang.String name,
                                      Type ret_type,
                                      Type[] arg_types,
                                      short kind)
Create an invoke instruction.

Parameters:
class_name - name of the called class
name - name of the called method
ret_type - return type of method
arg_types - argument types of method
kind - how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL
See Also:
Constants

createInvoke

public InvokeInstruction createInvoke(java.lang.String class_name,
                                      java.lang.String name,
                                      java.lang.String signature,
                                      short kind)

createALOAD

public static Instruction createALOAD(int n)

createASTORE

public static Instruction createASTORE(int n)

createConstant

public Instruction createConstant(java.lang.Object value)
Uses PUSH to push a constant value onto the stack.

Parameters:
value - must be of type Number, Boolean, Character or String

createFieldAccess

public FieldInstruction createFieldAccess(java.lang.String class_name,
                                          java.lang.String name,
                                          Type type,
                                          short kind)
Create a field instruction.

Parameters:
class_name - name of the accessed class
name - name of the referenced field
type - type of field
kind - how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
See Also:
Constants

createThis

public static Instruction createThis()
Create reference to `this'


createReturn

public static Instruction createReturn(Type type)
Create typed return


createPop

public static Instruction createPop(int size)
Parameters:
size - size of operand, either 1 (int, e.g.) or 2 (double)

createDup

public static Instruction createDup(int size)
Parameters:
size - size of operand, either 1 (int, e.g.) or 2 (double)

createDup_2

public static Instruction createDup_2(int size)
Parameters:
size - size of operand, either 1 (int, e.g.) or 2 (double)

createDup_1

public static Instruction createDup_1(int size)
Parameters:
size - size of operand, either 1 (int, e.g.) or 2 (double)

createStore

public static InstructionLV createStore(Type type,
                                        int index)
Parameters:
index - index of local variable

createLoad

public static InstructionLV createLoad(Type type,
                                       int index)
Parameters:
index - index of local variable

createArrayLoad

public static Instruction createArrayLoad(Type type)
Parameters:
type - type of elements of array, i.e., array.getElementType()

createArrayStore

public static Instruction createArrayStore(Type type)
Parameters:
type - type of elements of array, i.e., array.getElementType()

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.


createGetField

public FieldInstruction createGetField(java.lang.String class_name,
                                       java.lang.String name,
                                       Type t)

createGetStatic

public FieldInstruction createGetStatic(java.lang.String class_name,
                                        java.lang.String name,
                                        Type t)

createPutField

public FieldInstruction createPutField(java.lang.String class_name,
                                       java.lang.String name,
                                       Type t)

createPutStatic

public FieldInstruction createPutStatic(java.lang.String class_name,
                                        java.lang.String name,
                                        Type t)

createCheckCast

public Instruction createCheckCast(ReferenceType t)

createInstanceOf

public Instruction createInstanceOf(ReferenceType t)

createNew

public Instruction createNew(ObjectType t)

createNew

public Instruction createNew(java.lang.String s)

createNewArray

public Instruction createNewArray(Type t,
                                  short dim)
Create new array of given size and type.

Returns:
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


createBranchInstruction

public static InstructionBranch createBranchInstruction(short opcode,
                                                        InstructionHandle target)
Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. For those you should use the SWITCH compound instruction.


setClassGen

public void setClassGen(ClassGen c)

getClassGen

public ClassGen getClassGen()

setConstantPool

public void setConstantPool(ConstantPool c)

getConstantPool

public ConstantPool getConstantPool()

PUSH

public static Instruction PUSH(ConstantPool cp,
                               int value)
Returns the right instruction for putting whatever you want onto the stack


PUSH

public static Instruction PUSH(ConstantPool cp,
                               ObjectType t)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               boolean value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               float value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               long value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               double value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               java.lang.String value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               java.lang.Number value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               java.lang.Character value)

PUSH

public static Instruction PUSH(ConstantPool cp,
                               java.lang.Boolean value)

PUSHCLASS

public InstructionList PUSHCLASS(ConstantPool cp,
                                 java.lang.String className)
Return a list that will load the Class object - on 1.5 or later use the class variant of ldc, whilst on earlier JVMs use the regular Class.forName.