Search in sources :

Example 6 with Value

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

the class JSSSAWriter method print.

private void print(InvokeStaticMethodExpression aValue) {
    String theMethodName = aValue.getMethodName();
    BytecodeMethodSignature theSignature = aValue.getSignature();
    List<Value> theVariables = aValue.incomingDataFlows();
    print(JSWriterUtils.toClassName(aValue.getClassName()));
    print(".");
    print(JSWriterUtils.toMethodName(theMethodName, theSignature));
    print("(");
    for (int i = 0; i < theVariables.size(); i++) {
        if (i > 0) {
            print(",");
        }
        print(theVariables.get(i));
    }
    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 7 with Value

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

the class JSSSAWriter method print.

private void print(NewArrayExpression aValue) {
    BytecodeTypeRef theType = aValue.getType();
    Value theLength = aValue.incomingDataFlows().get(0);
    Object theDefaultValue = theType.defaultValue();
    String theStrDefault = theDefaultValue != null ? theDefaultValue.toString() : "null";
    print("bytecoder.newArray(");
    print(theLength);
    print(",");
    print(theStrDefault);
    print(")");
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef) 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 8 with Value

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

the class JSSSAWriter method print.

private void print(TypeConversionExpression aValue) {
    TypeRef theTargetType = aValue.resolveType();
    Value theValue = aValue.incomingDataFlows().get(0);
    switch(theTargetType.resolve()) {
        case FLOAT:
            print(theValue);
            break;
        case DOUBLE:
            print(theValue);
            break;
        default:
            print("Math.floor(");
            print(theValue);
            print(")");
            break;
    }
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef) TypeRef(de.mirkosertic.bytecoder.ssa.TypeRef) BytecodeObjectTypeRef(de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef) 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 9 with Value

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

the class OpenCLWriter method printCompareExpression.

private void printCompareExpression(CompareExpression aExpression) {
    List<Value> theIncomingData = aExpression.incomingDataFlows();
    Value theVariable1 = theIncomingData.get(0);
    Value theVariable2 = theIncomingData.get(1);
    print("(");
    printValue(theVariable1);
    print(" > ");
    printValue(theVariable2);
    print(" ? 1 ");
    print(" : (");
    printValue(theVariable1);
    print(" < ");
    printValue(theVariable2);
    print(" ? -1 : 0))");
}
Also used : DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) Value(de.mirkosertic.bytecoder.ssa.Value) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue)

Example 10 with Value

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

the class OpenCLWriter method writeExpressions.

private void writeExpressions(ExpressionList aList) {
    for (Expression theExpression : aList.toList()) {
        if (options.isDebugOutput()) {
            String theComment = theExpression.getComment();
            if (theComment != null && !theComment.isEmpty()) {
                print("// ");
                println(theComment);
            }
        }
        if (theExpression instanceof VariableAssignmentExpression) {
            VariableAssignmentExpression theInit = (VariableAssignmentExpression) theExpression;
            Variable theVariable = theInit.getVariable();
            Value theValue = theInit.getValue();
            if (theVariable.resolveType().isObject() && theValue instanceof InvocationExpression) {
                print(toType(theVariable.resolveType(), false));
                print(" ");
                print(theVariable.getName());
                print("_temp = ");
                printValue(theValue);
                println(";");
                print(theVariable.getName());
                print(" = &");
                print(theVariable.getName());
                println("_temp;");
            } else {
                print(theVariable.getName());
                print(" = ");
                printValue(theValue);
                println(";");
            }
        } else if (theExpression instanceof ArrayStoreExpression) {
            ArrayStoreExpression theStore = (ArrayStoreExpression) theExpression;
            List<Value> theIncomingData = theStore.incomingDataFlows();
            Value theArray = theIncomingData.get(0);
            Value theIndex = theIncomingData.get(1);
            Value theValue = theIncomingData.get(2);
            printValue(theArray);
            print("[");
            printValue(theIndex);
            print("] = ");
            printValue(theValue);
            println(";");
        } else if (theExpression instanceof IFExpression) {
            IFExpression theE = (IFExpression) theExpression;
            print("if ");
            printValue(theE.incomingDataFlows().get(0));
            println(" {");
            withDeeperIndent().writeExpressions(theE.getExpressions());
            println("}");
        } else if (theExpression instanceof BreakExpression) {
            BreakExpression theBreak = (BreakExpression) theExpression;
            if (theBreak.isSetLabelRequired()) {
                print("$__label__ = ");
                print(theBreak.jumpTarget().getAddress());
                println(";");
            }
            if (!theBreak.isSilent()) {
                print("goto $");
                print(theBreak.blockToBreak().name());
                println("_next;");
            }
        } else if (theExpression instanceof ContinueExpression) {
            ContinueExpression theContinue = (ContinueExpression) theExpression;
            print("$__label__ = ");
            print(theContinue.jumpTarget().getAddress());
            println(";");
            print("goto $");
            print(theContinue.labelToReturnTo().name());
            println(";");
        } else if (theExpression instanceof ReturnExpression) {
            println("return;");
        } else if (theExpression instanceof PutFieldExpression) {
            PutFieldExpression thePutField = (PutFieldExpression) theExpression;
            List<Value> theIncomingData = thePutField.incomingDataFlows();
            Value theTarget = theIncomingData.get(0);
            BytecodeFieldRefConstant theField = thePutField.getField();
            Value thevalue = theIncomingData.get(1);
            printValue(theTarget);
            printInstanceFieldReference(theField);
            print(" = ");
            printValue(thevalue);
            println(";");
        } else if (theExpression instanceof ReturnValueExpression) {
            ReturnValueExpression theReturn = (ReturnValueExpression) theExpression;
            List<Value> theIncomingData = theReturn.incomingDataFlows();
            print("return ");
            printValue(theIncomingData.get(0));
            println(";");
        } else {
            throw new IllegalArgumentException("Not supported. " + theExpression);
        }
    }
}
Also used : Variable(de.mirkosertic.bytecoder.ssa.Variable) InvocationExpression(de.mirkosertic.bytecoder.ssa.InvocationExpression) IFExpression(de.mirkosertic.bytecoder.ssa.IFExpression) PutFieldExpression(de.mirkosertic.bytecoder.ssa.PutFieldExpression) BreakExpression(de.mirkosertic.bytecoder.ssa.BreakExpression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) ReturnValueExpression(de.mirkosertic.bytecoder.ssa.ReturnValueExpression) ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) ArrayStoreExpression(de.mirkosertic.bytecoder.ssa.ArrayStoreExpression) ContinueExpression(de.mirkosertic.bytecoder.ssa.ContinueExpression) InvokeVirtualMethodExpression(de.mirkosertic.bytecoder.ssa.InvokeVirtualMethodExpression) TypeConversionExpression(de.mirkosertic.bytecoder.ssa.TypeConversionExpression) CompareExpression(de.mirkosertic.bytecoder.ssa.CompareExpression) DirectInvokeMethodExpression(de.mirkosertic.bytecoder.ssa.DirectInvokeMethodExpression) InvocationExpression(de.mirkosertic.bytecoder.ssa.InvocationExpression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) InvokeStaticMethodExpression(de.mirkosertic.bytecoder.ssa.InvokeStaticMethodExpression) ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) ReturnValueExpression(de.mirkosertic.bytecoder.ssa.ReturnValueExpression) ArrayStoreExpression(de.mirkosertic.bytecoder.ssa.ArrayStoreExpression) BinaryExpression(de.mirkosertic.bytecoder.ssa.BinaryExpression) GetFieldExpression(de.mirkosertic.bytecoder.ssa.GetFieldExpression) ContinueExpression(de.mirkosertic.bytecoder.ssa.ContinueExpression) IFExpression(de.mirkosertic.bytecoder.ssa.IFExpression) ArrayEntryExpression(de.mirkosertic.bytecoder.ssa.ArrayEntryExpression) Expression(de.mirkosertic.bytecoder.ssa.Expression) PutFieldExpression(de.mirkosertic.bytecoder.ssa.PutFieldExpression) BreakExpression(de.mirkosertic.bytecoder.ssa.BreakExpression) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) Value(de.mirkosertic.bytecoder.ssa.Value) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList) List(java.util.List) BytecodeFieldRefConstant(de.mirkosertic.bytecoder.core.BytecodeFieldRefConstant)

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