wasm2c
Compile WebAssembly modules to C source code
TLDR
Convert a file to a C source file and header and display it to the console
Write the output to a given file (file.h gets additionally generated)
SYNOPSIS
wasm2c [options]
PARAMETERS
-h|--help
Display available options.
-o
Specify the output C file name.
--mvp
Only emit code that uses MVP features, even when the input file uses proposals.
--validate
Validate the wasm module before translating.
--memory-base=
Set the memory base address.
--table-base=
Set the table base address.
--debug-names
Use debug names from the wasm module in the generated C code.
DESCRIPTION
wasm2c is a command-line tool that translates WebAssembly (WASM) bytecode into equivalent C source code. This allows you to compile and run WASM modules on platforms where a WASM runtime might not be readily available. The generated C code can be compiled using a standard C compiler (like GCC or Clang), making WASM modules portable to a wider range of architectures. The output C code aims to be readable and understandable, offering insight into the WASM module's logic. This tool is part of the WebAssembly Binary Toolkit (WABT), a suite of tools for working with WASM files.
CAVEATS
The generated C code might not be as performant as native WASM execution.
Complex WASM modules can result in large and intricate C code.
USAGE EXAMPLE
To convert a WASM file named 'module.wasm' to a C file named 'module.c', you would use the command: wasm2c module.wasm -o module.c
You can then compile 'module.c' using a C compiler like GCC: gcc module.c -o module
HISTORY
wasm2c is part of the WABT (WebAssembly Binary Toolkit) project, which was created to provide developers with tools for working with WebAssembly files. It emerged alongside the development and standardization of the WebAssembly specification, aimed at enabling more portable and efficient web applications and beyond.
SEE ALSO
wasm-validate(1), wasm-objdump(1)