Whoa, now this is a cool idea. The Emscripten guys are back at it again compiling LLVM itself to JavaScript to run in the browser. Now you can compile and run LLVM IR assembly directly in the browser using LLVM.js.

Emscripten, for those that don’t know is an LLVM bytecode to JavaScript compiler. LLVM is a compiler backend for many languages like C and C++ via the Clang compiler, Objective-C and several others. Those compilers generate LLVM bytecode which LLVM normally compiles to native machine code, but Emscripten replaces that output with JavaScript instead, enabling programs written in any language supporting LLVM to be run wherever JavaScript runs.

LLVM.js takes Emscripten a step further by compiling LLVM itself to JavaScript, using Emscripten (which uses LLVM). Whoa! This means that you can now compile and run LLVM assembly directly in JavaScript without installing the native LLVM tools. If language compilers supporting LLVM such as Clang were also compiled to JavaScript, you could compile and run C/C++ code directly in JavaScript as well.

This is a very cool demo. I’m not sure how practical it really is to wait until runtime to compile your code rather than precompiling it, but it could be useful to avoid having to install the LLVM tools, or for platforms where the LLVM compiler cannot run (such as mobile operating systems).

Check out the code on Github, and try your hand at LLVM assembly on the demo page.