NOTE: the content is out-of-date. All development is moved to the https://github.com/yurydelendik/wasmception
# locations, e.g.
export WORKDIR=~/llvmwasm; mkdir -p $WORKDIR
export INSTALLDIR=$WORKDIR
# checkout LLVM
cd $WORKDIR
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
# checkout clang
cd $WORKDIR/llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
# checkout lld
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
# build folder (~14 min; ~1 hour /wo -j)
mkdir $WORKDIR/llvm-build
cd $WORKDIR/llvm-build
# For Debug build:
# cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$INSTALLDIR -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Debug $WORKDIR/llvm
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$INSTALLDIR -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly $WORKDIR/llvm
make -j 8
# install llvm
make install
Let's create "fib.c" and compile it, first to LLVM bitcode, then to WebAssembly-like file. (Notice -O2 or above near clang to avoid failure during llc
run.)
$INSTALLDIR/bin/clang -emit-llvm --target=wasm32 -Oz fib.c -c -o fib.bc
$INSTALLDIR/bin/llc -asm-verbose=false -o fib.s fib.bc
See output at fib.s.
Convert to WebAssebly s-expressions (needs binaryen s2wasm tool):
$BINARYENDIR/bin/s2wasm fib.s > fib.wast
See output at fib.wast.