Search in sources :

Example 16 with Value

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

the class WASMSSAWriter method writeNewMultiArrayValue.

private void writeNewMultiArrayValue(NewMultiArrayExpression aValue) {
    List<Value> theDimensions = aValue.incomingDataFlows();
    BytecodeTypeRef theType = aValue.getType();
    String theMethodName;
    switch(theDimensions.size()) {
        case 1:
            theMethodName = WASMWriterUtils.toMethodName(BytecodeObjectTypeRef.fromRuntimeClass(MemoryManager.class), "newArray", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Address.class), new BytecodeTypeRef[] { BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT }));
            break;
        case 2:
            theMethodName = WASMWriterUtils.toMethodName(BytecodeObjectTypeRef.fromRuntimeClass(MemoryManager.class), "newArray", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Address.class), new BytecodeTypeRef[] { BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT }));
            break;
        default:
            throw new IllegalStateException("Unsupported number of dimensions : " + theDimensions.size());
    }
    print("(call $");
    print(theMethodName);
    // UNUSED argument
    print(" (i32.const 0) ");
    for (Value theDimension : theDimensions) {
        print(" ");
        writeValue(theDimension);
    }
    // We also need the runtime class
    print(" (get_global $jlrArray__runtimeClass)");
    // Plus the vtable index
    print(" (i32.const ");
    print(idResolver.resolveVTableMethodByType(BytecodeObjectTypeRef.fromRuntimeClass(Array.class)));
    print(")");
    println(") ;; new array of type " + theType);
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) Address(de.mirkosertic.bytecoder.classlib.Address) 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 17 with Value

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

the class WASMSSAWriter method writeArrayStoreExpression.

private void writeArrayStoreExpression(ArrayStoreExpression aExpression) {
    List<Value> theIncomingData = aExpression.incomingDataFlows();
    Value theArray = theIncomingData.get(0);
    Value theIndex = theIncomingData.get(1);
    Value theValue = theIncomingData.get(2);
    // If the index is a constant, we can precompute the offset.
    if (theIndex instanceof IntegerValue) {
        int offset = 20 + ((IntegerValue) theIndex).getIntValue() * 4;
        switch(aExpression.getArrayType().resolve()) {
            case DOUBLE:
            case FLOAT:
                {
                    print("(f32.store ");
                    break;
                }
            default:
                {
                    print("(i32.store ");
                    break;
                }
        }
        print("offset=" + offset + " ");
        writeValue(theArray);
        print(" ");
        writeValue(theValue);
        println(")");
        return;
    }
    switch(aExpression.getArrayType().resolve()) {
        case DOUBLE:
        case FLOAT:
            {
                println("(f32.store offset=20 ");
                break;
            }
        default:
            {
                println("(i32.store offset=20 ");
                break;
            }
    }
    WASMSSAWriter theChild = withDeeperIndent();
    theChild.print("(i32.add ");
    theChild.writeValue(theArray);
    theChild.print(" (i32.mul ");
    theChild.writeValue(theIndex);
    theChild.print(" (i32.const 4)");
    theChild.println("))");
    theChild.writeValue(theValue);
    theChild.println();
    println(")");
}
Also used : IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) 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 18 with Value

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

the class WASMSSAWriter method writeLookupSwitchExpression.

private void writeLookupSwitchExpression(LookupSwitchExpression aExpression) {
    println("(block $outer");
    Value theValue = aExpression.incomingDataFlows().get(0);
    WASMSSAWriter theChild2 = withDeeperIndent();
    // For each statement
    for (Map.Entry<Long, ExpressionList> theEntry : aExpression.getPairs().entrySet()) {
        theChild2.print("(block $switch_");
        theChild2.print(theEntry.getKey());
        theChild2.println();
        WASMSSAWriter theChild3 = theChild2.withDeeperIndent();
        theChild3.print("(br_if $switch_");
        theChild3.print(theEntry.getKey());
        theChild3.print(" (i32.ne (i32.const ");
        theChild3.print(theEntry.getKey());
        theChild3.print(") ");
        theChild3.writeValue(theValue);
        theChild3.print("))");
        theChild3.println();
        theChild3.writeExpressionList(theEntry.getValue());
        theChild3.println();
        theChild3.writeExpressionList(theEntry.getValue());
        theChild3.println("(br $outer)");
        theChild2.println(")");
    }
    writeExpressionList(aExpression.getDefaultExpressions());
    println(")");
}
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) Map(java.util.Map) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList)

Example 19 with Value

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

the class WASMSSAWriter method writeInvokeVirtualValue.

private void writeInvokeVirtualValue(InvokeVirtualMethodExpression aValue) {
    idResolver.registerGlobalType(aValue.getSignature(), false);
    print("(call_indirect $t_");
    print(WASMWriterUtils.toMethodSignature(aValue.getSignature(), false));
    println();
    List<Value> theFlows = aValue.incomingDataFlows();
    Value theTarget = theFlows.get(0);
    List<Value> theVariables = theFlows.subList(1, theFlows.size());
    writeValue(theTarget);
    println();
    for (Value theValue : theVariables) {
        writeValue(theValue);
        println();
    }
    WASMSSAWriter theChild = withDeeperIndent();
    theChild.println("(call_indirect $t_RESOLVEMETHOD");
    WASMSSAWriter theChild2 = theChild.withDeeperIndent();
    theChild2.writeValue(theTarget);
    theChild2.println();
    // This is the method number
    theChild2.print("(i32.const ");
    BytecodeVirtualMethodIdentifier theMethodIdentifier = linkerContext.getMethodCollection().identifierFor(aValue.getMethodName(), aValue.getSignature());
    theChild2.print(theMethodIdentifier.getIdentifier());
    theChild2.println(")");
    // And this is the pointer into the function table
    theChild2.print("(i32.load offset=4 ");
    theChild2.writeValue(theTarget);
    // This is id of the virtual table method
    theChild2.println(")");
    theChild.println(")");
    println(")");
}
Also used : BytecodeVirtualMethodIdentifier(de.mirkosertic.bytecoder.core.BytecodeVirtualMethodIdentifier) 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 20 with Value

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

the class InvokeVirtualOptimizer method visit.

private void visit(VariableAssignmentExpression aExpression, BytecodeLinkerContext aLinkerContext) {
    Value theValue = aExpression.getValue();
    if (theValue instanceof InvokeVirtualMethodExpression) {
        Optional<DirectInvokeMethodExpression> theNewExpression = visit((InvokeVirtualMethodExpression) theValue, aLinkerContext);
        theNewExpression.ifPresent(directInvokeMethodExpression -> aExpression.replaceIncomingDataEdge(theValue, directInvokeMethodExpression));
    }
}
Also used : InvokeVirtualMethodExpression(de.mirkosertic.bytecoder.ssa.InvokeVirtualMethodExpression) Value(de.mirkosertic.bytecoder.ssa.Value) DirectInvokeMethodExpression(de.mirkosertic.bytecoder.ssa.DirectInvokeMethodExpression)

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