Search in sources :

Example 1 with Value

use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.

the class RedundantAssignmentOptimizer method visit.

@Override
protected void visit(ControlFlowGraph aGraph, ExpressionList aList, Expression aExpression, BytecodeLinkerContext aLinkerContext) {
    // Check if a variable assignment is before the current expression
    Expression theBefore = aList.predecessorOf(aExpression);
    if (theBefore instanceof VariableAssignmentExpression) {
        VariableAssignmentExpression theAssignment = (VariableAssignmentExpression) theBefore;
        Variable theVariable = theAssignment.getVariable();
        Value theValue = theAssignment.getValue();
        // Check if there is only one data flow
        List<Edge> theDataEdges = theVariable.outgoingEdges(DataFlowEdgeType.filter()).collect(Collectors.toList());
        if (theDataEdges.size() == 1) {
            List<Value> theIncomingData = aExpression.incomingDataFlows();
            if (theIncomingData.contains(theVariable)) {
                aExpression.replaceIncomingDataEdge(theVariable, theValue);
                aList.remove(theAssignment);
                aGraph.getProgram().deleteVariable(theVariable);
            }
        }
    }
}
Also used : Variable(de.mirkosertic.bytecoder.ssa.Variable) Expression(de.mirkosertic.bytecoder.ssa.Expression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) Value(de.mirkosertic.bytecoder.ssa.Value) Edge(de.mirkosertic.bytecoder.graph.Edge) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression)

Example 2 with Value

use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.

the class JSSSAWriter method print.

private void print(DirectInvokeMethodExpression aValue) {
    String theMethodName = aValue.getMethodName();
    BytecodeMethodSignature theSignature = aValue.getSignature();
    List<Value> theIncomingData = aValue.incomingDataFlows();
    Value theTarget = theIncomingData.get(0);
    List<Value> theArguments = theIncomingData.subList(1, theIncomingData.size());
    if (!"<init>".equals(theMethodName)) {
        print(theTarget);
        print(".");
        print(JSWriterUtils.toMethodName(theMethodName, theSignature));
    } else {
        print(JSWriterUtils.toClassName(aValue.getClazz()));
        print(".");
        print(JSWriterUtils.toMethodName(theMethodName, theSignature));
    }
    print("(");
    print(theTarget);
    for (Value theArgument : theArguments) {
        print(",");
        print(theArgument);
    }
    print(")");
}
Also used : BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) StringValue(de.mirkosertic.bytecoder.ssa.StringValue) ByteValue(de.mirkosertic.bytecoder.ssa.ByteValue) Value(de.mirkosertic.bytecoder.ssa.Value) ClassReferenceValue(de.mirkosertic.bytecoder.ssa.ClassReferenceValue) SelfReferenceParameterValue(de.mirkosertic.bytecoder.ssa.SelfReferenceParameterValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) NullValue(de.mirkosertic.bytecoder.ssa.NullValue) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) MethodParameterValue(de.mirkosertic.bytecoder.ssa.MethodParameterValue) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Example 3 with Value

use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.

the class JSSSAWriter method print.

private void print(NegatedExpression aValue) {
    Value theValue = aValue.incomingDataFlows().get(0);
    print("(-");
    print(theValue);
    print(")");
}
Also used : StringValue(de.mirkosertic.bytecoder.ssa.StringValue) ByteValue(de.mirkosertic.bytecoder.ssa.ByteValue) Value(de.mirkosertic.bytecoder.ssa.Value) ClassReferenceValue(de.mirkosertic.bytecoder.ssa.ClassReferenceValue) SelfReferenceParameterValue(de.mirkosertic.bytecoder.ssa.SelfReferenceParameterValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) NullValue(de.mirkosertic.bytecoder.ssa.NullValue) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) MethodParameterValue(de.mirkosertic.bytecoder.ssa.MethodParameterValue) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Example 4 with Value

use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.

the class JSSSAWriter method print.

private void print(CompareExpression aValue) {
    List<Value> theIncomingData = aValue.incomingDataFlows();
    Value theVariable1 = theIncomingData.get(0);
    Value theVariable2 = theIncomingData.get(1);
    print("(");
    print(theVariable1);
    print(" > ");
    print(theVariable2);
    print(" ? 1 ");
    print(" : (");
    print(theVariable1);
    print(" < ");
    print(theVariable2);
    print(" ? -1 : 0))");
}
Also used : StringValue(de.mirkosertic.bytecoder.ssa.StringValue) ByteValue(de.mirkosertic.bytecoder.ssa.ByteValue) Value(de.mirkosertic.bytecoder.ssa.Value) ClassReferenceValue(de.mirkosertic.bytecoder.ssa.ClassReferenceValue) SelfReferenceParameterValue(de.mirkosertic.bytecoder.ssa.SelfReferenceParameterValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) NullValue(de.mirkosertic.bytecoder.ssa.NullValue) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) MethodParameterValue(de.mirkosertic.bytecoder.ssa.MethodParameterValue) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Example 5 with Value

use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.

the class JSSSAWriter method print.

private void print(FixedBinaryExpression aValue) {
    Value theValue1 = aValue.incomingDataFlows().get(0);
    print(theValue1);
    switch(aValue.getOperator()) {
        case ISNONNULL:
            print(" != null ");
            break;
        case ISZERO:
            print(" == 0 ");
            break;
        case ISNULL:
            print(" == null ");
            break;
        default:
            throw new IllegalStateException("Unsupported operator : " + aValue.getOperator());
    }
}
Also used : StringValue(de.mirkosertic.bytecoder.ssa.StringValue) ByteValue(de.mirkosertic.bytecoder.ssa.ByteValue) Value(de.mirkosertic.bytecoder.ssa.Value) ClassReferenceValue(de.mirkosertic.bytecoder.ssa.ClassReferenceValue) SelfReferenceParameterValue(de.mirkosertic.bytecoder.ssa.SelfReferenceParameterValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) NullValue(de.mirkosertic.bytecoder.ssa.NullValue) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) MethodParameterValue(de.mirkosertic.bytecoder.ssa.MethodParameterValue) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Aggregations

Value (de.mirkosertic.bytecoder.ssa.Value)34 DoubleValue (de.mirkosertic.bytecoder.ssa.DoubleValue)32 FloatValue (de.mirkosertic.bytecoder.ssa.FloatValue)32 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)32 LongValue (de.mirkosertic.bytecoder.ssa.LongValue)32 ByteValue (de.mirkosertic.bytecoder.ssa.ByteValue)26 ClassReferenceValue (de.mirkosertic.bytecoder.ssa.ClassReferenceValue)26 NullValue (de.mirkosertic.bytecoder.ssa.NullValue)26 ShortValue (de.mirkosertic.bytecoder.ssa.ShortValue)26 StringValue (de.mirkosertic.bytecoder.ssa.StringValue)26 MethodParameterValue (de.mirkosertic.bytecoder.ssa.MethodParameterValue)13 SelfReferenceParameterValue (de.mirkosertic.bytecoder.ssa.SelfReferenceParameterValue)13 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)6 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)5 Variable (de.mirkosertic.bytecoder.ssa.Variable)5 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)4 ExpressionList (de.mirkosertic.bytecoder.ssa.ExpressionList)4 BytecodeFieldRefConstant (de.mirkosertic.bytecoder.core.BytecodeFieldRefConstant)3 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)3 DirectInvokeMethodExpression (de.mirkosertic.bytecoder.ssa.DirectInvokeMethodExpression)3