package binaryen

  1. Overview
  2. Docs
OCaml bindings for Binaryen

Install

Dune Dependency

Authors

Maintainers

Sources

binaryen-archive-v0.2.3.tar.gz
md5=f4cb5ad491901b6252cc8adcec7cfd8a
sha512=ebceb1b39a1dc69870b6b5d4d0364df609c0743c9f4af2b9d37fb46a255e3417ff34ccc0f8eac1f1d0b10f42f10f47987bd208f887b1a2bd89153aef42eb0a76

Description

Published: 22 Jul 2020

README

Binaryen.ml

OCaml bindings for Binaryen.

Binaryen is a compiler and toolchain infrastructure for WebAssembly. It makes compilation to WebAssembly pretty darn easy.

Here's Binaryen's hello world test in OCaml form:

open Binaryen

let wasm_mod = Module.create ()

(* Create function type for i32 (i32, i32) *)
let params = Type.create [| Type.int32; Type.int32 |]
let results = Type.int32

(* Get arguments 0 and 1, add them *)
let x = Expression.local_get wasm_mod 0 Type.int32
let y = Expression.local_get wasm_mod 1 Type.int32
let add = Expression.binary wasm_mod Op.add_int32 x y

(* Create the add function *)
(* Note: no additional local variables *)
let adder = Function.add_function wasm_mod "adder" params results [||] add

let _ = Module.print wasm_mod
let _ = Module.dispose wasm_mod

Feature Parity

This project aims to provide full feature parity with the Binaryen C API. It's fairly complete, but a few things still need bindings:

  • SIMD instructions

  • Events

  • Atomics

  • Query operations on expressions

  • Query operations on functions

None of these are particularly challenging to create bindings for—they just haven't been written yet. If you need anything that's missing, feel free to open a PR.

Contributing

After cloning the repository, be sure to initialize the Binaryen submodule:

git submodule update --init

You'll need Node.js and yarn to build this project, as well as cmake to build Binaryen.

dune will take care of building Binaryen and compiling the C stubs, so to build the project you'll only need to run:

yarn
yarn build

This will take a while. Once it's done, you can run the tests:

yarn test

Dependencies (4)

  1. conf-python-3 build
  2. conf-cmake build
  3. dune >= "2.6"
  4. ocaml >= "4.08"

Dev Dependencies

None

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.