Hi, what would be needed to make a C/C++ interpreter using the LLVM libraries. We have in our project (http://root.cern.ch) a C/C++ interpreter (http://root.cern.ch/twiki/bin/view/ROOT/CINT), but it has some limitations (the biggest being maintenance). 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 ? Cheers, Fons. -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers at cern.ch Phone: +41 22 7679248 WWW: http://fons.rademakers.org Fax: +41 22 7669640
On Wed, Jun 18, 2008 at 5:42 AM, Fons Rademakers <Fons.Rademakers at cern.ch> wrote:> Hi, > > what would be needed to make a C/C++ interpreter using the LLVM > libraries.See http://llvm.org/docs/tutorial/. Essentially, what's required is a converter from whatever internal representation you use into LLVM IR, and a bit of glue code to actually execute the generated code.> We have in our project (http://root.cern.ch) a C/C++ interpreter > (http://root.cern.ch/twiki/bin/view/ROOT/CINT), but it has some limitations > (the biggest being maintenance). 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 ?I have no idea what you mean by a real interpreter. LLVM IR is a (low-level) language; there are libraries in the LLVM tree for static compilation, interpretation, and JIT. There's also a command-line tool, called lli, which can interpret and JIT LLVM IR. clang (http://clang.llvm.org) might also be of interest. -Eli
> 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.