小编Mic*_*dal的帖子

LLVM和C函数以struct作为参数

我正在研究脚本语言,作为其中的一部分,我正在使用LLVM在我的语言和C之间编写桥接代码.我一直致力于在objective-c中使用LLVM API的包装器,直到这一点为止它一直很好用.

typedef struct _test_struct {
    int x;
    int y;
} test_struct;

id testLLVMStructFuncCall(test_struct x) {
    NSLog(@"%d %d",x.x,x.y);
    return N(x.x + x.y);
}

-(void) testLLVMStructFuncCall {
    CGKModule* myMod = [CGKModule moduleWithName:@"llvm_structfunccall_test"];
    CGKType* testStructType = [CGKType structTypeWithElementTypes:[NSArray arrayWithObjects:[CGKType intTypeWith32Bits],[CGKType intTypeWith32Bits],nil]];
    CGKFunction* lfunc = [CGKFunction functionWithName:@"testLLVMStructFuncCall" types:[NSArray arrayWithObjects:[CGKType idType],testStructType,nil] intoModule:myMod];
    CGKFunction* rfunc = [CGKBuilder createStandaloneCallForFunction:lfunc withArguments:[NSArray 
                                                                                          arrayWithObjects:
                                                                                      [CGKConstant getStructOfType:testStructType 
                                                                                                        withValues:[NSArray arrayWithObjects:[CGKConstant getIntConstant:N(10) bits:32],
                                                                                                                    [CGKConstant getIntConstant:N(25) bits:32],nil]],nil] 
                                                        inModule:myMod];
    [myMod dump];
    id var = [[CGKRunner runnerForModule:myMod] runCGKFunction:rfunc];
    assertThat(var,is(equalTo(N(35))));
}
Run Code Online (Sandbox Code Playgroud)

我在测试的以下输出中看到了我遇到的问题:

Test Case '-[SVFunctionTests testLLVMStructFuncCall]' …
Run Code Online (Sandbox Code Playgroud)

llvm

7
推荐指数
1
解决办法
1415
查看次数

标签 统计

llvm ×1