Hi everyone,
I compiled parts of LLVM to JavaScript using emscripten and made a demo of parsing and executing LLVM assembly,
http://kripken.github.com/llvm.js/demo.html
Basically you enter some LLVM IR, press a button and see the output of compiling and running it, directly in the browser.
This was done mainly as a fun hacking project over the holidays, but I'm posting it here in case anyone thinks it might be useful for something - maybe to teach people LLVM IR in a simple way (no need to install anything, just visit a website). If it is potentially useful it can be optimized and polished etc.
- azakai
I compiled parts of LLVM to JavaScript using emscripten and made a demo of parsing and executing LLVM assembly,
http://kripken.github.com/llvm.js/demo.html
Basically you enter some LLVM IR, press a button and see the output of compiling and running it, directly in the browser.
This was done mainly as a fun hacking project over the holidays, but I'm posting it here in case anyone thinks it might be useful for something - maybe to teach people LLVM IR in a simple way (no need to install anything, just visit a website). If it is potentially useful it can be optimized and polished etc.
Cool project. This is a nice complement to http://llvm.org/demo/
Eli
It would be awesome to combine the llvm.org demo with the in-browser emscripten (or possibly a server-side emscripten) so that the user can execute his snippets in the browser.
This would be especially awesome for a C++ tutorial page. Instead of having to start with the arduous process of setting up a compiler environment, the user could jump straight into the fun by typing his programs in the web page and executing them there.
Sebastian
It would definitely be nice to allow compiling C++ to LLVM IR to JS all in the browser, yeah! That means compiling clang to JS though, which would require a fairly large download I think. If there is a way to compile clang with just the parts we need though (just compile a single C/C++ file to only LLVM IR, nothing else) then this would be much simpler.
- azakai
The existing LLVM demo already provides the C --> IR part, so you just
need to run that IR through your execution engine to complete the
whole cycle, IMHO.
Eli
I think speed and download considerations alone make it more reasonable to compile everything on the server, the way the current llvm.org demo page does, but use emscripten's target description, and then run emscripten (also on the server) to generate JS, which can then be loaded back into the web page and executed.
Sebastian
Doing it all on the server would be simpler, yes, but then you do need to maintain the server and make sure it has enough power to handle the load it receives. Compiling it all to JS will make for a larger download and perhaps slower execution (depends on the browser etc.), but would make it not require a server at all. It would also work without a network connection.
I agree both are useful approaches. I went with clientside-everything in this demo because I work on that stuff and like it
But I am happy to help integrate this with the current serverside C/C++ to LLVM IR service.
- azakai
Oh, I agree that it is awesome. It just froze my browser completely for several seconds just compiling the Hello World program.
Sebastian
Yeah, as mentioned in the demo page, it isn't optimized, it's just something I hacked up. With some more work it could be much faster.
A few seconds is slower than I would expect though. It takes me about 1 second for hello world, I am on a nightly build of Firefox though (nightly builds tend to be faster than stable releases), perhaps that is the difference.
- azakai