
Emscripten is meant to translate ANY LLVM IR code to javascript and it
should work (as I belive).
I've tried to compile 'hello wrold' Haskell program to JS using Emscripten
but I faced a problem, that in generated LLVM IR code there is no C-like
main function (https://github.com/kripken/emscripten/issues/500) so there
has to be a runtime library that has to be linked and will run the code -
is this "RTS" or something else?
If its RTS I understeand I should compile it to javascript and then provide
it as a library to emscripten? Do you have a working RTS js version?
I want to simply try emscripten and see how it performs on such GHC
generater LLVM IRs.
2013/7/2 Luite Stegeman
On Tue, Jul 2, 2013 at 4:38 PM, B B
wrote: Thank you for all the replies. Luite Stegeman - I was thinking that the LLVM IR code is optimized already or you can run LLVM IR optimization passes to get rid of such things. I think compiling with ghc -fllvm generates LLVM bitcode and then you can simply run emscripten on it to get Javascript - and it should work as expected.
Most of the optimizations that GHC does are on Core, so you also get those if you use Core or STG as the source. You do miss out on the later optimization passes (GHC optimizes Cmm with Hoopl, and LLVM optimizes again). We implement this in GHCJS ourselves, optimizing the generated JavaScript.
Since GHC itself is written in Haskell, it would be a good goal to compile simple Haskell programs first and make sure that the RTS is working (you'll need to compile the Cmm and C RTS files to LLVM). You can try to get the GHC Testsuite [1] running. The GHCJS testsuite [2] might also be useful, it contains much of the GHC Testsuite and a runner program that checks the JavaScript results against native Haskell.
Like i said in the previous post, the generated code is a bit weird: stacks are allocated dynamically, functions never return, there are only tail calls. Emscripten might have a hard time with this.
[1] https://github.com/ghc/testsuite [2] https://github.com/ghcjs/ghcjs/tree/master/test