WLLVM

A tool for compiling C/C++ to LLVM bitcode. See also GLLVM.

Example

nix-shell --pure -p clang_6 -p wllvm --run "wllvm -c test.cpp && extract-bc test.o"
nix-shell test.nix --pure --run "wllvm++ -o test -static -g -O1 test.cpp"
nix-shell test.nix --pure --run "extract-bc test"
nix-shell test.nix --pure --run "llvm-dis test.bc > test.ll"

where

with import <nixpkgs> { };

llvmPackages.stdenv.mkDerivation {
  name = "test";
  buildInputs = [
    file
    wllvm
    clang_6
    llvm_6
    llvmPackages_6.compiler-rt
    glibc.static
  ];
  src = lib.sourceFilesBySuffices ./. [ ".cpp" ];
  LLVM_COMPILER = "clang";
}

Linking

wllvm will bring in the definitions from your project. However, if you're including stuff from other libraries, that will have to be linked manually. Confusingly, wllvm will bring in anything in the header files, and with C++ templates, this can be a surprisingly large amount of what gets included from libraries (especially libstdc++).

Error Messages

wllvm requires the file utility.

WARNING:wllvm: exception case: [Errno 2] No such file or directory: 'file': 'file'