Search in sources :

Example 21 with FunctionType

use of org.robovm.compiler.llvm.FunctionType 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)

Example 22 with FunctionType

use of org.robovm.compiler.llvm.FunctionType 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 23 with FunctionType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperPrimitiveReturn.

@Test
public void testCreateBridgeCWrapperPrimitiveReturn() {
    FunctionType functionType = new FunctionType(I32);
    assertEquals("int f(void* target) {\n" + "    return ((int (*)(void)) target)();\n" + "}\n", BridgeMethodCompiler.createBridgeCWrapper(functionType.getReturnType(), functionType.getParameterTypes(), functionType.getParameterTypes(), "f"));
}
Also used : FunctionType(org.robovm.compiler.llvm.FunctionType) Test(org.junit.Test)

Example 24 with FunctionType

use of org.robovm.compiler.llvm.FunctionType 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 25 with FunctionType

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

the class BridgeMethodCompilerTest method testCreateBridgeCWrapperPointerReturn.

@Test
public void testCreateBridgeCWrapperPointerReturn() {
    FunctionType functionType = new FunctionType(I8_PTR);
    assertEquals("void* f(void* target) {\n" + "    return ((void* (*)(void)) target)();\n" + "}\n", BridgeMethodCompiler.createBridgeCWrapper(functionType.getReturnType(), functionType.getParameterTypes(), functionType.getParameterTypes(), "f"));
}
Also used : FunctionType(org.robovm.compiler.llvm.FunctionType) Test(org.junit.Test)

Aggregations

FunctionType (org.robovm.compiler.llvm.FunctionType)33 PointerType (org.robovm.compiler.llvm.PointerType)16 Test (org.junit.Test)15 StructureType (org.robovm.compiler.llvm.StructureType)15 Type (org.robovm.compiler.llvm.Type)12 FunctionRef (org.robovm.compiler.llvm.FunctionRef)10 Variable (org.robovm.compiler.llvm.Variable)8 ArrayList (java.util.ArrayList)7 Function (org.robovm.compiler.llvm.Function)7 Value (org.robovm.compiler.llvm.Value)7 IntegerType (org.robovm.compiler.llvm.IntegerType)6 Ret (org.robovm.compiler.llvm.Ret)6 ArrayType (org.robovm.compiler.llvm.ArrayType)5 Global (org.robovm.compiler.llvm.Global)5 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)5 LongType (soot.LongType)5 PrimType (soot.PrimType)5 Call (org.robovm.compiler.llvm.Call)4 Label (org.robovm.compiler.llvm.Label)4 NullConstant (org.robovm.compiler.llvm.NullConstant)4