Take the 2-minute tour ×

Is there any tool to convert the LLVM IR code to Python code? I know it is possible to convert it to Javascript (https://github.com/kripken/emscripten/wiki), to Java (http://da.vidr.cc/projects/lljvm/) and I would love to convert it to Python also.

Additionaly if such tool does not exist, could you provide any information, what is the best tool to base on (maybe I should extend the emscripten with other language - Javascript and Python are similar to each other in some terms ;) )

share|improve this question
I'm not aware of such a tool. Although, I would not recommend implementing it as a complete platform backend (it will be an overkill). A simple pass will be sufficient. See the cbe pass, for example. –  SK-logic Nov 16 '12 at 11:28
You are right, it is a good idea. Could you elaborate a little bit more why for example such tool like Emscripten is not written as LLVM pass? It would be a lot easier to use it or embed it in custom compiler. –  Wojciech Danilo Nov 16 '12 at 11:32
probably, they wanted to host the whole thing inside JavaScript. Or they just like coding in JS more than in C++. There are many possible reasons for doing it one way or another. Alternatively, you can do something in between these two options: implement your code generation pass in, say, OCaml, Haskell or Python itself with LLVM bindings. –  SK-logic Nov 16 '12 at 11:36
Thank you. Do you know any projects that use LLVM Pass (in C++) to convert LLVM IR to some specific language code? I want to base on some existing code unless I'm not an LLVM expert :) –  Wojciech Danilo Nov 16 '12 at 11:45
cbe is by far the simplest pass of this kind, I'd recommend to start with it. –  SK-logic Nov 16 '12 at 11:59

1 Answer 1

up vote 1 down vote accepted

LLVM up to 3.0 provided a C backend (see lib/Target/CBackend) which should be a good starting point for implementing a simple Python code generator.

share|improve this answer

Your Answer


