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
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:
- LUNA Es muy popular
- Wikipedia lists some other Extension/embeddable languages bajo el Lenguaje de escritura entrada
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
- Mono's CLR engine supports embedding: http://www.mono-project.com/Embedding_Mono
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).
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.