Search in sources :

Example 16 with StructureType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperPointerParameters.

@Test
public void testCreateBridgeCWrapperPointerParameters() {
    FunctionType functionType = new FunctionType(VOID, I8_PTR, new PointerType(new StructureType(I32)));
    assertEquals("void f(void* target, void* p0, void* p1) {\n" + "    ((void (*)(void*, void*)) target)(p0, p1);\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 17 with StructureType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperComplexNestedStructByValReturnAndParameter.

@Test
public void testCreateBridgeCWrapperComplexNestedStructByValReturnAndParameter() {
    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))));
    FunctionType functionType = new FunctionType(structType, structType);
    assertEquals("void f(void* target, void* ret, void* p0) {\n" + "    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" + "    *((struct f_0000*)ret) = ((struct f_0000 (*)(struct f_0001)) target)(*((struct f_0001*)p0));\n" + "}\n", BridgeMethodCompiler.createBridgeCWrapper(functionType.getReturnType(), functionType.getParameterTypes(), functionType.getParameterTypes(), "f"));
}
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)

Example 18 with StructureType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperIgnoresEmptyStructAsFirstMember.

@Test
public void testCreateBridgeCWrapperIgnoresEmptyStructAsFirstMember() {
    FunctionType functionType = new FunctionType(VOID, new StructureType(new StructureType(), I32));
    assertEquals("void f(void* target, void* p0) {\n" + "    struct f_0001 {int m1;};\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) Test(org.junit.Test)

Example 19 with StructureType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperNestedStructByValReturn.

@Test
public void testCreateBridgeCWrapperNestedStructByValReturn() {
    FunctionType functionType = new FunctionType(new StructureType(new StructureType(I32), new StructureType(I32)));
    assertEquals("void f(void* target, void* ret) {\n" + "    struct f_0000_0001 {int m0;};\n" + "    struct f_0000_0000 {int m0;};\n" + "    struct f_0000 {struct f_0000_0000 m0;struct f_0000_0001 m1;};\n" + "    *((struct f_0000*)ret) = ((struct f_0000 (*)(void)) target)();\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) Test(org.junit.Test)

Example 20 with StructureType

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

the class BroMethodCompiler method mergeStructMemberTypes.

static Type mergeStructMemberTypes(DataLayout dataLayout, Type t1, Type t2) {
    int align1 = dataLayout.getAlignment(t1);
    int align2 = dataLayout.getAlignment(t2);
    int size1 = dataLayout.getStoreSize(t1);
    int size2 = dataLayout.getStoreSize(t2);
    Type result = align1 < align2 ? t2 : t1;
    int size = align1 < align2 ? size2 : size1;
    int pad = Math.max(size1, size2) - size;
    if (pad > 0) {
        return new StructureType(result, new ArrayType(pad, I8));
    } else {
        return result;
    }
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) 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) StructureType(org.robovm.compiler.llvm.StructureType) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint)

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