{"id":13470340,"url":"https://github.com/turbolent/w2c2","last_synced_at":"2025-05-16T19:07:27.174Z","repository":{"id":43749861,"uuid":"398904359","full_name":"turbolent/w2c2","owner":"turbolent","description":"Translates WebAssembly modules to portable C","archived":false,"fork":false,"pushed_at":"2025-04-02T14:32:14.000Z","size":47351,"stargazers_count":749,"open_issues_count":9,"forks_count":43,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-14T13:58:27.836Z","etag":null,"topics":["c","c89","compiler","wasi","wasm","wasm2c","webassembly"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/turbolent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-22T21:25:04.000Z","updated_at":"2025-04-13T22:58:38.000Z","dependencies_parsed_at":"2023-02-12T19:01:06.594Z","dependency_job_id":"81177145-0091-4563-a6f3-f324449d982e","html_url":"https://github.com/turbolent/w2c2","commit_stats":{"total_commits":495,"total_committers":10,"mean_commits":49.5,"dds":0.07272727272727275,"last_synced_commit":"d94227c22f8d78a04fbad70fa744481ca4a1912e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbolent%2Fw2c2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbolent%2Fw2c2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbolent%2Fw2c2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbolent%2Fw2c2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/turbolent","download_url":"https://codeload.github.com/turbolent/w2c2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254592395,"owners_count":22097013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c89","compiler","wasi","wasm","wasm2c","webassembly"],"created_at":"2024-07-31T16:00:28.717Z","updated_at":"2025-05-16T19:07:27.153Z","avatar_url":"https://github.com/turbolent.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg height=\"460\" src=\"w2c2.svg\"\u003e\n\u003c/p\u003e\n\n# w2c2\n\nTranslates WebAssembly modules to portable C.\nInspired by [wabt's wasm2c](https://github.com/WebAssembly/wabt/tree/main/wasm2c).\n\nWorking towards [WebAssembly as the Elusive Universal Binary](https://kripken.github.io/talks/2020/universal.html#/):\n\n```\n                                          ↗ different\n  source code     →  WebAssembly  →  C89  → OSes,\n(C++, Rust, ...)                          ↘ CPUs\n```\n\n\n## Features\n\n- Implements the [WebAssembly Core Specification 1.0](https://www.w3.org/TR/wasm-core-1/)\n- Implements several extensions:\n  - [Threads and atomics](https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md)\n  - [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md)\n  - [Conditional data segment initialization](https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md)\n  - [Sign-extension operators](https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md)\n  - [Non-trapping float-to-int conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md)\n- Passes 99.9% of the WebAssembly core semantics test suite\n- Written in (mostly) C89 and generates (mostly) C89 (some common extensions are used and not all limits are followed, see e.g. #98)\n- Support for many operating systems (e.g. Mac OS X, Mac OS 9, Haiku, Rhapsody, OPENSTEP, NeXTSTEP, DOS, Windows XP, etc.)\n- Support for many architectures (e.g. x86, ARM, PowerPC, SPARC, PA-RISC, etc.)\n- Support for big-endian systems (e.g. PowerPC, SPARC, PA-RISC, etc.)\n- Support for various compilers (e.g. old GCC, MSVC, CodeWarrior, etc.) \n- Streaming/single-pass compilation, low memory usage\n- Separate compilation into multiple files\n- Parallel compilation\n- Assist with incremental compilation: Separate static and dynamic functions by comparing with another module\n- Support for multiple modules and instances\n- Support for generating debug information:\n  - Function names, if function names are provided in the [`names` custom section](https://webassembly.github.io/spec/core/appendix/custom.html#function-names)\n  - Source line mapping, if DWARF line information is provided in the [`.debug_line` custom section](https://yurydelendik.github.io/webassembly-dwarf/).\n    Requires [libdwarf](https://github.com/davea42/libdwarf-code) to be installed. See instructions below.\n- WASI implementation\n  - Able to run clang and Python\n  - Support for many operating systems and architectures, support for big-endian systems\n  - Implements the [threads proposal](https://github.com/webAssembly/wasi-threads)\n\n## Performance\n\n- Coremark 1.0: ~7% slower than native\n\n## Compilation\n\nIf your system is supported by at least CMake 2.8.12, prefer using CMake to detect features.\nOn systems without CMake you can also use Make.\n\n### w2c2\n\n```sh\ncd w2c2\ncmake -B build\ncmake --build build\n```\n\n### wasi\n\n```sh\ncd wasi\ncmake -B build\ncmake --build build\n```\n\n## Usage\n\nFor example, to compile `module.wasm` to `module.c` (and `module.h`):\n\n```sh\n./w2c2 module.wasm module.c\n```\n\n### Separate Compilation\n\nw2c2 is able to compile a module into separate C files.\nThis is recommended when compiling large modules and on hosts with limited resources.\n\nFor example, to compile `module.wasm` (and `module.h`), into multiple files with 100 functions each:\n\n```sh\n./w2c2 -f 100 module.wasm module.c\n```\n\n### Parallel Compilation\n\nWhen w2c2 was built with threading support, it is able to compile a module in parallel.\nBy default, w2c2 spawns as many worker threads as CPU cores are available.\n\nTo manually specify the number of worker threads, pass the number using the `-t` flag.\n\nFor example, to compile using 2 threads:\n\n```sh\n./w2c2 -t 2 module.wasm module.c\n```\n\n## Examples\n\nCoremark:\n\n```sh\ncd examples/coremark\nmake\n./coremark\n```\n\n## Testing\n\nRequires Python 3 and [wabt](https://github.com/WebAssembly/wabt) (for `wast2json`).\n\n```sh\ncd tests\nmake gen\nmake run-tests\n```\n\n## WASI Status\n\n- [x] `args_get`\n- [x] `args_sizes_get`\n- [x] `clock_res_get`\n- [x] `clock_time_get`\n- [x] `environ_get`\n- [x] `environ_sizes_get`\n- [ ] `fd_advise`\n- [ ] `fd_allocate`\n- [x] `fd_close`\n- [x] `fd_datasync`\n- [x] `fd_fdstat_get`\n- [ ] `fd_fdstat_set_flags`\n- [ ] `fd_fdstat_set_rights`\n- [x] `fd_filestat_get`\n- [ ] `fd_filestat_set_size`\n- [ ] `fd_filestat_set_times`\n- [x] `fd_pread`\n- [x] `fd_prestat_get`\n- [x] `fd_prestat_dir_name`\n- [x] `fd_pwrite`\n- [x] `fd_read`\n- [x] `fd_readdir`\n- [ ] `fd_renumber`\n- [x] `fd_seek`\n- [x] `fd_sync`\n- [x] `fd_tell`\n- [x] `fd_write`\n- [x] `path_create_directory`\n- [x] `path_filestat_get`\n- [ ] `path_filestat_set_times`\n- [ ] `path_link`\n- [x] `path_open`\n- [x] `path_readlink`\n- [x] `path_remove_directory`\n- [x] `path_rename`\n- [x] `path_symlink`\n- [x] `path_unlink_file`\n- [ ] `poll_oneoff`\n- [x] `proc_exit`\n- [x] `random_get`\n- [ ] `sched_yield`\n- [ ] `sock_recv`\n- [ ] `sock_send`\n- [ ] `sock_shutdown`\n- [x] `thread-spawn` (from the [threads proposal](https://github.com/webAssembly/wasi-threads))\n\n## Development\n\nTo build a debug release, pass `BUILD=debug` to `make`.\n\nTo enable sanitizers, list them in the `SANITIZERS` variable passed to `make`, e.g. `make BUILD=debug SANITIZERS=\"base clang address thread\"`.\n- `base` enables the [Undefined Behavior Sanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html)\n- `clang` enables Clang-specific sanitizers\n- `thread` enables the [Thread Sanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html)\n- `address` enables the [Address Sanitizer](https://clang.llvm.org/docs/AddressSanitizer.html)\n\n## Installing libdwarf (required for source line mapping)\n\n- On Linux, try installing a package named like `libdwarf-dev`\n- On macOS, you can use [Homebrew](https://brew.sh/) and install `libdwarf` (not `dwarf`!)\n- w2c2 currently defaults to using the libdwarf API of \u003e=v0.4.2. v0.6.0 has been tested to work successfully too.\n- If using a version \u003c0.4.2, try passing `-DDWARF_OLD=1` to CMake. Version 20200114 is known to work.\n- Since version 0.1.1, libdwarf ships with a pkg-config file, which CMake should be able to detect automatically.\n\n  If libdwarf cannot be automatically found by CMake, you get the following message:\n\n  ```\n  -- Checking for module 'libdwarf'\n  --   No package 'libdwarf' found\n  ```\n\n  In that case you can still provide the necessary information manually by passing a variation of the following options:\n\n  ```\n  -DDWARF_FOUND=1 -DDWARF_LIBRARIES=-ldwarf -DDWARF_LIBRARY_DIRS=/usr/lib -DDWARF_INCLUDE_DIRS=/usr/include/libdwarf\n  ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbolent%2Fw2c2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturbolent%2Fw2c2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbolent%2Fw2c2/lists"}