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();
}
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();
}
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"));
}
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;
}
}
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()]));
}
Aggregations