Search in sources :

Example 16 with IntegerConstant

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

the class BroMethodCompiler method marshalValueObjectToNative.

protected Value marshalValueObjectToNative(Function fn, MarshalerMethod marshalerMethod, Type nativeType, Value env, Value object, long flags) {
    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);
    Value result = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));
    return marshalPrimitiveToNative(fn, marshalerMethod.getMethod(), result);
}
Also used : Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Value(org.robovm.compiler.llvm.Value) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 17 with IntegerConstant

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

the class BroMethodCompiler method marshalNativeToValueObject.

protected Value marshalNativeToValueObject(Function fn, MarshalerMethod marshalerMethod, Value env, String valueClassName, Value nativeValue, long flags) {
    Invokestatic invokeToObject = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokeToObject);
    Value valueClass = ldcClass(fn, valueClassName, env);
    nativeValue = marshalNativeToPrimitive(fn, marshalerMethod.getMethod(), 1, nativeValue);
    return call(fn, invokeToObject.getFunctionRef(), env, valueClass, nativeValue, new IntegerConstant(flags));
}
Also used : Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Value(org.robovm.compiler.llvm.Value) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 18 with IntegerConstant

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

the class BroMethodCompiler method marshalNativeToArray.

protected Value marshalNativeToArray(Function fn, MarshalerMethod marshalerMethod, Value env, String arrayClassName, Value nativeValue, long flags, int[] dimensions) {
    Invokestatic invokeToObject = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokeToObject);
    Variable handle = fn.newVariable(I64);
    fn.add(new Ptrtoint(handle, nativeValue, I64));
    Value valueClass = ldcClass(fn, arrayClassName, env);
    List<Value> args = new ArrayList<>();
    args.add(env);
    args.add(valueClass);
    args.add(handle.ref());
    args.add(new IntegerConstant(flags));
    args.addAll(arrayDimensionsValues(dimensions));
    return call(fn, invokeToObject.getFunctionRef(), args);
}
Also used : Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Variable(org.robovm.compiler.llvm.Variable) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint) Value(org.robovm.compiler.llvm.Value) ArrayList(java.util.ArrayList) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 19 with IntegerConstant

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

the class BroMethodCompiler method marshalObjectToNative.

protected Value marshalObjectToNative(Function fn, MarshalerMethod marshalerMethod, MarshaledArg marshaledArg, Type nativeType, Value env, Value object, long flags) {
    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);
    Value handle = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));
    Variable nativeValue = fn.newVariable(nativeType);
    if (nativeType instanceof StructureType || nativeType instanceof ArrayType) {
        Variable tmp = fn.newVariable(new PointerType(nativeType));
        fn.add(new Inttoptr(tmp, handle, tmp.getType()));
        fn.add(new Load(nativeValue, tmp.ref()));
    } else {
        fn.add(new Inttoptr(nativeValue, handle, nativeType));
    }
    if (marshaledArg != null) {
        marshaledArg.handle = handle;
        marshaledArg.object = object;
    }
    return nativeValue.ref();
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value) Inttoptr(org.robovm.compiler.llvm.Inttoptr) PointerType(org.robovm.compiler.llvm.PointerType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 20 with IntegerConstant

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

the class ClassCompiler method createLookupFunction.

private void createLookupFunction(SootMethod m) {
    Function function = FunctionBuilder.lookup(m, true);
    mb.addFunction(function);
    Variable reserved0 = function.newVariable(I8_PTR_PTR);
    function.add(new Getelementptr(reserved0, function.getParameterRef(0), 0, 4));
    Variable reserved1 = function.newVariable(I8_PTR_PTR);
    function.add(new Getelementptr(reserved1, function.getParameterRef(0), 0, 5));
    function.add(new Store(getString(m.getName()), reserved0.ref()));
    function.add(new Store(getString(getDescriptor(m)), reserved1.ref()));
    if (!sootClass.isInterface()) {
        int vtableIndex = 0;
        try {
            VTable vtable = config.getVTableCache().get(sootClass);
            vtableIndex = vtable.getEntry(m).getIndex();
        } catch (IllegalArgumentException e) {
        // VTable throws this if any of the superclasses of the class is actually an interface.
        // Shouldn't happen frequently but the DRLVM test suite has some tests for this.
        // Use 0 as vtableIndex since this lookup function will never be called anyway.
        }
        Value classPtr = call(function, OBJECT_CLASS, function.getParameterRef(1));
        Value vtablePtr = call(function, CLASS_VITABLE, classPtr);
        Variable funcPtrPtr = function.newVariable(I8_PTR_PTR);
        function.add(new Getelementptr(funcPtrPtr, vtablePtr, 0, 1, vtableIndex));
        Variable funcPtr = function.newVariable(I8_PTR);
        function.add(new Load(funcPtr, funcPtrPtr.ref()));
        Variable f = function.newVariable(function.getType());
        function.add(new Bitcast(f, funcPtr.ref(), f.getType()));
        Value result = tailcall(function, f.ref(), function.getParameterRefs());
        function.add(new Ret(result));
    } else {
        ITable itable = config.getITableCache().get(sootClass);
        ITable.Entry entry = itable.getEntry(m);
        List<Value> args = new ArrayList<Value>();
        args.add(function.getParameterRef(0));
        args.add(getInfoStruct(function, sootClass));
        args.add(function.getParameterRef(1));
        args.add(new IntegerConstant(entry.getIndex()));
        Value fptr = call(function, BC_LOOKUP_INTERFACE_METHOD_IMPL, args);
        Variable f = function.newVariable(function.getType());
        function.add(new Bitcast(f, fptr, f.getType()));
        Value result = tailcall(function, f.ref(), function.getParameterRefs());
        function.add(new Ret(result));
    }
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) ArrayList(java.util.ArrayList) Store(org.robovm.compiler.llvm.Store) Getelementptr(org.robovm.compiler.llvm.Getelementptr) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) Function(org.robovm.compiler.llvm.Function) Bitcast(org.robovm.compiler.llvm.Bitcast) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) Value(org.robovm.compiler.llvm.Value)

Aggregations

IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)39 Value (org.robovm.compiler.llvm.Value)24 Variable (org.robovm.compiler.llvm.Variable)14 NullConstant (org.robovm.compiler.llvm.NullConstant)11 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)10 FunctionRef (org.robovm.compiler.llvm.FunctionRef)10 ArrayList (java.util.ArrayList)9 Function (org.robovm.compiler.llvm.Function)9 Ret (org.robovm.compiler.llvm.Ret)9 Constant (org.robovm.compiler.llvm.Constant)8 FunctionType (org.robovm.compiler.llvm.FunctionType)8 Global (org.robovm.compiler.llvm.Global)8 PointerType (org.robovm.compiler.llvm.PointerType)8 StructureConstant (org.robovm.compiler.llvm.StructureConstant)8 StructureConstantBuilder (org.robovm.compiler.llvm.StructureConstantBuilder)8 Invokestatic (org.robovm.compiler.trampoline.Invokestatic)8 Bitcast (org.robovm.compiler.llvm.Bitcast)6 Label (org.robovm.compiler.llvm.Label)6 Load (org.robovm.compiler.llvm.Load)6 Type (org.robovm.compiler.llvm.Type)6