Search in sources :

Example 21 with Value

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

the class OpenCLWriter method printArrayEntryValue.

private void printArrayEntryValue(ArrayEntryExpression aValue) {
    List<Value> theIncomingData = aValue.incomingDataFlows();
    Value theArray = theIncomingData.get(0);
    Value theIndex = theIncomingData.get(1);
    if (aValue.resolveType().isObject()) {
        print("&");
    }
    printValue(theArray);
    print("[");
    printValue(theIndex);
    print("]");
}
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 22 with Value

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

the class OpenCLWriter method printDirectInvokeMethodExpression.

private void printDirectInvokeMethodExpression(DirectInvokeMethodExpression aExpression) {
    print(aExpression.getMethodName());
    print("(");
    List<OpenCLInputOutputs.KernelArgument> theArguments = inputOutputs.arguments();
    boolean theFirst = true;
    for (int i = 0; i < theArguments.size(); i++) {
        theFirst = false;
        if (i > 0) {
            print(", ");
        }
        OpenCLInputOutputs.KernelArgument theArgument = theArguments.get(i);
        print(theArgument.getField().getValue().getName().stringValue());
    }
    List<Value> theMethodArguments = aExpression.incomingDataFlows();
    for (int i = 1; i < theMethodArguments.size(); i++) {
        Value theValue = theMethodArguments.get(i);
        if (theFirst) {
            theFirst = false;
        } else {
            print(",");
        }
        print("&");
        printValue(theValue);
    }
    print(")");
}
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 23 with Value

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

the class WASMSSAWriter method writeCompareValue.

private void writeCompareValue(CompareExpression aValue) {
    List<Value> theIncomingFlows = aValue.incomingDataFlows();
    Value theValue1 = theIncomingFlows.get(0);
    Value theValue2 = theIncomingFlows.get(1);
    TypeRef.Native theValue1Type = theValue1.resolveType().resolve();
    TypeRef.Native theValue2Type = theValue2.resolveType().resolve();
    if (theValue1Type != theValue2Type) {
        throw new IllegalStateException("Does not support mixed types : " + theValue1Type + " -> " + theValue2Type);
    }
    switch(theValue1Type) {
        case DOUBLE:
        case FLOAT:
            print("(call $compareValueF32 ");
            break;
        default:
            print("(call $compareValueI32 ");
            break;
    }
    writeValue(theValue1);
    print(" ");
    writeValue(theValue2);
    print(")");
}
Also used : BytecodePrimitiveTypeRef(de.mirkosertic.bytecoder.core.BytecodePrimitiveTypeRef) 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) 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) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Example 24 with Value

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

the class WASMSSAWriter method writeNegateValue.

private void writeNegateValue(NegatedExpression aValue) {
    Value theValue = aValue.incomingDataFlows().get(0);
    switch(theValue.resolveType().resolve()) {
        case DOUBLE:
        case FLOAT:
            {
                print("(f32.neg ");
                writeValue(theValue);
                print(")");
            }
            break;
        default:
            print("(i32.mul (i32.const -1) ");
            writeValue(theValue);
            print(")");
            break;
    }
}
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) 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) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue)

Example 25 with Value

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

the class WASMSSAWriter method writeBinaryValue.

private void writeBinaryValue(BinaryExpression aValue) {
    List<Value> theIncomingData = aValue.incomingDataFlows();
    Value theValue1 = theIncomingData.get(0);
    Value theValue2 = theIncomingData.get(1);
    String theType1 = WASMWriterUtils.toType(theValue1.resolveType());
    String theType2 = WASMWriterUtils.toType(theValue2.resolveType());
    switch(aValue.getOperator()) {
        case NOTEQUALS:
            {
                println("(" + theType1 + ".ne ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case EQUALS:
            {
                println("(" + theType1 + ".eq ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case LESSTHAN:
            {
                if ("i32".equals(theType1)) {
                    println("(" + theType1 + ".lt_s ");
                } else {
                    println("(" + theType1 + ".lt ");
                }
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case LESSTHANOREQUALS:
            {
                if ("i32".equals(theType1)) {
                    println("(" + theType1 + ".le_s ");
                } else {
                    println("(" + theType1 + ".le ");
                }
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case GREATEROREQUALS:
            {
                if ("i32".equals(theType1)) {
                    println("(" + theType1 + ".ge_s ");
                } else {
                    println("(" + theType1 + ".ge ");
                }
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case GREATERTHAN:
            {
                if ("i32".equals(theType1)) {
                    println("(" + theType1 + ".gt_s ");
                } else {
                    println("(" + theType1 + ".gt ");
                }
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case ADD:
            {
                println("(" + theType1 + ".add ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case MUL:
            {
                println("(" + theType1 + ".mul");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case DIV:
            {
                println("(f32.div ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.printVariableNameOrValueAsFloat(theValue1);
                theChild.println();
                theChild.printVariableNameOrValueAsFloat(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case REMAINDER:
            {
                if (theValue1.resolveType().resolve() == TypeRef.Native.INT) {
                    println("(i32.rem_s ");
                    WASMSSAWriter theChild = withDeeperIndent();
                    theChild.writeValue(theValue1);
                    theChild.println();
                    theChild.writeValue(theValue2);
                    theChild.println();
                    println(")");
                    break;
                }
                print("(call $float_remainder ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                print(")");
                break;
            }
        case SUB:
            {
                println("(" + theType1 + ".sub ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYXOR:
            {
                println("(" + theType1 + ".xor ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYOR:
            {
                println("(" + theType1 + ".or ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYAND:
            {
                println("(" + theType1 + ".and ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYSHIFTLEFT:
            {
                println("(" + theType1 + ".shl ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYSHIFTRIGHT:
            {
                println("(" + theType1 + ".shr_s ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        case BINARYUNSIGNEDSHIFTRIGHT:
            {
                println("(" + theType1 + ".shr_u ");
                WASMSSAWriter theChild = withDeeperIndent();
                theChild.writeValue(theValue1);
                theChild.println();
                theChild.writeValue(theValue2);
                theChild.println();
                println(")");
                break;
            }
        default:
            throw new IllegalStateException("Operator not supported : " + 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) 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) 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