[Haskell-cafe] ghci & ghc -> JS (Emscripten)

Luite Stegeman stegeman at gmail.com
Tue Jul 2 17:25:04 CEST 2013

On Tue, Jul 2, 2013 at 4:38 PM, B B <blackbox.dev.ml at gmail.com> 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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130702/1e60b1d2/attachment.htm>

More information about the Haskell-Cafe mailing list