Search in sources :

Example 6 with BytecodeLinkerContext

use of de.mirkosertic.bytecoder.core.BytecodeLinkerContext 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

BytecodeLinkerContext (de.mirkosertic.bytecoder.core.BytecodeLinkerContext)6 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)5 BytecodeLoader (de.mirkosertic.bytecoder.core.BytecodeLoader)3 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)3 Method (java.lang.reflect.Method)3 CompileOptions (de.mirkosertic.bytecoder.backend.CompileOptions)2 OpenCLCompileBackend (de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileBackend)2 OpenCLCompileResult (de.mirkosertic.bytecoder.backend.opencl.OpenCLCompileResult)2 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)2 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)2 Slf4JLogger (de.mirkosertic.bytecoder.unittest.Slf4JLogger)2 Test (org.junit.Test)2 BytecodeAccessFlags (de.mirkosertic.bytecoder.core.BytecodeAccessFlags)1 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)1 BytecodeClass (de.mirkosertic.bytecoder.core.BytecodeClass)1 BytecodeCodeAttributeInfo (de.mirkosertic.bytecoder.core.BytecodeCodeAttributeInfo)1 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)1 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)1 Relooper (de.mirkosertic.bytecoder.relooper.Relooper)1 NaiveProgramGenerator (de.mirkosertic.bytecoder.ssa.NaiveProgramGenerator)1