Search in sources :

Example 16 with BytecodeTypeRef

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

the class JSWriterUtils method toMethodName.

public static String toMethodName(String aMethodName, BytecodeMethodSignature aSignature) {
    String theName = typeRefToString(aSignature.getReturnType());
    theName += aMethodName.replace("<", "").replace(">", "");
    for (BytecodeTypeRef theTypeRef : aSignature.getArguments()) {
        theName += typeRefToString(theTypeRef);
    }
    return theName;
}
Also used : BytecodeTypeRef(de.mirkosertic.bytecoder.core.BytecodeTypeRef)

Example 17 with BytecodeTypeRef

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

BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)17 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)11 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)7 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)6 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)5 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)5 StringValue (de.mirkosertic.bytecoder.ssa.StringValue)5 Address (de.mirkosertic.bytecoder.classlib.Address)4 MemoryManager (de.mirkosertic.bytecoder.classlib.MemoryManager)4 BytecodeProgram (de.mirkosertic.bytecoder.core.BytecodeProgram)4 ArrayList (java.util.ArrayList)4 BytecodeInstructionACONSTNULL (de.mirkosertic.bytecoder.core.BytecodeInstructionACONSTNULL)3 HashSet (java.util.HashSet)3 ConstantPool (de.mirkosertic.bytecoder.backend.ConstantPool)2 VM (de.mirkosertic.bytecoder.classlib.VM)2 BytecodeClass (de.mirkosertic.bytecoder.core.BytecodeClass)2 BytecodeInstructionGOTO (de.mirkosertic.bytecoder.core.BytecodeInstructionGOTO)2 BytecodeInstructionGenericADD (de.mirkosertic.bytecoder.core.BytecodeInstructionGenericADD)2 BytecodeInstructionGenericLOAD (de.mirkosertic.bytecoder.core.BytecodeInstructionGenericLOAD)2 BytecodeInstructionGenericRETURN (de.mirkosertic.bytecoder.core.BytecodeInstructionGenericRETURN)2