Java Code Examples for proguard.classfile.instruction.ConstantInstruction#length()

The following examples show how to use proguard.classfile.instruction.ConstantInstruction#length() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeAttributeEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Write out the instruction.
    instructionWriter.visitConstantInstruction(clazz,
                                               method,
                                               codeAttribute,
                                               newOffset,
                                               constantInstruction);

    newOffset += constantInstruction.length(newOffset);
}
 
Example 2
Source File: TailRecursionSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Is it a method invocation?
    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKESTATIC:
        {
            // Is it a recursive call?
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, recursionChecker);

            if (recursionChecker.isRecursive())
            {
                // Is the next instruction a return?
                int nextOffset =
                    offset + constantInstruction.length(offset);

                Instruction nextInstruction =
                    InstructionFactory.create(codeAttribute.code, nextOffset);

                switch (nextInstruction.opcode)
                {
                    case InstructionConstants.OP_IRETURN:
                    case InstructionConstants.OP_LRETURN:
                    case InstructionConstants.OP_FRETURN:
                    case InstructionConstants.OP_DRETURN:
                    case InstructionConstants.OP_ARETURN:
                    case InstructionConstants.OP_RETURN:
                    {
                        // Isn't the recursive call inside a try/catch block?
                        codeAttribute.exceptionsAccept(clazz, method, offset, recursionChecker);

                        if (recursionChecker.isRecursive())
                        {
                            if (DEBUG)
                            {
                                System.out.println("TailRecursionSimplifier: ["+
                                                   clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"], inlining "+constantInstruction.toString(offset));
                            }

                            // Append a label.
                            codeAttributeComposer.appendLabel(offset);

                            storeParameters(clazz, method);

                            // Branch back to the start of the method.
                            int gotoOffset = offset + 1;
                            codeAttributeComposer.appendInstruction(gotoOffset,
                                                                    new BranchInstruction(InstructionConstants.OP_GOTO, -gotoOffset));

                            // The original return instruction will be
                            // removed elsewhere, if possible.

                            // Remember that the code has changed.
                            inlinedAny = true;

                            if (extraTailRecursionVisitor != null)
                            {
                                extraTailRecursionVisitor.visitConstantInstruction(clazz, method, codeAttribute, offset, constantInstruction);
                            }

                            // The invocation itself is no longer necessary.
                            return;
                        }
                    }
                }
            }

            break;
        }
    }

    // Copy the instruction.
    codeAttributeComposer.appendInstruction(offset, constantInstruction.shrink());
}