Code Monkey home page Code Monkey logo

w2c2's Introduction

w2c2

Translates WebAssembly modules to C. Inspired by wabt's wasm2c.

Working towards WebAssembly as the Elusive Universal Binary:

                                          ↗ different
  source code     →  WebAssembly  →  C89  → OSes,
(C++, Rust, ...)                          ↘ CPUs

Features

  • Implements the WebAssembly Core Specification 1.0, and bulk memory operations
  • Passes 99.9% of the WebAssembly core semantics test suite
  • Written in C89 and generates C89
  • Support for older operating systems and architectures (e.g. Mac OS X on PowerPC, Haiku, Rhapsody, OPENSTEP, Windows XP, etc.)
  • Support for big-endian systems (e.g. PowerPC)
  • Streaming/single-pass compilation, low memory usage
  • Separate compilation into multiple files
  • Parallel compilation
  • Support for multiple modules and instances
  • WASI implementation which is able to run clang and Python

Performance

  • Coremark 1.0: ~7% slower than native

Compilation

If your system is supported by at least CMake 2.8.12, prefer using CMake to detect features. On systems without CMake you can also use Make.

w2c2

cd w2c2
cmake -B build
cmake --build build

wasi

cd wasi
cmake -B build
cmake --build build

Usage

For example, to compile module.wasm to module.c (and module.h):

./w2c2 module.wasm module.c

Separate Compilation

w2c2 is able to compile a module into separate C files. This is recommended when compiling large modules and on hosts with limited resources.

For example, to compile module.wasm (and module.h), into multiple files with 100 functions each:

./w2c2 -f 100 module.wasm module.c

Parallel Compilation

When w2c2 was built with threading support, it is able to compile a module in parallel. By default, w2c2 spawns as many worker threads as CPU cores are available.

To manually specify the number of worker threads, pass the number using the -t flag.

For example, to compile using 2 threads:

./w2c2 -t 2 module.wasm module.c

Examples

Coremark:

cd examples/coremark
make
./coremark

Testing

Requires Python 3 and wabt (for wast2json).

cd tests
make gen
make run-tests

WASI Status

  • args_get
  • args_sizes_get
  • clock_res_get
  • clock_time_get
  • environ_get
  • environ_sizes_get
  • fd_advise
  • fd_allocate
  • fd_close
  • fd_datasync
  • fd_fdstat_get
  • fd_fdstat_set_flags
  • fd_fdstat_set_rights
  • fd_filestat_get
  • fd_filestat_set_size
  • fd_filestat_set_times
  • fd_pread
  • fd_prestat_get
  • fd_prestat_dir_name
  • fd_pwrite
  • fd_read
  • fd_readdir
  • fd_renumber
  • fd_seek
  • fd_sync
  • fd_tell
  • fd_write
  • path_create_directory
  • path_filestat_get
  • path_filestat_set_times
  • path_link
  • path_open
  • path_readlink
  • path_remove_directory
  • path_rename
  • path_symlink
  • path_unlink_file
  • poll_oneoff
  • proc_exit
  • random_get
  • sched_yield
  • sock_recv
  • sock_send
  • sock_shutdown

Development

To build a debug release, pass BUILD=debug to make.

To enable sanitizers, list them in the SANITIZERS variable passed to make, e.g. make BUILD=debug SANITIZERS="base clang address thread".

w2c2's People

Contributors

turbolent avatar samuraicrow avatar vshymanskyy avatar asiekierka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.