binaryen.cr

Crystal binding for binaryen, WIP

Binaryen.cr

A Crystal binding of Binaryen.

WARNING : lack enough test currently.

However most of bug could be fix quickly. And depending on the huge workload for testing code, I decide to develop my next project using this library (which is a Crystal -> WASM compiler), and test them together. Completely testing will be finished after several weeks I believe. Pull request for testing or bug fix is really appreciated.

Installation

Add this to your application's shard.yml:

dependencies:
  binaryen:
    github: xqyww123/binaryen.cr

Usage

require "binaryen"

mod = Binaryen::Module.new
ft = mod.add_function_type "name_of_function_type", Binaryen::Int32, [Binaryen::Int32]
# add_function_type name, result_type, params_type
f  = mod.add_function "name_of_function", ft, [Binaryen::Int64], mod.exp_return(mod.exp_get_local 0, Binaryen::Int32)
# add_function name, function_type, locals type, expression
mod.start_point = f
code = mod.compile # => Binaryen::Module::Codes
File.write "result", code.data # => Bytes

Basically warpped from Binaryen C-API by Crystal classes, with some OOP conception such as class Module and struct Function etc.

With enough WASM knowledge, src/binaryen.cr is clear enough without any comment.

Get more information from Binaryen C-API (binaryen-c.h) and WASM design.

Find more example in spec.

Contributors

  • [xqyww123] Shirotsu Essential - creator, maintainer
Repository

binaryen.cr

Owner
Statistic
  • 1
  • 0
  • 0
  • 0
  • 0
  • almost 5 years ago
  • May 17, 2018
License

MIT License

Links
Synced at

Mon, 18 Nov 2024 08:16:42 GMT

Languages