llvmlite
llvmlite copied to clipboard
Ability to wrap existing ctype with llvmlite objects?
If I have an existing ctype object, is there any way for me to create a llvmlite object that refers to the ctype object?
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.
Yes, by 'refer' I mean as a pointer to the ctype object. What would prevent me from modifying the data directly?
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.