Search in sources :

Example 6 with FunctionDeclaration

use of org.robovm.compiler.llvm.FunctionDeclaration in project robovm by robovm.

the class ITable method getStruct.

public StructureConstant getStruct(ModuleBuilder mb, SootClass clazz) {
    if (clazz.isInterface()) {
        throw new IllegalArgumentException("Expected a class got an interface: " + clazz.getName());
    }
    ArrayConstantBuilder table = new ArrayConstantBuilder(I8_PTR);
    for (Entry entry : entries) {
        ResolvedEntry resolvedEntry = entry.resolve(clazz);
        if (resolvedEntry == null) {
            FunctionRef defaultFunctionRef = entry.getFunctionRef();
            if (defaultFunctionRef != null) {
                if (!mb.hasSymbol(defaultFunctionRef.getName())) {
                    mb.addFunctionDeclaration(new FunctionDeclaration(defaultFunctionRef));
                }
                table.add(new ConstantBitcast(defaultFunctionRef, I8_PTR));
            } else {
                table.add(new ConstantBitcast(BC_ABSTRACT_METHOD_CALLED, I8_PTR));
            }
        } else if (Modifier.isAbstract(resolvedEntry.getModifiers())) {
            table.add(new ConstantBitcast(BC_ABSTRACT_METHOD_CALLED, I8_PTR));
        } else if (!Modifier.isPublic(resolvedEntry.getModifiers())) {
            table.add(new ConstantBitcast(BC_NON_PUBLIC_METHOD_CALLED, I8_PTR));
        } else {
            /*
                 * Found a non-abstract method implementation. Either on the
                 * class, in one of its super classes or a default method in an
                 * implemented interface.
                 */
            FunctionRef functionRef = resolvedEntry.getFunctionRef();
            if (!resolvedEntry.declaringClass.equals(clazz.getName())) {
                if (!mb.hasSymbol(functionRef.getName())) {
                    mb.addFunctionDeclaration(new FunctionDeclaration(functionRef));
                }
            }
            table.add(new ConstantBitcast(functionRef, I8_PTR));
        }
    }
    return new StructureConstantBuilder().add(new IntegerConstant((short) entries.length)).add(table.build()).build();
}
Also used : ArrayConstantBuilder(org.robovm.compiler.llvm.ArrayConstantBuilder) FunctionDeclaration(org.robovm.compiler.llvm.FunctionDeclaration) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) StructureConstantBuilder(org.robovm.compiler.llvm.StructureConstantBuilder) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 7 with FunctionDeclaration

use of org.robovm.compiler.llvm.FunctionDeclaration in project robovm by robovm.

the class TrampolineCompiler method alias.

private void alias(Trampoline t, String fnName) {
    FunctionRef aliasee = new FunctionRef(fnName, t.getFunctionType());
    if (!mb.hasSymbol(fnName)) {
        mb.addFunctionDeclaration(new FunctionDeclaration(aliasee));
    }
    Function fn = new FunctionBuilder(t).linkage(aliasLinkage()).attribs(shouldInline(), optsize).build();
    Value result = call(fn, aliasee, fn.getParameterRefs());
    fn.add(new Ret(result));
    mb.addFunction(fn);
}
Also used : Ret(org.robovm.compiler.llvm.Ret) FunctionDeclaration(org.robovm.compiler.llvm.FunctionDeclaration) Function(org.robovm.compiler.llvm.Function) Value(org.robovm.compiler.llvm.Value) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Aggregations

FunctionDeclaration (org.robovm.compiler.llvm.FunctionDeclaration)7 FunctionRef (org.robovm.compiler.llvm.FunctionRef)7 Function (org.robovm.compiler.llvm.Function)5 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)4 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)4 Ret (org.robovm.compiler.llvm.Ret)4 Value (org.robovm.compiler.llvm.Value)4 ArrayList (java.util.ArrayList)3 FunctionType (org.robovm.compiler.llvm.FunctionType)3 Global (org.robovm.compiler.llvm.Global)3 Unreachable (org.robovm.compiler.llvm.Unreachable)3 MarshalSite (org.robovm.compiler.MarshalerLookup.MarshalSite)2 MarshalerMethod (org.robovm.compiler.MarshalerLookup.MarshalerMethod)2 PointerMarshalerMethod (org.robovm.compiler.MarshalerLookup.PointerMarshalerMethod)2 ModifiedUtf8HashFunction (org.robovm.compiler.hash.ModifiedUtf8HashFunction)2 ArrayConstantBuilder (org.robovm.compiler.llvm.ArrayConstantBuilder)2 BasicBlockRef (org.robovm.compiler.llvm.BasicBlockRef)2 DataLayout (org.robovm.compiler.llvm.DataLayout)2 Label (org.robovm.compiler.llvm.Label)2 NullConstant (org.robovm.compiler.llvm.NullConstant)2