Search in sources :

Example 21 with BytecodeMethodSignature

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

the class WASMSSAWriter method writeNewArray.

private void writeNewArray(Value aValue) {
    String theMethodName = WASMWriterUtils.toMethodName(BytecodeObjectTypeRef.fromRuntimeClass(MemoryManager.class), "newArray", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Address.class), new BytecodeTypeRef[] { BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT }));
    print("(call $");
    print(theMethodName);
    // UNUSED argument
    print(" (i32.const 0) ");
    // Length
    withDeeperIndent().writeValue(aValue);
    // 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(")");
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) MemoryManager(de.mirkosertic.bytecoder.classlib.MemoryManager)

Example 22 with BytecodeMethodSignature

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

the class JSSSAWriter method print.

private void print(InvokeVirtualMethodExpression 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());
    BytecodeVirtualMethodIdentifier theMethodIdentifier = linkerContext.getMethodCollection().identifierFor(theMethodName, theSignature);
    if (Objects.equals(aValue.getMethodName(), "invokeWithMagicBehindTheScenes")) {
        print("(");
    } else {
        print(theTarget);
        print(".");
        print(JSWriterUtils.toMethodName(theMethodName, theSignature));
        print("(");
    }
    print(theTarget);
    for (Value theArgument : theArguments) {
        print(",");
        print(theArgument);
    }
    print(")");
}
Also used : BytecodeVirtualMethodIdentifier(de.mirkosertic.bytecoder.core.BytecodeVirtualMethodIdentifier) 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 23 with BytecodeMethodSignature

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

the class CompileTarget method compileToJS.

public CompileResult compileToJS(CompileOptions aOptions, Class aClass, String aMethodName, BytecodeMethodSignature aSignature) {
    BytecodeLinkerContext theLinkerContext = new BytecodeLinkerContext(bytecodeLoader, aOptions.getLogger());
    BytecodeLinkedClass theClassLinkedCass = theLinkerContext.resolveClass(BytecodeObjectTypeRef.fromRuntimeClass(Class.class));
    theClassLinkedCass.resolveConstructorInvocation(new BytecodeMethodSignature(BytecodePrimitiveTypeRef.VOID, new BytecodeTypeRef[] {}));
    // Lambda handling
    BytecodeLinkedClass theCallsite = theLinkerContext.resolveClass(BytecodeObjectTypeRef.fromRuntimeClass(VM.ImplementingCallsite.class));
    theCallsite.resolveVirtualMethod("invokeExact", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Object.class), new BytecodeTypeRef[] { new BytecodeArrayTypeRef(BytecodeObjectTypeRef.fromRuntimeClass(Object.class), 1) }));
    BytecodeObjectTypeRef theTypeRef = BytecodeObjectTypeRef.fromRuntimeClass(aClass);
    BytecodeLinkedClass theClass = theLinkerContext.resolveClass(theTypeRef);
    BytecodeMethod theMethod = theClass.getBytecodeClass().methodByNameAndSignatureOrNull(aMethodName, aSignature);
    if (theMethod.getAccessFlags().isStatic()) {
        theClass.resolveStaticMethod(aMethodName, aSignature);
    } else {
        theClass.resolveVirtualMethod(aMethodName, aSignature);
    }
    // Before code generation we have to make sure that all abstract method implementations are linked correctly
    aOptions.getLogger().info("Resolving abstract method hierarchy");
    theLinkerContext.resolveAbstractMethodsInSubclasses();
    return backend.generateCodeFor(aOptions, theLinkerContext, aClass, aMethodName, aSignature);
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) BytecodeObjectTypeRef(de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef) BytecodeLinkerContext(de.mirkosertic.bytecoder.core.BytecodeLinkerContext) BytecodeArrayTypeRef(de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef) BytecodeMethod(de.mirkosertic.bytecoder.core.BytecodeMethod) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Aggregations

BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)23 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)10 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)9 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)7 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)6 StringValue (de.mirkosertic.bytecoder.ssa.StringValue)6 PrintWriter (java.io.PrintWriter)6 CompileOptions (de.mirkosertic.bytecoder.backend.CompileOptions)5 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)5 BytecodeLinkerContext (de.mirkosertic.bytecoder.core.BytecodeLinkerContext)5 DoubleValue (de.mirkosertic.bytecoder.ssa.DoubleValue)5 FloatValue (de.mirkosertic.bytecoder.ssa.FloatValue)5 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)5 LongValue (de.mirkosertic.bytecoder.ssa.LongValue)5 BytecodeProgram (de.mirkosertic.bytecoder.core.BytecodeProgram)4 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)4 ByteValue (de.mirkosertic.bytecoder.ssa.ByteValue)4 ClassReferenceValue (de.mirkosertic.bytecoder.ssa.ClassReferenceValue)4 Value (de.mirkosertic.bytecoder.ssa.Value)4 Test (org.junit.Test)4