[LLVMdev] C/C++ interpreter...

Holger Schurig hs4233 at mail.mn-solutions.de
Thu Jun 19 00:17:50 PDT 2008


> Hi,
>
>    what would be needed to make a C/C++ interpreter using the
> LLVM libraries.

I don't know how your interpreter works, but I guess you lex and 
parse the source-code into an AST. Based on this AST, you're 
interpreting, maybe you generate bytecode like 
perl/python/parrot/lua and interpret this.


If this is true, then you may stop after parsing the AST. Instead 
of interpreting the AST directly or converting the AST to 
bytecode, you now "lower" the AST into llvm-IR.

>From this point on you can follow several roads:

* use the code in lib/ExecutionEngine/Interpreter. Understand 
that one header comment says "This interpreter is designed to be 
a very simple, portable, inefficient interpreter".

* use the JIT. I think that even unoptimized llvm IR get's run 
faster via the JIT than via the interpreter. I also think that 
the JIT is maintained better, e.g. not sure if the interpreter 
already knows the new insertvalue/extractvalue.


Together with the rest of llvm it would now also be easy to 
convert your interpreter to an compiler :-)


> I see there is a libLLVMInterpreter that can interpret the LLVM
> IR. Could this be used to interpret, or a starting point, to an
> real interpreter ?

Yes.




More information about the llvm-dev mailing list