Search in sources :

Example 6 with BytecodeLinkedClass

use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.

the class OpenCLWriter method printInvokeStatic.

private void printInvokeStatic(InvokeStaticMethodExpression aValue) {
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aValue.getClassName());
    BytecodeResolvedMethods theMethods = theLinkedClass.resolvedMethods();
    AtomicBoolean theFound = new AtomicBoolean(false);
    theMethods.stream().forEach(aMethodMapsEntry -> {
        BytecodeMethod theMethod = aMethodMapsEntry.getValue();
        if (Objects.equals(theMethod.getName().stringValue(), aValue.getMethodName()) && theMethod.getSignature().metchesExactlyTo(aValue.getSignature())) {
            BytecodeAnnotation theAnnotation = theMethod.getAttributes().getAnnotationByType(OpenCLFunction.class.getName());
            if (theAnnotation == null) {
                throw new IllegalArgumentException("Annotation @OpenCLFunction required for static method " + aValue.getMethodName());
            }
            String theMethodName = theAnnotation.getElementValueByName("value").stringValue();
            BytecodeMethodSignature theSignature = aValue.getSignature();
            print(theMethodName);
            print("(");
            List<Value> theArguments = aValue.incomingDataFlows();
            for (int i = 0; i < theArguments.size(); i++) {
                if (i > 0) {
                    print(",");
                }
                if (!theSignature.getArguments()[i].isPrimitive()) {
                    print("*");
                }
                printValue(theArguments.get(i));
            }
            print(")");
            theFound.set(true);
        }
    });
    if (!theFound.get()) {
        throw new IllegalArgumentException("Not supported method : " + aValue.getMethodName());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BytecodeAnnotation(de.mirkosertic.bytecoder.core.BytecodeAnnotation) BytecodeResolvedMethods(de.mirkosertic.bytecoder.core.BytecodeResolvedMethods) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) BytecodeMethod(de.mirkosertic.bytecoder.core.BytecodeMethod) 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) OpenCLFunction(de.mirkosertic.bytecoder.api.opencl.OpenCLFunction) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Example 7 with BytecodeLinkedClass

use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.

the class OpenCLWriter method printGetFieldValue.

private void printGetFieldValue(GetFieldExpression aValue) {
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
    if (theLinkedClass == kernelClass) {
        print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
    } else {
        Value theValue = aValue.incomingDataFlows().get(0);
        if (theValue instanceof Variable && ((Variable) theValue).isSynthetic()) {
            print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
        } else {
            printValue(theValue);
            printInstanceFieldReference(aValue.getField());
        }
    }
}
Also used : Variable(de.mirkosertic.bytecoder.ssa.Variable) 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) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Example 8 with BytecodeLinkedClass

use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.

the class WASMSSAWriter method writeInstanceOfValue.

private void writeInstanceOfValue(InstanceOfExpression aValue) {
    BytecodeLinkedClass theClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getType().getConstant()));
    print("(call $INSTANCEOF_CHECK ");
    writeValue(aValue.incomingDataFlows().get(0));
    print(" (i32.const ");
    print(theClass.getUniqueId());
    println("))");
}
Also used : BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Example 9 with BytecodeLinkedClass

use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.

the class WASMSSAWriter method writeGetStaticValue.

private void writeGetStaticValue(GetStaticExpression aValue) {
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
    WASMMemoryLayouter.MemoryLayout theLayout = memoryLayouter.layoutFor(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
    int theMemoryOffset = theLayout.offsetForClassMember(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
    String theFieldName = aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue();
    BytecodeResolvedFields theStaticFields = theLinkedClass.resolvedFields();
    BytecodeResolvedFields.FieldEntry theField = theStaticFields.fieldByName(theFieldName);
    if (!theField.getValue().getAccessFlags().isStatic()) {
        throw new IllegalStateException("Field " + theFieldName + " is not static!");
    }
    String theClassName = WASMWriterUtils.toClassName(aValue.getField().getClassIndex().getClassConstant());
    switch(TypeRef.toType(theField.getValue().getTypeRef()).resolve()) {
        case DOUBLE:
        case FLOAT:
            {
                print("(f32.load offset=");
                break;
            }
        default:
            {
                print("(i32.load offset=");
                break;
            }
    }
    print(theMemoryOffset);
    println();
    WASMSSAWriter theChild = withDeeperIndent();
    theChild.print("(get_global $");
    theChild.print(theClassName);
    theChild.println("__runtimeClass)");
    println(")");
}
Also used : BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass) BytecodeResolvedFields(de.mirkosertic.bytecoder.core.BytecodeResolvedFields)

Example 10 with BytecodeLinkedClass

use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.

the class WASMSSAWriter method writeClassReferenceValue.

private void writeClassReferenceValue(ClassReferenceValue aValue) {
    print("(get_global $");
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aValue.getType());
    print(WASMWriterUtils.toClassName(theLinkedClass.getClassName()));
    print("__runtimeClass)");
}
Also used : BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Aggregations

BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)17 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)7 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)6 BytecodeResolvedFields (de.mirkosertic.bytecoder.core.BytecodeResolvedFields)6 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)5 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)5 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)4 DoubleValue (de.mirkosertic.bytecoder.ssa.DoubleValue)4 FloatValue (de.mirkosertic.bytecoder.ssa.FloatValue)4 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)4 LongValue (de.mirkosertic.bytecoder.ssa.LongValue)4 StringValue (de.mirkosertic.bytecoder.ssa.StringValue)4 Value (de.mirkosertic.bytecoder.ssa.Value)4 BytecodeAnnotation (de.mirkosertic.bytecoder.core.BytecodeAnnotation)3 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)3 Relooper (de.mirkosertic.bytecoder.relooper.Relooper)3 Program (de.mirkosertic.bytecoder.ssa.Program)3 ProgramGenerator (de.mirkosertic.bytecoder.ssa.ProgramGenerator)3 Variable (de.mirkosertic.bytecoder.ssa.Variable)3 PrintWriter (java.io.PrintWriter)3