C-- is a compiler-target language. The idea is that a compiler for a high-level language translates programs
into into C--, leaving the C-- compiler to generate native code. C--’s major goals are these:
• C-- encapsulates compilation techniques that are well understood, but difficult to implement. Such
techniques include instruction selection, register allocation, instruction scheduling, and optimization
of imperative code with loops.
• C-- is a language, rather than a library (such as gcc’s RTL back end). As such, it has a concrete syntax
that can be read by people, and a semantics that is independent of any particular implementation.
• C-- is a portable assembly language. It is, by design, as low-level as possible while still concealing
details of the particular machine architecture.
• C-- is independent of both source programming language and target architecture. Its design accom-
modates a variety of source languages and leaves room for back-end optimization, all without upcalls
from the back end to the front end.
• C-- is efficient—or at least admits efficient implementation. So C-- provides almost as much flexibility
and performance (assuming a good C-- compiler) as a custom code generator.
A client of C-- is divided into two parts. The front-end compiler generates programs written in the C--
language, which the C-- compiler translates into efficient machine code. This code interoperates with the
front-end run-time system, which implements such services as garbage collection, exception dispatch, thread
scheduling, and so on. The front-end run-time system relies on mechanisms provided by the C-- run-time
system; they interact through the C-- run-time interface. This document describes the C-- language and
run-time interface. It is intended for authors who wish to write clients of the C-- system.
The C-- team has prepared some demonstration front ends that may help you learn to use C--.
• Paul Govereau’s tigerc compiler includes a compiler for Tiger (the language of Andrew Appel’s
compiler text) as well as a small run-time system with garbage collector. The tigerc compiler is
written in Objective Caml.
• Norman Ramsey’s lcc back end works with lcc to translate C into C--. It is written in C.
• Reuben Olinsky’s interpreter, which is packaged with the Quick C-- sources, includes sample run-time
clients for garbage collection and exception dispatch.
All this code is available through the C-- web site at http://www.cminusminus.org
1.1 What C-- is not
C-- has some important non-goals:
• C-- is not an execution platform, such as the Java Virtual Machine or the .NET Common Language
Runtime. These virtual machines are extremely high-level compared to C--. Each provides a rich type
system, garbage collector, class loader, just-in-time compiler, byte-code verifier, exception-dispatch
mechanism, debugger, massive libraries, and much more besides. These may be good things, but
they clearly involve much more than encapsulating code-generation technology, and depending on your
language model, they may impose a significant penalty in both space and time.
• C-- is not “write-once, run-anywhere”. It conceals most architecture-specific details, such as the
number of registers, but it exposes some. In particular, C-- exposes the word size, byte order, and
alignment properties of the target architecture, for two reasons. First, to hide these details would
require introducing a great deal of complexity, inefficiency, or both—especially when the front-end
compiler needs to control the representation of its high-level data types. Second, these details are easy
to handle in a front-end compiler. Indeed, a compiler may benefit, because it can do address arithmetic
using integers instead of symbolic constants such as FloatSize and IntSize.