#webassembly #wasm #compiler #binaryen

binaryen

Bindings to the binaryen library

6 releases (breaking)

0.6.0 Jan 4, 2019
0.5.0 Oct 19, 2018
0.4.0 Aug 16, 2018
0.3.0 Jan 19, 2018
0.1.0 Sep 3, 2017

#21 in #webassembly

Download history 29/week @ 2018-10-11 86/week @ 2018-10-18 26/week @ 2018-10-25 12/week @ 2018-11-01 51/week @ 2018-11-08 38/week @ 2018-11-15 20/week @ 2018-11-22 72/week @ 2018-11-29 13/week @ 2018-12-06 9/week @ 2018-12-13 3/week @ 2018-12-20 41/week @ 2018-12-27 9/week @ 2019-01-03

139 downloads per month
Used in 1 crate

Apache-2.0

4.5MB
35K SLoC

C++ 29K SLoC // 0.2% comments Python 2.5K SLoC // 0.1% comments JavaScript 1.5K SLoC // 0.0% comments Rust 1.5K SLoC // 0.2% comments Shell 604 SLoC // 0.1% comments

binaryen-rs

Build Status crates.io docs.rs

Binaryen bindings for Rust. These bindings wrap binaryen C API very closly and at times might be not very idiomatic. For example, binaryen can abort your program if used incorrectly.

With Binaryen you can create optimized WebAssembly modules.

For example what you can create with Binaryen you can check out DEMO*. Yes, this is CHIP-8 roms compiled straight to the WebAssembly. See emchipten test bed for this project.

(*) Modern browser required

Example

extern crate binaryen;

use binaryen::*;

fn main() {
    let module = Module::new();

    let params = &[ValueTy::I32, ValueTy::I32];
    let iii = module.add_fn_type(Some("iii"), params, Ty::I32);

    let x = module.get_local(0, ValueTy::I32);
    let y = module.get_local(1, ValueTy::I32);
    let add = module.binary(BinaryOp::AddI32, x, y);

    let _adder = module.add_fn("adder", &iii, &[], add);

    assert!(module.is_valid());

    module.print();
}

This example will print:

(module
 (type $iii (func (param i32 i32) (result i32)))
 (memory $0 0)
 (func $adder (type $iii) (param $0 i32) (param $1 i32) (result i32)
  (i32.add
   (get_local $0)
   (get_local $1)
  )
 )
)

Dependencies