LLVM For The 1802 – Fumbling first Steps
The C compiler I built for the olduino LCC1802 is serviceable and easy to work on. It has limitations though and the code is a long way from optimized. I’ve had the idea for a while that I would look at using the LLVM compiler infrastructure to try to go it one better. LLVM can generate extremely good code and I think I can even handle C++ syntax which would be funny.
I’m going to use an aged macbook that i inherited from my daughter. This is partly to audition the mac as an alternative for my next laptop and partly because the mac has easily available a lot of the things I need (xcode, svn). The macbook is by far the nicest piece of hardware I’ve used and os x has a learning curve but i’m disposed to like it.
So far I’ve installed xcode from the mac app store – That was dead easy. xcode is the mac ide for c and c++. It actually uses parts of the llvm c/c++ compiler suite but, the llvm i build will be done with GCC 4.2. This is a problem because the current llvm version(3.5) wants gcc 4.7 so i’m going to work on llvm version 3.0 from a few years ago. If I get a new mac for christmas i’ll move to the current source version.
I’ve downloaded the llvm 3.0 source and corresponding clang from here. The llvm source tree is in folder ~\llvm\release\src and the clang source in a subfolder ~\llvm\release\src\tools\clang. The llvm source came down in a .tar as llvm-3.0.src(renamed to src) and clang as clang-3.0.src(renamed to clang). I’m just trying to stick to something analogous to the tutorial because the mac directory structure confuses me.
I’ve downloaded cmake from here. cmake takes the make files shipped with llvm/clang and makes a project definition file that the xcode ide can read. This led to some hilarity because installing non app-store programs on a mac seems a bit odd to a windows user.
For cmake it was a matter of telling it where the source was:~\llvm\release\src and where the binaries were to go:~\llvm\release\cmake_release_build. Running cmake was a bit confusing and I had to set a couple of options as per the tutorial** and ignore some llvm version related stuff but cmake did its thing and generated an LLVM.xcodeproj file in the binaries directory which xcode was happy to open. ** specifically, as per his figure 7 and related comments setting checkmarks beside CLANG_BUILD_EXAMPLES, LLVM_BUILD_EXAMPLES, and unchecking LLVM_ENABLE_PIC.
xcode happily opened the xcodeproj file. Then it was a matter of selecting “build” from the xcode build menu and waiting a long long time. There seemed to be 202 targets to be built each of which had dozens of files to be compiled and linked. I didn’t time it but it was at least 3 hours. Prior to this I had not thought the macbook was showing its age too much but…
Anyway, I now have a version of clang and llvm built on the mac and I’m ready for the next step. The clang and llvm binaries ended up in ~\llvm\release\cmake_release_build\bin\debug.