[llvm-dev] mcjit C interface problems
Andres Freund via llvm-dev
llvm-dev at lists.llvm.org
Wed Jan 25 18:53:16 PST 2017
On 2017-01-25 18:44:58 -0800, Toshiyasu Morita wrote:
> Andres Freund wrote:
>
> > On 2017-01-25 18:16:09 -0800, Toshiyasu Morita wrote:
> >> Thanks for the tip - getting closer:
> >>
> >> $ ./capi_test 5 6
> >> args[0]: 5
> >> args[1]: 6
> >> result: 4294959200
> >>
> >> Here's the code I changed:
> >>
> >> printf("args[0]: %d\n", (int)LLVMGenericValueToInt(args[0], 0));
> >> printf("args[1]: %d\n", (int)LLVMGenericValueToInt(args[1], 0));
> >>
> >> uint64_t (*func)();
> >> func = (uint64_t (*)())LLVMGetFunctionAddress(engine, "sum");
> >> printf("result: %lu\n", (*func)());
> >
> >You're calling the function without arguments, but it's (in IR) declared
> >to take two. And you're miscasting the return value to be int64, instead
> >of int32 as the function's declared.
>
> Thanks again - revised code snippet:
>
> int (*func)(LLVMGenericValueRef *);
> func = (int (*)(LLVMGenericValueRef *))LLVMGetFunctionAddress(engine,
> "sum");
It's a normal function taking integers. So just pass in the values *as
integers*. What you're doing here is re-interpreting LLVMGenericValueRef
pointers as integers.
> Do the two argument pointers need to be passed separately?
Yes. But as ints.
> Does the function return an LLVMGenericValueRef?
No, an int.
More information about the llvm-dev
mailing list