Search in sources :

Example 16 with BytecodeLinkedClass

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

the class JSSSAWriter method print.

private void print(InstanceOfExpression aValue) {
    Value theValue = aValue.incomingDataFlows().get(0);
    print("(");
    print(theValue);
    print(" == null ? false : ");
    print(theValue);
    print(".instanceOf(");
    BytecodeUtf8Constant theConstant = aValue.getType().getConstant();
    if (!theConstant.stringValue().startsWith("[")) {
        BytecodeLinkedClass theLinkedClass = linkerContext.isLinkedOrNull(aValue.getType().getConstant());
        print(JSWriterUtils.toClassName(theLinkedClass.getClassName()));
    } else {
        BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromRuntimeClass(Array.class));
        print(JSWriterUtils.toClassName(theLinkedClass.getClassName()));
    }
    print(")");
    print(")");
}
Also used : Array(java.lang.reflect.Array) BytecodeUtf8Constant(de.mirkosertic.bytecoder.core.BytecodeUtf8Constant) 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) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Example 17 with BytecodeLinkedClass

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

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