Using WebAssembly in LLVM on Windows
This example demonstrates how to compile C code to WebAssembly on Windows using LLVM's experimental WebAssembly backend, and visualizes the intermediate and final artifacts generated at each stage of the toolchain. The source code defines a Fibonacci function in C, and the visualization walks through the transformation pipeline: C source (fib.c) → LLVM bitcode (fib.bc) → LLVM assembly (fib.s) → WebAssembly text format (fib.wast) → WebAssembly binary (fib.wasm). A hex dump of the resulting .wasm file shows the compiled binary, including the memory table and the fib function export. The gist includes commands for setting up the required tools—Git, Subversion, CMake, and Visual Studio—to build the necessary LLVM/Clang, Binaryen, and Wabt toolchain on Windows, along with a compile.bat script that automates the build steps.