llvmlite icon indicating copy to clipboard operation
llvmlite copied to clipboard

Ability to wrap existing ctype with llvmlite objects?

Open SamKG opened this issue 5 years ago • 3 comments

If I have an existing ctype object, is there any way for me to create a llvmlite object that refers to the ctype object?

SamKG avatar Jun 27 '19 15:06 SamKG

I will need more details to answer your question. With "refers to", do you want a pointer to the ctypes object in memory? You can do so by referring to it as a void* (i.e. i8*) from llvmlite.

If you want to manipulate the ctypes data, it will be more involved.

sklam avatar Jun 27 '19 18:06 sklam

Yes, by 'refer' I mean as a pointer to the ctype object. What would prevent me from modifying the data directly?

SamKG avatar Jun 27 '19 20:06 SamKG

There are multiple ways:

  • To pass ctypes object into a LLVM jitted function, see example at https://github.com/numba/llvmlite/blob/master/examples/sum.py.
  • To reference in-memory ctypes object as a global value, you can use inttoptr to convert the address directly into a pointer to the data.
  • You can also use add_symbol() to bind the address to a global variable name.

Also take a look at https://godbolt.org/z/qvBotR to understand what LLVM IR to emit.

sklam avatar Jun 28 '19 14:06 sklam