- A modern C++ toolchain (>=
g++-4.8
or 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-essential
package 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
m4
and 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-get
package name islibffi-dev
. Sorry but I don't know its OSX equivalence... - Install
g++-multilib
, if you are usinggcc
to build LLVM - Install
cmake
, which is used to configure the build system
- Install the
-
Clone this repository and checkout the
llvm
submodule:$ git clone git@github.com: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=ON
as 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.txt
and add-lmpfr -lgmp
to the end of that file, and runmake
(in thebuild
directory!) again. -
After it successfully builds, the executable we care about is located at
build/bin/lli
.
-
Make sure that you have
clang
orclang++
installed because we didn't actually buildclang
when 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
-c
flag;-emit-llvm
doesn't work without it. - Supply the
-g
flag if you want extra debugging information (e.g. line number) - Supply the
-fno-use-cxa-atexit
flag if you encounter a__dso_handle
related error in the next step.
- Be sure to supply the
-
To run the byte code with
lli
, use the.bc
file. DO NOT forget to invokelli
with the-force-interpreter
flag:# make sure you are using the correct lli executable... $ ./lli -force-interpreter program.bc