Search in sources :

Example 11 with StructureType

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;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) VariableRef(org.robovm.compiler.llvm.VariableRef) Variable(org.robovm.compiler.llvm.Variable) Inttoptr(org.robovm.compiler.llvm.Inttoptr) PointerType(org.robovm.compiler.llvm.PointerType) Getelementptr(org.robovm.compiler.llvm.Getelementptr) Function(org.robovm.compiler.llvm.Function) StructureType(org.robovm.compiler.llvm.StructureType) PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) VoidType(soot.VoidType) Bitcast(org.robovm.compiler.llvm.Bitcast) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value)

Example 12 with StructureType

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);
}
Also used : Function(org.robovm.compiler.llvm.Function) StructureType(org.robovm.compiler.llvm.StructureType) SootField(soot.SootField)

Example 13 with StructureType

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()])));
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) CharType(soot.CharType) LongType(soot.LongType) IntegerType(org.robovm.compiler.llvm.IntegerType) BooleanType(soot.BooleanType) OpaqueType(org.robovm.compiler.llvm.OpaqueType) StructureType(org.robovm.compiler.llvm.StructureType) RefLikeType(soot.RefLikeType) ByteType(soot.ByteType) Type(org.robovm.compiler.llvm.Type) BottomType(soot.jimple.toolkits.typing.fast.BottomType) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayList(java.util.ArrayList) SootField(soot.SootField) ConstantPtrtoint(org.robovm.compiler.llvm.ConstantPtrtoint)

Example 14 with StructureType

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);
}
Also used : StructureType(org.robovm.compiler.llvm.StructureType) Test(org.junit.Test)

Example 15 with StructureType

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"));
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) StructureType(org.robovm.compiler.llvm.StructureType) FunctionType(org.robovm.compiler.llvm.FunctionType) PointerType(org.robovm.compiler.llvm.PointerType) Test(org.junit.Test)

Aggregations

StructureType (org.robovm.compiler.llvm.StructureType)25 FunctionType (org.robovm.compiler.llvm.FunctionType)16 PointerType (org.robovm.compiler.llvm.PointerType)14 Test (org.junit.Test)10 ArrayType (org.robovm.compiler.llvm.ArrayType)8 PrimitiveType (org.robovm.compiler.llvm.PrimitiveType)8 Type (org.robovm.compiler.llvm.Type)8 Value (org.robovm.compiler.llvm.Value)7 Variable (org.robovm.compiler.llvm.Variable)6 LongType (soot.LongType)6 MarshalSite (org.robovm.compiler.MarshalerLookup.MarshalSite)5 MarshalerMethod (org.robovm.compiler.MarshalerLookup.MarshalerMethod)5 Function (org.robovm.compiler.llvm.Function)5 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)5 Load (org.robovm.compiler.llvm.Load)5 ArrayList (java.util.ArrayList)4 AggregateType (org.robovm.compiler.llvm.AggregateType)4 Bitcast (org.robovm.compiler.llvm.Bitcast)4 IntegerType (org.robovm.compiler.llvm.IntegerType)4 Ptrtoint (org.robovm.compiler.llvm.Ptrtoint)4