• Stars
    star
    704
  • Rank 64,316 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Translates WebAssembly modules to portable C

w2c2

Translates WebAssembly modules to portable 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, as well as
  • Passes 99.9% of the WebAssembly core semantics test suite
  • Written in C89 and generates C89
  • Support for many operating systems (e.g. Mac OS X, Mac OS 9, Haiku, Rhapsody, OPENSTEP, NeXTSTEP, DOS, Windows XP, etc.)
  • Support for many architectures (e.g. x86, ARM, PowerPC, SPARC, PA-RISC, etc.)
  • Support for big-endian systems (e.g. PowerPC, SPARC, PA-RISC, etc.)
  • Streaming/single-pass compilation, low memory usage
  • Separate compilation into multiple files
  • Parallel compilation
  • Support for multiple modules and instances
  • Support for generating debug information:
  • 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".

Installing libdwarf (required for source line mapping)

  • On Linux, try installing a package named like libdwarf-dev

  • On macOS, you can use Homebrew and install libdwarf (not dwarf!)

  • w2c2 currently defaults to using the libdwarf API of >=v0.4.2. v0.6.0 has been tested to work successfully too.

  • If using a version <0.4.2, try passing -DDWARF_OLD=1 to CMake. Version 20200114 is known to work.

  • Since version 0.1.1, libdwarf ships with a pkg-config file, which CMake should be able to detect automatically.

    If libdwarf cannot be automatically found by CMake, you get the following message:

    -- Checking for module 'libdwarf'
    --   No package 'libdwarf' found
    

    In that case you can still provide the necessary information manually by passing a variation of the following options:

    -DDWARF_FOUND=1 -DDWARF_LIBRARIES=-ldwarf -DDWARF_LIBRARY_DIRS=/usr/lib -DDWARF_INCLUDE_DIRS=/usr/include/libdwarf
    

More Repositories

1

ralph

Ralph is a Lisp-1 dialect that compiles to JavaScript
JavaScript
73
star
2

collection-view

UICollectionView for the web
TypeScript
66
star
3

g0m8

UI for M8 Headless Firmware
Go
34
star
4

SwiftDiff

Diff text in Swift
Swift
19
star
5

Binaryen

Binaryen for Swift
Swift
14
star
6

lila

Lila is a dynamic language running on the JVM with efficient multiple and predicate method dispatch
Java
13
star
7

NewtonKit

An implementation of the Apple Newton Dock protocol in Swift
Swift
13
star
8

ReteEngine

A Rete-based rule engine
Swift
8
star
9

TigerSwift

Swift for Mac OS X Tiger, via w2c2
Objective-C
7
star
10

spacy-thrift

spaCy as a service using Thrift
Python
6
star
11

duckling-docker

Duckling as a Docker container
Dockerfile
5
star
12

deployd

Update Kubernetes deployments and Docker Swarm services using webhooks
Go
5
star
13

JavaRegex

An implementation of Rob Pike's Virtual Machine-based regular expression engine
Java
5
star
14

SpaCyKit

Industrial-strength Natural Language Processing (NLP) with Swift
Swift
5
star
15

postgrest-small

A small PostgREST Docker image
Dockerfile
4
star
16

Trampoline

Trampolining in Swift
Swift
4
star
17

BridgeSupportParser

A Swift library for parsing bridgesupport files
Swift
3
star
18

sicl

Simple SPARQL library written in Common Lisp
HTML
3
star
19

ParserCombinators

A parser-combinator library for Swift
Swift
3
star
20

CDuckling

C bindings for Duckling
Haskell
3
star
21

spacy-grpc

spaCy part-of-speech tagging and named entity recognition as a gRPC service
Python
2
star
22

SpacyClient

A Swift client for spaCy
Swift
2
star
23

wikidata-ontology

Scala
2
star
24

CWriter

A Swift library for generating C code
Swift
2
star
25

serd-sys

Rust bindings to Serd, a lightweight RDF syntax library
Rust
2
star
26

lemmatizer

A lemmatizer based on WordNet's morphological processing
Java
1
star
27

telescope

Go explore
Scala
1
star
28

blazegraph-wikidata

Shell
1
star
29

OrderedSet

A mutable random access collection of unique elements, which behaves like a set, but guarantees insertion order
Swift
1
star
30

aptagger

An implementation of Matthew Honnibal's fast and accurate part-of-speech tagger based on the Averaged Perceptron
Java
1
star
31

number-parser

Java
1
star
32

CassowarySwift

Cassowary for Swift using cassowary.js
JavaScript
1
star
33

question-compiler

Scala
1
star
34

spacy-thrift-docker

spacy-thrift as a Docker container
Dockerfile
1
star
35

spacy-thrift-scala

Use spacy-thrift in Scala
Scala
1
star
36

wikidata-dump-filter

Filter a Wikidata RDF Dump
Java
1
star
37

ralph-ilc2012

Paper and slides for the ILC 2012 submission about Ralph
1
star