binaryen

Haskell bindings to binaryen. Provides complete bindings to the C API, which can be useful for building WebAssembly toolchains in Haskell.


Keywords
compiler, library, Propose Tags , Binaryen, Binaryen.Event, Binaryen.Export, Binaryen.Expression, Binaryen.ExpressionId, Binaryen.ExternalKind, Binaryen.Features, Binaryen.Function, Binaryen.Global, Binaryen.Index, Binaryen.Module, Binaryen.Op, Binaryen.Relooper, Binaryen.SideEffects, Binaryen.Type, Binaryen C API, nix, asterius, haskell, webassembly, ghc
License
BSD-3-Clause
Install
cabal install binaryen

Documentation

asterius

CircleCI

A Haskell to WebAssembly compiler. Work in progress.

What's already present:

  • A framework which hijacks normal ghc pipeline and retrieves in-memory representation of raw Cmm.
  • A test suite for booting which compiles ghc-prim, integer-simple and base.
  • Complete raw Haskell bindings of binaryen.
  • A serializable IR, roughly mapping to binaryen IR.

What comes next:

  • A code generator/linker which collects relevant Cmm blocks at link-time and uses the binaryen relooper to handle arbitrary jumps.
  • An RTS written from scratch in native WebAssembly. Will implement enough primops & libc stubs for an MVP(Minimum Viable Product).
  • A test suite for the generated WebAssembly code.

Building

Assumes x64 platform, only tested on Linux for now. Dependencies:

  • cmake/make/g++: For building in-tree binaryen
  • autoconf/sed: For booting ghc-prim/base
  • nodejs: For running tests
  • ghc-head built with TABLES_NEXT_TO_CODE disabled and integer library set to integer-simple. Get one via docker pull terrorjack/meikyu:ghc-head
  • stack. cabal users need to run hpack first to generate asterius.cabal, and add head.hackage to the project config.

Simply run stack build. Set MAKEFLAGS=-j8 to pass flags to make for parallel building of binaryen. Run stack test asterius:ahc-boot to test if booting works.

Windows users need to run it in an mingw-w64 Win64 shell. stack takes care of installing/launching it by default.

Differences from WebGHC

  • Doesn't depend on Emscripten/LLVM. There is no plan to port the C runtime and support C libraries, at least for now.