首页 > 代码库 > Coursera compiler Set up environment and Run first program
Coursera compiler Set up environment and Run first program
Environment, Ubuntu 14.04
set up guide
Set up cool compiler
1. sudo apt-get install flex bison build-essential csh openjdk-6-jdk libxaw7-dev libc6-i386
2. Make the /usr/class directory
sudo mkdir /usr/class
3. Make the directory owned by you
sudo chown $USER /usr/class
4. Go to /usr/class and download the tarball
cd /usr/class
wget http://spark-university.s3.amazonaws.com/stanford-compilers/vm/student-dist.tar.gz
5. Untar
tar -xf student-dist.tar.gz
6. If you want things exactly like the VMs:
Add a symlink to your home directory
ln -s /usr/class/cs143/cool ~/cool
7. Add the bin directory to your $PATH environment variable. If you are using bash, add to your .profile (or .bash_profile, .bashrc etc. depending on your configuration; note that in Ubuntu have to log out and back in for this to take effect):
vim ~/.bashrc and append
PATH=/usr/class/cs143/cool/bin:$PATH
8. you may also need to do this
sudo apt-get install xfonts-75dpi xfonts-100dpi
xset +fp /usr/share/fonts/X11/75dpi
Run first program
$ mkdir examples
$ cd examples
$ cp /usr/class/cs143/examples/hello_world.cl .
$ coolc hello_world.cl
$ spim hello_world.s
SPIM Version 6.5 of January 4, 2003
Copyright 1990-2003 by James R. Larus (larus@cs.wisc.edu).
All Rights Reserved.
See the file README for a full copyright notice.
Loaded: /usr/class/cs143/cool/lib/trap.handler
Hello, World.
COOL program successfully executed
Stats -- #instructions : 152
#reads : 27 #writes 22 #branches 28 #other 75