Package org.apache.bcel.generic
Class InstructionFactory
java.lang.Object
org.apache.bcel.generic.InstructionFactory
- All Implemented Interfaces:
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.
Note: The static createXXX methods return singleton instances from the InstructionConst
class.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.bcel.generic.InstructionConstants
InstructionConstants.Clinit
-
Field Summary
Modifier and TypeFieldDescriptionprotected ClassGen
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected ConstantPoolGen
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setterFields inherited from interface org.apache.bcel.generic.InstructionConstants
AALOAD, AASTORE, ACONST_NULL, ALOAD_0, ALOAD_1, ALOAD_2, ARETURN, ARRAYLENGTH, ASTORE_0, ASTORE_1, ASTORE_2, ATHROW, BALOAD, BASTORE, bla, CALOAD, CASTORE, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DMUL, DNEG, DREM, DRETURN, 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, FMUL, FNEG, FREM, FRETURN, 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, IMUL, INEG, INSTRUCTIONS, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE_0, ISTORE_1, ISTORE_2, ISUB, IUSHR, IXOR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDIV, LMUL, LNEG, LOR, LREM, LRETURN, LSHL, LSHR, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, NOP, POP, POP2, RETURN, SALOAD, SASTORE, SWAP, THIS
-
Constructor Summary
ConstructorDescriptionInitialize with ClassGen objectInitialize just with ConstantPoolGen object -
Method Summary
Modifier and TypeMethodDescriptioncreateAppend
(Type type) static ArrayInstruction
createArrayLoad
(Type type) static ArrayInstruction
createArrayStore
(Type type) static ArithmeticInstruction
createBinaryOperation
(String op, Type type) Create binary operation for simple basic types, such as int and float.static BranchInstruction
createBranchInstruction
(short opcode, InstructionHandle target) Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.createCast
(Type srcType, Type destType) 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
(Object value) Uses PUSH to push a constant value onto the stack.static StackInstruction
createDup
(int size) static StackInstruction
createDup_1
(int size) static StackInstruction
createDup_2
(int size) createFieldAccess
(String className, String name, Type type, short kind) Create a field instruction.createGetField
(String className, String name, Type t) createGetStatic
(String className, String name, Type t) createInvoke
(String className, String name, Type retType, Type[] argTypes, short kind) Create an invoke instruction.createInvoke
(String className, String name, Type retType, Type[] argTypes, short kind, boolean useInterface) Create an invoke instruction.static LocalVariableInstruction
createLoad
(Type type, int index) 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 intstatic StackInstruction
createPop
(int size) Create a call to the most popular System.out.println() method.createPutField
(String className, String name, Type t) createPutStatic
(String className, String name, Type t) static ReturnInstruction
createReturn
(Type type) Create typed returnstatic LocalVariableInstruction
createStore
(Type type, int index) static Instruction
Create reference to 'this'void
void
-
Field Details
-
cg
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
cp
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Details
-
InstructionFactory
Initialize with ClassGen object -
InstructionFactory
-
InstructionFactory
Initialize just with ConstantPoolGen object
-
-
Method Details
-
createArrayLoad
- Parameters:
type
- type of elements of array, i.e., array.getElementType()
-
createArrayStore
- Parameters:
type
- type of elements of array, i.e., array.getElementType()
-
createBinaryOperation
Create binary operation for simple basic types, such as int and float.- Parameters:
op
- operation, such as "+", "*", "<<", etc.
-
createBranchInstruction
Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. For those you should use the SWITCH compound instruction. -
createDup
- Parameters:
size
- size of operand, either 1 (int, e.g.) or 2 (double)
-
createDup_1
- Parameters:
size
- size of operand, either 1 (int, e.g.) or 2 (double)
-
createDup_2
- Parameters:
size
- size of operand, either 1 (int, e.g.) or 2 (double)
-
createLoad
- Parameters:
index
- index of local variable
-
createNull
Create "null" value for reference types, 0 for basic types like int -
createPop
- Parameters:
size
- size of operand, either 1 (int, e.g.) or 2 (double)
-
createReturn
Create typed return -
createStore
- Parameters:
index
- index of local variable
-
createThis
Create reference to 'this' -
createAppend
-
createCast
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. -
createCheckCast
-
createConstant
Uses PUSH to push a constant value onto the stack.- Parameters:
value
- must be of type Number, Boolean, Character or String
-
createFieldAccess
Create a field instruction.- Parameters:
className
- name of the accessed classname
- name of the referenced fieldtype
- type of fieldkind
- how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC- See Also:
-
createGetField
-
createGetStatic
-
createInstanceOf
-
createInvoke
public InvokeInstruction createInvoke(String className, String name, Type retType, Type[] argTypes, short kind) Create an invoke instruction. (Except for invokedynamic.)- Parameters:
className
- name of the called classname
- name of the called methodretType
- return type of methodargTypes
- argument types of methodkind
- how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL- See Also:
-
createInvoke
public InvokeInstruction createInvoke(String className, String name, Type retType, Type[] argTypes, short kind, boolean useInterface) Create an invoke instruction. (Except for invokedynamic.)- Parameters:
className
- name of the called classname
- name of the called methodretType
- return type of methodargTypes
- argument types of methodkind
- how to invoke: INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIALuseInterface
- force use of InterfaceMethodref- Returns:
- A new InvokeInstruction.
- Since:
- 6.5.0
-
createNew
-
createNew
-
createNewArray
Create new array of given size and type.- Returns:
- an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction
-
createPrintln
Create a call to the most popular System.out.println() method.- Parameters:
s
- the string to print
-
createPutField
-
createPutStatic
-
getClassGen
-
getConstantPool
-
setClassGen
-
setConstantPool
-