¿Es posible integrar LLVM Interpreter en mi software y tiene sentido?

Suppose I have a software and I want to make cross-plataform plugins. You compile the plugin for a virtual machine, and any platform running my software would be able to run this code.

I am wondering if it is possible to use LLVM interpreter and bytecode for this purpose. Also, I am wondering if does make sense using LLVM for this purpose instead of something else, i.e. is it what LLVM was made for?

preguntado el 08 de noviembre de 11 a las 16:11

Deberías mirar llvm.org , they have plenty of documentation and I've tested jitting as part of a proof-of-concept program some years ago. You should go through the kaleidoscope tutorial, which is also a good tutorial if you start into compiler construction. -

5 Respuestas

I'm not sure that LLVM was diseñado for it. However, I doubt there is anything that hasn't been done using LLVM1

Other virtual-machines based script engines son specifically created for the job:

If you're looking for embeddable virtual machines:

  • IKVM supports embedding JVM and CLR in a bridged mode (interoperable)
  • Parrot supports embedding (and includes a Python interpreter; mind you, you can just run python bytecode images)
  • Perl has similar architecture and supports embedding
  • Javascript supports embedding (not sure about the architecture of v8, but I guess it would use a virtual machine)
  • Mono's CLR engine supports embedding: http://www.mono-project.com/Embedding_Mono

1 including compiling c++ information to javascript to run in your browser...

respondido 08 nov., 11:21

Thank you for the answer. It is being helpful. I am avoiding Lua because I am looking for something more like "virtual machine" and less like "interpreted". Actually, I do not have a real problem where performance is a issue, but I am researching a virtual machine solution with LLVM anyway. - André Puel

@AndréPuel: What's the difference? First off, it's a blurry line in any case: Lua compiles to bytecode and hands that to a bytecode VM (you can also dump the bytecode to a binary file and run that, though it may have portability issues depending on how the Lua VM was compiled). Second, any sensible distiction between "interpreter" and "VM" I can imagine boils down to minor implementation details, which probably shouldn't concern you. - user395760

@delnan I appreciate your comment and I totally agree with you. But it is not a real scenario, lets say I am just wondering about embedding virtual machine in a software. If I had a real scenario where I needed to make extensions I probably would use Lua or something like that. - André Puel

@AndréPuel: My question is simply: What do you call a "virtual machine" and how is the Lua implementation not one? - user395760

@AndréPuel Yup, I'm guessing you'd find 'embedding a Parrot virtual machine' sound more attractive than 'embedding a Python interpreter'. But it is really the same (although, with the VM you could do other languages on top of the same VM... I'm not sure what that would be useful for) - sehe

There is VMIR (https://github.com/andoma/vmir) which is a LLVM bitcode interpreter / JIT engine that's intended to be embedded into other apps.

Disclaimer: I'm the author of it and it's still work-in-progress but works reasonable well.

Respondido 08 ago 16, 22:08

This project is awesome! Really nice! I've loved it. - André Puel

In theory, there exist a limited subset of LLVM IR which can be portable across various platforms. You shall not specify alignments, you shall not bitcast pointers to integral types, you must avoid intrinsics, etc. Which means - you can't immediately use a code generated by a stock C compiler (llvm-gcc, Clang, whatever), unless you specify a limited target for it and implement sanitising LLVM passes. Another issue is that the bitcode format from different LLVM versions is not guaranteed to be compatible.

In practice, I would not go there. Mono is a reasonably small, embeddable, fast VM, and all the .NET stack of tools is available for it. VM itself is pretty low-level (as long as you do not care about the verifyability).

respondido 10 nov., 11:12

LLVM includes an Interprete, so if you can build this interpreter for your target platforms, you can then evaluate LLVM bitcode on the fly.

It's apparently not so fast though.

Respondido 17 Jul 13, 13:07

En su classic discussion (that you do not want to miss if you're a fan of open source, LLVM, compilers) about LLVM vs libJIT, that has happened long before LLVM became famous and established, the author of libJIT Rhys Weatherley raised this particular issue, he stated that LLVM is not suitable to be embedded, while Chris Lattner, the author of LLVM stated that otherwise, it is modular and you can use it in any possible fashion including embedding only the parts you need.

respondido 08 nov., 17:15

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.