Java Code Examples for proguard.evaluation.TracedVariables#load()

The following examples show how to use proguard.evaluation.TracedVariables#load() . 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: EvaluationSimplifier.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Replaces the long pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceLongPushInstruction(Clazz       clazz,
                                        int         offset,
                                        Instruction instruction,
                                        int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Push a constant instead.
        long value = pushedValue.longValue().value();
        if (value == 0L ||
            value == 1L)
        {
            replaceConstantPushInstruction(clazz,
                                   offset,
                                   instruction,
                                   InstructionConstants.OP_LCONST_0,
                                   (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addLongConstant(value));

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        // Load an equivalent lower-numbered variable instead, if any.
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            // Note that we have to check the second part as well.
            if (pushedValue.equals(variables.load(variableIndex)) &&
                variables.load(variableIndex + 1) != null         &&
                variables.load(variableIndex + 1).computationalType() == Value.TYPE_TOP)
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_LLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 2
Source File: EvaluationSimplifier.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Replaces the double pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceDoublePushInstruction(Clazz       clazz,
                                          int         offset,
                                          Instruction instruction,
                                          int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Push a constant instead.
        // Make sure to distinguish between +0.0 and -0.0.
        double value = pushedValue.doubleValue().value();
        if (value == 0.0 && Double.doubleToLongBits(value) == POS_ZERO_DOUBLE_BITS ||
            value == 1.0)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_DCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addDoubleConstant(value));

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        // Load an equivalent lower-numbered variable instead, if any.
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            // Note that we have to check the second part as well.
            if (pushedValue.equals(variables.load(variableIndex)) &&
                variables.load(variableIndex + 1) != null         &&
                variables.load(variableIndex + 1).computationalType() == Value.TYPE_TOP)
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_DLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 3
Source File: EvaluationSimplifier.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the long pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceLongPushInstruction(Clazz       clazz,
                                        int         offset,
                                        Instruction instruction,
                                        int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Push a constant instead.
        long value = pushedValue.longValue().value();
        if (value == 0L ||
            value == 1L)
        {
            replaceConstantPushInstruction(clazz,
                                   offset,
                                   instruction,
                                   InstructionConstants.OP_LCONST_0,
                                   (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addLongConstant(value));

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        // Load an equivalent lower-numbered variable instead, if any.
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            // Note that we have to check the second part as well.
            if (pushedValue.equals(variables.load(variableIndex)) &&
                variables.load(variableIndex + 1) != null         &&
                variables.load(variableIndex + 1).computationalType() == Value.TYPE_TOP)
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_LLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 4
Source File: EvaluationSimplifier.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the double pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceDoublePushInstruction(Clazz       clazz,
                                          int         offset,
                                          Instruction instruction,
                                          int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Push a constant instead.
        // Make sure to distinguish between +0.0 and -0.0.
        double value = pushedValue.doubleValue().value();
        if (value == 0.0 && Double.doubleToLongBits(value) == POS_ZERO_DOUBLE_BITS ||
            value == 1.0)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_DCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addDoubleConstant(value));

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        // Load an equivalent lower-numbered variable instead, if any.
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            // Note that we have to check the second part as well.
            if (pushedValue.equals(variables.load(variableIndex)) &&
                variables.load(variableIndex + 1) != null         &&
                variables.load(variableIndex + 1).computationalType() == Value.TYPE_TOP)
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_DLOAD,
                                               variableIndex);
            }
        }
    }
}