llvm setup

Today I’m playing with llvm.

Goal: get kaleidoscope tutorial setup in “proper place”.

Time: end of the day

  1. Download llvm
  2. Sample project


The Getting Started with LLVM page has the git location and straightforward instructions for building it. I already had XCode and the XCode command line tools installed giving me Apple LLVM 4.2 which equates to llvm 3.2 (of course).


Once I got to the kaleidoscope tutorial, I discovered what should have been an obvious problem. The git repo is trunk, and only trunk, and it is quite different from 3.2. Specifically, many header files have moved, which seems an odd thing to do for a point release. So once I built the sample app and then copied the kaleidoscope source into it, it wouldn’t compile because headers were wrong. Which seems odd. So, for the Install, use svn and grab the 3.2 branch.

Why do that at all? I like source code to look at. Its how I learn quickest. I can reverse engineer binary files but it takes longer.


Next I’m going to set up a new project. The kaleidoscope documentation doesn’t actually tell me how to do this, or even advise one way or the other if I should. At the bottom of the getting started doc is a link to the Creating an LLVM Project documentation. I’ll do that then.

I made a new folder by copying the sample folder there and renaming it. The I set about building the thing.

First rule: follow the instructions precisely.

In Step 5:

% cd autoconf
% ./AutoRegen.sh

This last one is going to asked me for the path of the llvm source and llvm object files I build during installation. I was thinking that if I set the LLVM_SRC_ROOT var in configure.ac it would figure this out, but it didn’t work. I looked at the source of AutoRegen.sh to see if I was doing something daft, and realized, no, its just going to ask me no matter what.

When it comes to the “run the configure” step (6), it follows the same pattern as for llvm itself in the GSwL:

% cd ~/experiments/kaleidotest.build
% ../kaleidotest/configure --with-llvmsrc=<src> --with-llvmobj=<obj> --prefix=/some/absolute/path

Since step 5 was in the context of the autoconf directory, and that directory has a configure script, I thought it meant that one. It doesn’t. When it says “Run configure”, it means “the other configure, the one in the project’s root”.

% ~/experiments/kaleidotest.build/Release+Assert/bin/Sample


Next: kaleidoscope