- A modern C++ toolchain (>=
g++-4.8or a recent version ofclang) - MPFR library (and also GMP, but it should install automatically if you get it through some sort of package manager)
- List of dependencies described in the LLVM Getting Started page. A few comments...
- Install the
build-essentialpackage if using Ubuntu Linux: that should install most of the required packages - If you're building on Mac, make sure to install all packages required by LLVM, including something called
m4and a bunch of compression libraries - Be sure to install
libffi, or library calls such asprintf()won't work. On Ubuntu Linux systems it should come with the box. If not, theapt-getpackage name islibffi-dev. Sorry but I don't know its OSX equivalence... - Install
g++-multilib, if you are usinggccto build LLVM - Install
cmake, which is used to configure the build system
- Install the
-
Clone this repository and checkout the
llvmsubmodule:$ git clone [email protected]:danking/real-semantics.git $ cd real-semantics $ git submodule init && git submodule update $ cd llvm-3.6.0
-
If you would like to get the latest LLVM code (which could be broken), switch to master branch and do a pull. You can skip this step if you just want to try it out.
$ git checkout master $ git pull
-
Now we can start building LLVM:
$ mkdir build $ cd build build$ cmake .. -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_FFI=ON build$ make -j2 # or whatever number of processors you have
During the third (
cmake) step, you can pass-DCMAKE_BUILD_TYPE=DEBUG -DLLVM_ENABLE_ASSERTIONS=ONas additional arguments if you wish to do a debug build. -
Keep your fingers crossed and hope that it will build without error... Actually it will probably fail at a final linking step because I haven't figured out the Makefile yet. If that happens, go to
build/tools/lli/CMakeFiles/lli.dir/link.txtand add-lmpfr -lgmpto the end of that file, and runmake(in thebuilddirectory!) again. -
After it successfully builds, the executable we care about is located at
build/bin/lli.
-
Make sure that you have
clangorclang++installed because we didn't actually buildclangwhen we built LLVM. -
Generating byte code is easy:
# this will generate the actual "byte" code $ clang -emit-llvm -c program.c -o program.bc # this will generate a human readable LLVM IR program $ clang -S -emit-llvm -c program.c -o program.ll
For complete debugging information, use the clang-3.6 executable:
$ ./clang-3.6 -I/usr/include/clang/3.4/include -emit-llvm -c -g program.c -o program.bc
Notes:
- Be sure to supply the
-cflag;-emit-llvmdoesn't work without it. - Supply the
-gflag if you want extra debugging information (e.g. line number) - Supply the
-fno-use-cxa-atexitflag if you encounter a__dso_handlerelated error in the next step.
- Be sure to supply the
-
To run the byte code with
lli, use the.bcfile. DO NOT forget to invokelliwith the-force-interpreterflag:# make sure you are using the correct lli executable... $ ./lli -force-interpreter program.bc