4
votes

I'm making an application and I would like to load and execute llvm bitcode using the ExecutionEngine. I have managed to do this with really simple C code compiled via clang so far.

My thought is, if I use llvm for this project then it could be more language agnostic than say, specifically picking lua/python/javascript. But I'm confused about how this might work for managed or scripting languages since they are often times tied to a platform with resources such as a GC. So I'm not sure how it would actually work through the ExecutionEngine.

So as an example scenario, suppose a user wanted to write some python code that runs in my application. I then want them to deliver to me bitcode representing that python code, which I will then run in my C++ application using llvm's ExecutionEngine.

Is this possible? Can python be simply compiled into bitcode and then run later using the ExecutionEngine? If not, what do I need to know to understand why not?

1
LLVM in this case is not any different from a mere dlopen. - SK-logic
So python would have to compile in everything it needed to run, including the GC, into the bitcode? It could do this? Does it actually do this? - justin.m.chase
numba is a LLVM compiler. But not a big part of the python library is supported yet. - M4rtini
You'll need a python runtime anyway. It's possible to compile the whole python runtime into a single bitcode module, of course, but I see no point in it, it's not any different from embedding the python interpreter the usual way. - SK-logic
@EliBendersky A Python bytecode compiler and interpreter running under PNaCl is not the same as a Python compiler emitting LLVM code. Both might solve OP's use case just fine, but I only claimed one of the two is unlikely to exist ;-) - user395760

1 Answers

0
votes

After some reading and some conversations I believe the answer is that the ExecutionEngine essentially executes code as if it was native C code. Which means if you wanted to execute lua/python/javascript code ontop of llvm you would need to actually send the bitcode for that runtime. Then the runtime could parse and execute the script as usual.

As far as I know none of these runtimes have the ability to compile their script directly into llvm bitcode (yet).