LCC C Compiler

Quick links: installation, usage example

lcc is a retargetable C compiler. The "target" of a C compiler is the processor for which it generates assembly instructions. The lcc compiler used in the download package is version 4.1 and has been ported to the mMIPS. A separate assembler (included with lcc) converts the mMIPS assembly to machine code that can be uploaded to the FPGA or fed to the hardware simulator. You need to rebuild it and set some environment settings before you can use the lcc compiler. See the paragraph installation below for an explanation of this procedure. See the usage example on how to use the compiler. The script dolcc included with the example applications gossip and multi-processor JPEG decoder invokes the lcc compiler. This script takes away the need to retype the compilation commands yourself (see the application design flow for more information).

Installation

Log on to an ICS server (e.g. co7.ics.ele.tue.nl). If you are using Windows you can use a SSH (Secure Shell) client such as SSH Secure Client to log on (instructions).

  1. Set up the environment for lcc
    Set the environment variable called LCCDIR in your logon script. The variable should contain the location of the folder ./lcc/lccdir. If you extracted the download package in your home directory then this location should be ~/mmips_noc/lcc/lccdir (~ is a shorthand notation for /home/you_home_dir). Which file is you logon script depends on the shell you get when you log on. You can determine which logon shell you have by typing ps (which gives a list of running processes) directly after you have logged on to an Linux server:
    1. bash
      If bash is in this list, then this should be your logon shell and ~/.bashrc should be your personal logon script. Include the following commands in this file (create it if doesn't exist):
      export LCCDIR=~/mmips_noc/lcc/lccdir
      export PATH=$PATH:$LCCDIR
    2. csh or tcsh
      If you see csh or tcsh in the list then you should include the following commands in the logon script ~/.cshrc (create it if it does not exist):
      setenv LCCDIR ~/mmips_noc/lcc/lccdir
      setenv PATH ${PATH}:${LCCDIR}
       
  2. Rebuild the lcc compiler
    Now that you have set up the environment, you can rebuild the lcc compiler:
    1. Go to the lcc directory (e.g. cd ~/mmips_noc/lcc)
    2. Remove all previous build output using the command make clean
    3. Rebuild the compiler using the command make

The lcc compiler that comes with the package is configured for a mMIPS with 16 kilobytes for instructions and 16 kilobytes for data. The mMIPS page shows how to change these memory sizes, if desired.

Usage example

This section describes how to compile an example program. The script dolcc included with the example applications gossip and multi-processor JPEG decoder invokes the lcc compiler, which takes away the need to type these commands yourself (see the software design flow for more information). As with any other compiler, you must first compile all source code files and then link the resulting object files into a binary.

Step 1: Compile the source code

Assume that we have a program which consists of 2 files foo1.cc and foo2.cc. Before we can make a binary of these files, we must first compile them. With lcc we use the following two commands:

lcc -c foo1.cc -o foo1.o
lcc -c foo2.cc -o foo2.o

The -c option tells the compiler that it should compile the source code file (e.g. foo1.cc and foo2.cc). After the -o option we put the name of the output file produced by the compiler.

Step 2: Link the object files

After all source code files have been compiled, we can link them into one binary. In our example, we have two object files foo1.o and foo2.o. Using the following command, we link them into the binary foo.

lcc foo1.o foo2.o -o foo