Will's blog

purpose: Will Kahn-Greene's blog of Miro, PyBlosxom, Python, GNU/Linux, random content, PyBlosxom, Miro, and other projects mixed in there ad hoc, half-baked, and with a twist of lemon

[ home | blog home | recent activity ]

Mon, 23 Apr 2007

Compiling the Tiger runtime for SPIM

I figured I'd post this because I just spent 24 hours trying to work out the issues.

I'm in a compilers class that's using the Modern Compiler Implementation in ML book (aka the Tiger book) by Andrew Appel. Over the course of the first 12 chapters, you build a compiler for a language called Tiger. Appel has a runtime.c that you can download from his web-site, but if you add functions to the runtime.c (for example, we added a ternary string comparison function which made string relops trivial to implement), then you need to compile runtime.c into assembler that's SPIM-appropriate.

Long story short I've got a Gateway 450 something or other laptop (i686) running Ubuntu Feisty Fawn and gcc version 4.1.2. I used the crosstool scripts from Dan Kegel. I used the demo-mips.sh script, but modified it to this:

#!/bin/sh
set -ex

# Big-endian MIPS

TARBALLS_DIR=$HOME/downloads
RESULT_TOP=$HOME/mipsgcc
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c"
export GCC_LANGUAGES

# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP

# Build the toolchain.  Takes a couple hours and a couple gigabytes.

eval `cat mips.dat gcc-3.4.5-glibc-2.3.5.dat`        sh all.sh --notest

echo Done.

Ubuntu has /bin/sh point to dash--but this causes problems when compiling glibc (see here). So I fixed /bin/sh to point to bash instead of dash. That fixes the "error: missing terminating " character" error.

After you get your cross-compiler working, you can compile your runtime.c into a runtime.s with something like this:

% mips-unknown-linux-gnu-gcc -S -mrnames -mmips-as runtime.c -o runtime.s.raw

After that, you have to remove a few things so that it works in SPIM. Olin Shivers has a page that talks about this some more.

Hopefully I included enough words in here that this pops up in Google and helps future compiler-class takers in the same position I was in.

Comments:

Post a new comment:

Three things:

  1. New comments get placed in a "draft" status and will NOT show up on the site until I explicitly approve it. Sometimes that happens within 24 hours.
  2. I reserve the right to reject/remove inappropriate comments.
  3. Sometimes I'll reply to a comment directly in email--so make sure your email address is correct.

If you can't for some reason post a comment, send me an email: willg at bluesock dot org.

Your name:


Your e-mail address (this doesn't get displayed to anyone--sometimes I'll reply directly to you):


URL of your website (optional):


Comment:


Yes, I am a human!


pyblosxom::1.5-dev git-master

Copyright 1996 to 2012, Will Guaraldi Kahn-Greene, under the Creative Commons BY-SA 3.0 license

Creative Commons License
Will's Blog by William Kahn-Greene is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.