Search in sources :

Example 11 with PointerType

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

the class BroMethodCompiler method createStackCopy.

protected Value createStackCopy(Function fn, Value value) {
    Variable stackCopy = fn.newVariable(new PointerType(value.getType()));
    fn.add(new Alloca(stackCopy, value.getType()));
    fn.add(new Store(value, stackCopy.ref()));
    return stackCopy.ref();
}
Also used : Variable(org.robovm.compiler.llvm.Variable) Alloca(org.robovm.compiler.llvm.Alloca) Store(org.robovm.compiler.llvm.Store) PointerType(org.robovm.compiler.llvm.PointerType)

Example 12 with PointerType

use of org.robovm.compiler.llvm.PointerType 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 13 with PointerType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperComplexNestedStructByValParameter.

@Test
public void testCreateBridgeCWrapperComplexNestedStructByValParameter() {
    FunctionType functionType = new FunctionType(VOID, new StructureType(new StructureType(I8, I16), new StructureType(I32, I64), new StructureType(FLOAT, DOUBLE), new StructureType(I8_PTR, new PointerType(new StructureType(I32)))));
    assertEquals("void f(void* target, void* p0) {\n" + "    struct f_0001_0003 {void* m0;void* m1;};\n" + "    struct f_0001_0002 {float m0;double m1;};\n" + "    struct f_0001_0001 {int m0;long long m1;};\n" + "    struct f_0001_0000 {char m0;short m1;};\n" + "    struct f_0001 {struct f_0001_0000 m0;struct f_0001_0001 m1;struct f_0001_0002 m2;struct f_0001_0003 m3;};\n" + "    ((void (*)(struct f_0001)) target)(*((struct f_0001*)p0));\n" + "}\n", BridgeMethodCompiler.createBridgeCWrapper(functionType.getReturnType(), functionType.getParameterTypes(), functionType.getParameterTypes(), "f"));
}
Also used : FunctionType(org.robovm.compiler.llvm.FunctionType) StructureType(org.robovm.compiler.llvm.StructureType) PointerType(org.robovm.compiler.llvm.PointerType) Test(org.junit.Test)

Example 14 with PointerType

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

the class BroMethodCompiler method getParameterType.

private Type getParameterType(String anno, SootMethod method, int i) {
    soot.Type sootType = method.getParameterType(i);
    if (hasPointerAnnotation(method, i)) {
        if (!sootType.equals(LongType.v())) {
            throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type long when annotated with @Pointer.");
        }
        return I8_PTR;
    }
    if (hasMachineSizedFloatAnnotation(method, i)) {
        if (!sootType.equals(DoubleType.v()) && !sootType.equals(FloatType.v())) {
            throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type float or double when annotated with @MachineSizedFloat.");
        }
        return config.getArch().is32Bit() ? FLOAT : DOUBLE;
    }
    if (hasMachineSizedSIntAnnotation(method, i) || hasMachineSizedUIntAnnotation(method, i)) {
        if (!sootType.equals(LongType.v())) {
            throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type long when annotated with " + "@MachineSizedSInt or @MachineSizedUInt");
        }
        return config.getArch().is32Bit() ? I32 : I64;
    }
    if (hasStructRetAnnotation(method, i)) {
        if (i > 0) {
            throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " cannot be annotated with @StructRet. Only the first" + " parameter may have this annotation.");
        }
        if (!isStruct(sootType)) {
            throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be a sub class of Struct when annotated with @StructRet.");
        }
        // @StructRet implies pass by reference
        return new PointerType(getStructType(sootType));
    }
    if (isStruct(sootType)) {
        StructureType structType = getStructType(sootType);
        if (hasByValAnnotation(method, i)) {
            return getStructType(sootType);
        }
        return new PointerType(structType);
    } else if (isNativeObject(sootType)) {
        // NativeObjects are always passed by reference.
        return I8_PTR;
    } else if (sootType instanceof PrimType) {
        return getType(sootType);
    }
    MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method, i));
    if (marshalerMethod instanceof ValueMarshalerMethod) {
        return ((ValueMarshalerMethod) marshalerMethod).getNativeType(config.getArch());
    } else {
        return I8_PTR;
    }
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) ValueMarshalerMethod(org.robovm.compiler.MarshalerLookup.ValueMarshalerMethod) StructureType(org.robovm.compiler.llvm.StructureType) PrimType(soot.PrimType) PointerType(org.robovm.compiler.llvm.PointerType) MarshalerMethod(org.robovm.compiler.MarshalerLookup.MarshalerMethod) ValueMarshalerMethod(org.robovm.compiler.MarshalerLookup.ValueMarshalerMethod) ArrayMarshalerMethod(org.robovm.compiler.MarshalerLookup.ArrayMarshalerMethod)

Example 15 with PointerType

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

the class BroMethodCompiler method getBridgeOrCallbackFunctionType.

private FunctionType getBridgeOrCallbackFunctionType(String anno, SootMethod method, boolean dynamic, boolean considerVariadic) {
    Type returnType = getReturnType(anno, method);
    boolean varargs = considerVariadic && hasVariadicAnnotation(method);
    int variadicIndex = varargs ? getVariadicParameterIndex(method) : Integer.MAX_VALUE;
    List<Type> paramTypes = new ArrayList<>();
    for (int i = dynamic ? 1 : 0; i < method.getParameterCount(); i++) {
        if (i == variadicIndex) {
            break;
        }
        paramTypes.add(getParameterType(anno, method, i));
    }
    if (!method.isStatic()) {
        int idx = hasStructRetAnnotation(method, 0) ? 1 : 0;
        soot.Type sootType = method.getDeclaringClass().getType();
        if (isStruct(sootType)) {
            paramTypes.add(idx, new PointerType(getStructType(sootType)));
        } else if (isNativeObject(sootType)) {
            // NativeObjects are always passed by reference.
            paramTypes.add(idx, I8_PTR);
        } else {
            throw new IllegalArgumentException("Receiver of non static " + anno + " method " + method + " must either be a Struct or a NativeObject");
        }
    }
    return new FunctionType(returnType, varargs, paramTypes.toArray(new Type[paramTypes.size()]));
}
Also used : RefType(soot.RefType) IntegerType(org.robovm.compiler.llvm.IntegerType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayType(org.robovm.compiler.llvm.ArrayType) PointerType(org.robovm.compiler.llvm.PointerType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) LongType(soot.LongType) Type(org.robovm.compiler.llvm.Type) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimitiveType(org.robovm.compiler.llvm.PrimitiveType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayList(java.util.ArrayList) PointerType(org.robovm.compiler.llvm.PointerType) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint)

Aggregations

PointerType (org.robovm.compiler.llvm.PointerType)22 Variable (org.robovm.compiler.llvm.Variable)13 FunctionType (org.robovm.compiler.llvm.FunctionType)11 StructureType (org.robovm.compiler.llvm.StructureType)11 Value (org.robovm.compiler.llvm.Value)9 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)8 Load (org.robovm.compiler.llvm.Load)8 Type (org.robovm.compiler.llvm.Type)8 ArrayType (org.robovm.compiler.llvm.ArrayType)7 Bitcast (org.robovm.compiler.llvm.Bitcast)7 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)6 FunctionRef (org.robovm.compiler.llvm.FunctionRef)6 Getelementptr (org.robovm.compiler.llvm.Getelementptr)6 NullConstant (org.robovm.compiler.llvm.NullConstant)6 Ret (org.robovm.compiler.llvm.Ret)6 PrimType (soot.PrimType)6 Br (org.robovm.compiler.llvm.Br)5 Function (org.robovm.compiler.llvm.Function)5 Icmp (org.robovm.compiler.llvm.Icmp)5 IntegerType (org.robovm.compiler.llvm.IntegerType)5