use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class MarshalerLookupTest method testFindMarshalerMethodUnsuccessfulSearchUnsupportedCallTypeCallback.
@Test
public void testFindMarshalerMethodUnsuccessfulSearchUnsupportedCallTypeCallback() {
MarshalerLookup lookup = new MarshalerLookup(config).searchBuiltins(false);
SootMethod method = toSootClass(Foo4.class).getMethodByName("foo5");
try {
lookup.findMarshalerMethod(new MarshalSite(method)).getMethod();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
try {
lookup.findMarshalerMethod(new MarshalSite(method, 0)).getMethod();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
}
use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class BridgeMethodCompiler method updateObject.
private void updateObject(SootMethod method, Function fn, Value env, long flags, List<MarshaledArg> marshaledArgs) {
for (MarshaledArg value : marshaledArgs) {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method, value.paramIndex));
SootMethod afterMethod = ((PointerMarshalerMethod) marshalerMethod).getAfterBridgeCallMethod();
if (afterMethod != null) {
Invokestatic invokestatic = new Invokestatic(getInternalName(method.getDeclaringClass()), getInternalName(afterMethod.getDeclaringClass()), afterMethod.getName(), getDescriptor(afterMethod));
trampolines.add(invokestatic);
call(fn, invokestatic.getFunctionRef(), env, value.object, value.handle, new IntegerConstant(flags));
}
}
}
use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class BroMethodCompiler method loadValueForGetter.
protected Value loadValueForGetter(SootMethod method, Function fn, Type memberType, Value memberPtr, Value env, boolean dereference, long flags) {
soot.Type type = method.getReturnType();
Value result = null;
if (memberType instanceof StructureType) {
// The member is a child struct contained in the current struct
result = memberPtr;
} else if (memberType instanceof ArrayType) {
// The member is an array contained in the current struct
result = memberPtr;
} else if (dereference) {
Variable tmp = fn.newVariable(memberType);
fn.add(new Load(tmp, memberPtr));
result = tmp.ref();
} else {
// Do not dereference the pointer but use it as is. This is needed for
// global values such as _dispatch_main_q which is a struct and not a
// pointer which we should load. We want the address of the struct.
Variable tmp = fn.newVariable(memberType);
fn.add(new Bitcast(tmp, memberPtr, tmp.getType()));
result = tmp.ref();
}
if (needsMarshaler(type)) {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method));
String targetClassName = getInternalName(type);
if (memberType instanceof PrimitiveType) {
// Value type wrapping a primitive value (e.g. Enum, Integer and Bits)
result = marshalNativeToValueObject(fn, marshalerMethod, env, targetClassName, result, flags);
} else {
if (memberType instanceof ArrayType) {
// Array
result = marshalNativeToArray(fn, marshalerMethod, env, targetClassName, result, flags, getArrayDimensions(method));
} else {
result = marshalNativeToObject(fn, marshalerMethod, null, env, targetClassName, result, flags);
}
}
} else {
result = marshalNativeToPrimitive(fn, method, result);
}
return result;
}
use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class CallbackMethodCompiler method updateNative.
private void updateNative(SootMethod method, Function fn, Value env, long flags, List<MarshaledArg> marshaledArgs) {
for (MarshaledArg value : marshaledArgs) {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method, value.paramIndex));
SootMethod afterMethod = ((PointerMarshalerMethod) marshalerMethod).getAfterCallbackCallMethod();
if (afterMethod != null) {
Invokestatic invokestatic = new Invokestatic(getInternalName(method.getDeclaringClass()), getInternalName(afterMethod.getDeclaringClass()), afterMethod.getName(), getDescriptor(afterMethod));
trampolines.add(invokestatic);
call(fn, invokestatic.getFunctionRef(), env, value.handle, value.object, new IntegerConstant(flags));
}
}
}
use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class BroMethodCompiler method getStructMemberType.
public Type getStructMemberType(SootMethod method) {
String methodType = hasStructMemberAnnotation(method) ? "@StructMember" : "@GlobalValue";
SootMethod getter = method.getParameterCount() == 0 ? method : null;
SootMethod setter = getter == null ? method : null;
soot.Type type = getter != null ? getter.getReturnType() : setter.getParameterType(0);
Type memberType = null;
if (getter != null && hasPointerAnnotation(getter) || setter != null && hasPointerAnnotation(setter, 0)) {
memberType = I8_PTR;
} else if (getter != null && hasMachineSizedFloatAnnotation(getter) || setter != null && hasMachineSizedFloatAnnotation(setter, 0)) {
memberType = config.getArch().is32Bit() ? FLOAT : DOUBLE;
} else if (getter != null && (hasMachineSizedSIntAnnotation(getter) || hasMachineSizedUIntAnnotation(getter)) || setter != null && (hasMachineSizedSIntAnnotation(setter, 0) || hasMachineSizedUIntAnnotation(setter, 0))) {
memberType = config.getArch().is32Bit() ? I32 : I64;
} else if (type instanceof PrimType) {
memberType = getType(type);
} else if (getter != null && hasArrayAnnotation(getter) || setter != null && hasArrayAnnotation(setter, 0)) {
int[] dimensions = getter != null ? getArrayDimensions(getter) : getArrayDimensions(setter, 0);
if (dimensions == null || dimensions.length == 0) {
throw new IllegalArgumentException("No dimensions specified for @Array annotation on " + methodType + " " + (getter != null ? "getter" : "setter") + " " + method);
}
if (type instanceof soot.ArrayType && ((soot.ArrayType) type).numDimensions != dimensions.length) {
throw new IllegalArgumentException("Mismatch in number of dimennsions for @Array annotation " + "and type on " + methodType + " " + (getter != null ? "getter" : "setter") + " " + method);
}
Type baseType = null;
if (type instanceof soot.ArrayType) {
soot.ArrayType arrayType = (soot.ArrayType) type;
if (isStruct(arrayType.baseType)) {
// ByVal is implied for arrays of structs
try {
baseType = getStructType(arrayType.baseType);
} catch (StackOverflowError e) {
throw new IllegalArgumentException("Struct type " + type + " refers to itself");
}
} else {
baseType = getType(arrayType.baseType);
}
} else if (isStruct(type)) {
// ByVal is implied
try {
baseType = getStructType(type);
} catch (StackOverflowError e) {
throw new IllegalArgumentException("Struct type " + type + " refers to itself");
}
} else if (type instanceof RefType) {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(getter != null ? new MarshalSite(getter) : new MarshalSite(setter, 0));
baseType = getType(((ArrayMarshalerMethod) marshalerMethod).getBaseType());
}
if (baseType == null) {
throw new IllegalArgumentException("Arrays of " + type + " is not supported");
}
long total = dimensions[0];
for (int i = 1; i < dimensions.length; i++) {
total *= dimensions[i];
}
memberType = new ArrayType(total, baseType);
} else if (isStruct(type)) {
boolean byVal = getter != null ? isPassByValue(getter) : isPassByValue(setter, 0);
if (!byVal) {
// NOTE: We use i8* instead of <StructType>* to support pointers to recursive structs
memberType = I8_PTR;
} else {
try {
memberType = getStructType(type);
} catch (StackOverflowError e) {
throw new IllegalArgumentException("Struct type " + type + " refers to itself");
}
}
} else if (isNativeObject(type)) {
memberType = I8_PTR;
} else {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(getter != null ? new MarshalSite(getter) : new MarshalSite(setter, 0));
if (marshalerMethod instanceof ValueMarshalerMethod) {
memberType = ((ValueMarshalerMethod) marshalerMethod).getNativeType(config.getArch());
} else {
memberType = I8_PTR;
}
}
return memberType;
}
Aggregations