Compiling C to WebAssembly Without Emscripten
The compiler in Emscripten’s toolchain, the program that translates C code to WebAssembly byte-code, is LLVM. The next step is invoking LLVMs backend compiler to turn the LLVM IR into an object file:
The output, , is effectively a valid WebAssembly module and contains all the compiled code of our C file. If the program requests n bytes of memory, we advance that marker by n and return the previous value:
The globals we saw in the WAT are actually defined by which means we can access them from our C code as normal variables if we declare them as .