public InstructionSequenceBuilder ldc(String string) { return ldc(string, null, null); }
/** * Pushes the given primitive value on the stack. * * Operand stack: * ... -> ..., value * * @param value the primitive value to be pushed - should never be null. * @param type the internal type of the primitive ('Z','B','I',...) */ public InstructionSequenceBuilder pushPrimitive(Object value, char type) { switch (type) { case ClassConstants.TYPE_BOOLEAN: return ((Boolean)value).booleanValue() ? iconst_1() : iconst_0(); case ClassConstants.TYPE_BYTE: case ClassConstants.TYPE_SHORT: case ClassConstants.TYPE_INT: return pushInt(((Number)value).intValue()); case ClassConstants.TYPE_CHAR: return ldc(((Character)value).charValue()); case ClassConstants.TYPE_LONG: return ldc2_w((Long)value); case ClassConstants.TYPE_FLOAT: return ldc(((Float)value).floatValue()); case ClassConstants.TYPE_DOUBLE: return ldc2_w((Double)value); default: throw new IllegalArgumentException("" + type); } }
appendChainComposer.ldc(concatenationRecipe.substring(argIndex, nextArgIndex)) .invokevirtual(ClassConstants.NAME_JAVA_LANG_STRING_BUILDER, ClassConstants.METHOD_NAME_APPEND,
}, { // ... * 32768 = ... << 15 ____.ldc(32768) .imul().__(), }, { // ... * 65536 = ... << 16 ____.ldc(65536) .imul().__(), }, { // ... * 16777216 = ... << 24 ____.ldc(16777216) .imul().__(), }, { // ... * -1f = -... ____.ldc(-1f) .fmul().__(), ____.ldc(-1f) .fdiv().__(), }, { // (... & 0x0000ff00) >> 8 = (... >> 8) & 0xff ____.ldc(0x0000ff00) .iand() .bipush(8)
}, { // ... * 32768 = ... << 15 ____.ldc(32768) .imul().__(), }, { // ... * 65536 = ... << 16 ____.ldc(65536) .imul().__(), }, { // ... * 16777216 = ... << 24 ____.ldc(16777216) .imul().__(), }, { // ... * -1f = -... ____.ldc(-1f) .fmul().__(), ____.ldc(-1f) .fdiv().__(), }, { // (... & 0x0000ff00) >> 8 = (... >> 8) & 0xff ____.ldc(0x0000ff00) .iand() .bipush(8)
public InstructionSequenceBuilder ldc(String string) { return ldc(string, null, null); }
/** * Pushes the given primitive value on the stack. * * Operand stack: * ... -> ..., value * * @param value the primitive value to be pushed - should never be null. * @param type the internal type of the primitive ('Z','B','I',...) */ public InstructionSequenceBuilder pushPrimitive(Object value, char type) { switch (type) { case ClassConstants.TYPE_BOOLEAN: return ((Boolean)value).booleanValue() ? iconst_1() : iconst_0(); case ClassConstants.TYPE_BYTE: case ClassConstants.TYPE_SHORT: case ClassConstants.TYPE_INT: return pushInt(((Number)value).intValue()); case ClassConstants.TYPE_CHAR: return ldc(((Character)value).charValue()); case ClassConstants.TYPE_LONG: return ldc2_w((Long)value); case ClassConstants.TYPE_FLOAT: return ldc(((Float)value).floatValue()); case ClassConstants.TYPE_DOUBLE: return ldc2_w((Double)value); default: throw new IllegalArgumentException("" + type); } }
appendChainComposer.ldc(concatenationRecipe.substring(argIndex, nextArgIndex)) .invokevirtual(ClassConstants.NAME_JAVA_LANG_STRING_BUILDER, ClassConstants.METHOD_NAME_APPEND,
public InstructionSequenceBuilder ldc(String string) { return ldc(string, null, null); }
/** * Pushes the given primitive value on the stack. * * Operand stack: * ... -> ..., value * * @param value the primitive value to be pushed - should never be null. * @param type the internal type of the primitive ('Z','B','I',...) */ public InstructionSequenceBuilder pushPrimitive(Object value, char type) { switch (type) { case ClassConstants.TYPE_BOOLEAN: return ((Boolean)value).booleanValue() ? iconst_1() : iconst_0(); case ClassConstants.TYPE_BYTE: case ClassConstants.TYPE_SHORT: case ClassConstants.TYPE_INT: return pushInt(((Number)value).intValue()); case ClassConstants.TYPE_CHAR: return ldc(((Character)value).charValue()); case ClassConstants.TYPE_LONG: return ldc2_w((Long)value); case ClassConstants.TYPE_FLOAT: return ldc(((Float)value).floatValue()); case ClassConstants.TYPE_DOUBLE: return ldc2_w((Double)value); default: throw new IllegalArgumentException("" + type); } }
appendChainComposer.ldc(concatenationRecipe.substring(argIndex, nextArgIndex)) .invokevirtual(ClassConstants.NAME_JAVA_LANG_STRING_BUILDER, ClassConstants.METHOD_NAME_APPEND,
/** * Pushes the given primitive float on the stack in the most efficient way * (as an fconst or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushFloat(float value) { return value == 0f || value == 1f ? fconst((int)value) : ldc(value); }
/** * Pushes the given primitive float on the stack in the most efficient way * (as an fconst or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushFloat(float value) { return value == 0f || value == 1f ? fconst((int)value) : ldc(value); }
/** * Pushes the given primitive float on the stack in the most efficient way * (as an fconst or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushFloat(float value) { return value == 0f || value == 1f ? fconst((int)value) : ldc(value); }
/** * Pushes the given primitive int on the stack in the most efficient way * (as an iconst, bipush, sipush, or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushInt(int value) { return value >= -1 && value <= 5 ? iconst(value) : value == (byte)value ? bipush(value) : value == (short)value ? sipush(value) : ldc(value); }
/** * Pushes the given primitive int on the stack in the most efficient way * (as an iconst, bipush, sipush, or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushInt(int value) { return value >= -1 && value <= 5 ? iconst(value) : value == (byte)value ? bipush(value) : value == (short)value ? sipush(value) : ldc(value); }
/** * Pushes the given primitive int on the stack in the most efficient way * (as an iconst, bipush, sipush, or ldc instruction). * * @param value the int value to be pushed. */ public InstructionSequenceBuilder pushInt(int value) { return value >= -1 && value <= 5 ? iconst(value) : value == (byte)value ? bipush(value) : value == (short)value ? sipush(value) : ldc(value); }
/** * This main method tests the class. */ public static void main(String[] args) { InstructionSequenceBuilder builder = new InstructionSequenceBuilder(); Instruction[] instructions = builder .iconst_2() .istore_0() .iinc(0, 2) .iload_0() .ldc(12) .iadd() .putstatic("com/example/SomeClass", "someField", "I", null, null) .instructions(); Constant[] constants = builder.constants(); for (Instruction instruction : instructions) { System.out.println(instruction); } System.out.println(); for (int index = 0; index < constants.length; index++) { System.out.println("#"+index+": " + constants[index]); } }
/** * This main method tests the class. */ public static void main(String[] args) { InstructionSequenceBuilder builder = new InstructionSequenceBuilder(); Instruction[] instructions = builder .iconst_2() .istore_0() .iinc(0, 2) .iload_0() .ldc(12) .iadd() .putstatic("com/example/SomeClass", "someField", "I", null, null) .instructions(); Constant[] constants = builder.constants(); for (Instruction instruction : instructions) { System.out.println(instruction); } System.out.println(); for (int index = 0; index < constants.length; index++) { System.out.println("#"+index+": " + constants[index]); } }
/** * This main method tests the class. */ public static void main(String[] args) { InstructionSequenceBuilder builder = new InstructionSequenceBuilder(); Instruction[] instructions = builder .iconst_2() .istore_0() .iinc(0, 2) .iload_0() .ldc(12) .iadd() .putstatic("com/example/SomeClass", "someField", "I", null, null) .instructions(); Constant[] constants = builder.constants(); for (Instruction instruction : instructions) { System.out.println(instruction); } System.out.println(); for (int index = 0; index < constants.length; index++) { System.out.println("#"+index+": " + constants[index]); } }