use of org.robovm.compiler.llvm.StructureType in project robovm by robovm.
the class StructMemberMethodCompiler method structMember.
private Function structMember(ModuleBuilder moduleBuilder, SootMethod method) {
Function function = createMethodFunction(method);
moduleBuilder.addFunction(function);
// Get the value of the handle field in the Struct base class and cast it to a <structType>*
Variable handleI64 = function.newVariable(I64);
function.add(new Load(handleI64, getFieldPtr(function, function.getParameterRef(1), offsetof(new StructureType(DATA_OBJECT, new StructureType(I64)), 1, 0), I64)));
Variable handlePtr = function.newVariable(new PointerType(structType));
function.add(new Inttoptr(handlePtr, handleI64.ref(), handlePtr.getType()));
// Add 1 since the first type in structType is the superclass type or {}.
int offset = getStructMemberOffset(method) + 1;
Type memberType = getStructMemberType(method);
Variable memberPtr = function.newVariable(new PointerType(memberType));
if (memberType != structType.getTypeAt(offset)) {
// Several @StructMembers of different types have this offset (union)
Variable tmp = function.newVariable(new PointerType(structType.getTypeAt(offset)));
function.add(new Getelementptr(tmp, handlePtr.ref(), 0, offset));
function.add(new Bitcast(memberPtr, tmp.ref(), memberPtr.getType()));
} else {
function.add(new Getelementptr(memberPtr, handlePtr.ref(), 0, offset));
}
VariableRef env = function.getParameterRef(0);
if (method.getParameterCount() == 0) {
// Getter
Value result = loadValueForGetter(method, function, memberType, memberPtr.ref(), function.getParameterRef(0), true, MarshalerFlags.CALL_TYPE_STRUCT_MEMBER);
function.add(new Ret(result));
} else {
// Setter
// 'env' is parameter 0, 'this' is at 1, the value we're interested in is at index 2
Value value = function.getParameterRef(2);
storeValueForSetter(method, function, memberType, memberPtr.ref(), env, value, MarshalerFlags.CALL_TYPE_STRUCT_MEMBER);
if (method.getReturnType().equals(VoidType.v())) {
function.add(new Ret());
} else {
function.add(new Ret(function.getParameterRef(1)));
}
}
return function;
}
use of org.robovm.compiler.llvm.StructureType in project robovm by robovm.
the class TrampolineCompiler method createInlinedAccessorForInstanceField.
private void createInlinedAccessorForInstanceField(FieldAccessor t, SootField field) {
Function fn = new FunctionBuilder(t).linkage(aliasLinkage()).attribs(shouldInline(), optsize).build();
List<SootField> classFields = Collections.emptyList();
StructureType classType = new StructureType();
List<SootField> instanceFields = getInstanceFields(config.getOs(), config.getArch(), field.getDeclaringClass());
StructureType instanceType = getInstanceType(config.getOs(), config.getArch(), field.getDeclaringClass());
if (t.isGetter()) {
ClassCompiler.createFieldGetter(fn, field, classFields, classType, instanceFields, instanceType);
} else {
ClassCompiler.createFieldSetter(fn, field, classFields, classType, instanceFields, instanceType);
}
mb.addFunction(fn);
}
use of org.robovm.compiler.llvm.StructureType in project robovm by robovm.
the class Types method getClassType.
public static StructureType getClassType(OS os, Arch arch, SootClass clazz) {
List<Type> types = new ArrayList<Type>();
int offset = 0;
for (SootField field : getClassFields(os, arch, clazz)) {
int falign = getFieldAlignment(os, arch, field);
int padding = (offset & (falign - 1)) != 0 ? (falign - (offset & (falign - 1))) : 0;
types.add(padType(getType(field.getType()), padding));
offset += padding + getFieldSize(arch, field);
}
return new StructureType(CLASS, new StructureType(types.toArray(new Type[types.size()])));
}
use of org.robovm.compiler.llvm.StructureType in project robovm by robovm.
the class TypesTest method testGetInstanceType.
@Test
public void testGetInstanceType() throws Exception {
StructureType type = Types.getInstanceType(OS.ios, Arch.thumbv7, getSootClass(D.class.getName()));
int size = getAllocSize(type, "thumbv7-unknown-ios");
assertEquals(48, size);
}
use of org.robovm.compiler.llvm.StructureType in project robovm by robovm.
the class CallbackMethodCompilerTest method testCreateCallbackCWrapperComplexNestedStructByValReturnAndParameter.
@Test
public void testCreateCallbackCWrapperComplexNestedStructByValReturnAndParameter() {
StructureType structType = new StructureType(new StructureType(I8, I16), new StructureType(I32, I64), new StructureType(FLOAT, DOUBLE), new ArrayType(100, I32), new ArrayType(10, new StructureType(FLOAT, FLOAT)), new ArrayType(5, new ArrayType(10, I32)), new StructureType(I8_PTR, new PointerType(new StructureType(I32))));
assertEquals("struct f_0001_0006 {void* m0;void* m1;};\n" + "struct f_0001_0004 {float m0;float 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;int m3[100];struct f_0001_0004 m4[10];int m5[5][10];struct f_0001_0006 m6;};\n" + "struct f_0000_0006 {void* m0;void* m1;};\n" + "struct f_0000_0004 {float m0;float m1;};\n" + "struct f_0000_0002 {float m0;double m1;};\n" + "struct f_0000_0001 {int m0;long long m1;};\n" + "struct f_0000_0000 {char m0;short m1;};\n" + "struct f_0000 {struct f_0000_0000 m0;struct f_0000_0001 m1;struct f_0000_0002 m2;int m3[100];struct f_0000_0004 m4[10];int m5[5][10];struct f_0000_0006 m6;};\n" + "void* f_inner(void*);\n" + "struct f_0000 f(struct f_0001 p0) {\n" + " return *((struct f_0000*) f_inner((void*) &p0));\n" + "}\n", CallbackMethodCompiler.createCallbackCWrapper(new FunctionType(structType, structType), "f", "f_inner"));
}
Aggregations