The Compcert verified compiler OVERVIEW: The Compcert verified compiler is a compiler for a large subset of the C programming language that generates code for the PowerPC, ARM and x86 processors. The distinguishing feature of Compcert is that it has been formally verified using the Coq proof assistant: the generated assembly code is formally guaranteed to behave as prescribed by the semantics of the source C code. Compcert is an ongoing research project. The present release is an advanced prototype intended for research, educational and evaluation purposes. COPYRIGHT: The Compcert verified compiler is Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Institut National de Recherche en Informatique et en Automatique (INRIA). It is distributed under the conditions stated in file LICENSE. SUPPORTED PLATFORMS: - PowerPC / MacOS [stable] For Apple Macs running the MacOS 10.4, 10.5 or 10.6 operating system. Both PowerPC-based and Intel-based Macs are supported. The PowerPC code generated by the Compcert compiler runs natively at full speed on PowerPC-based Macs, and runs under software emulation at reduced speed on Intel-based Macs. - PowerPC / Linux [somewhat experimental] For PowerPC machines running the Linux operating system. - IA32 / Linux or MacOS or Windows+Cygwin [experimental] For Intel/AMD x86 processors with SSE2 extensions (i.e. Pentium 4 and later), running either Linux, MacOS 10.6, or Windows with the Cygwin environment (http://www.cygwin.com/). - ARM / Linux [experimental] For ARM machines running the Linux operating system. PREREQUISITES: * The "gcc", "as" and "make" tools must be installed and accessible in the search path. For MacOS X, you can get them by installing the XCode development tools, as found on the installation DVDs or on http://developer.apple.com/. For Microsoft Windows, install the Cygwin environment http://www.cygwin.com/. * The Coq proof assistant, version 8.3pl1. Coq is free software, available from http://coq.inria.fr/ The original version 8.3 is not compatible, nor any of the 8.2 versions. * The Caml functional language, version 3.10 or later. Caml is free software, available from http://caml.inria.fr/ * Under MacOS 10.5 and 10.6, some standard C include files in /usr/include/ contain gcc-isms that cause errors when compiling with CompCert. Symptoms include: - references to undefined types uint16_t and uint32_t - a type error when using the "assert" macro. These issues have been reported through Apple Developer's Connection. Until Apple fixes them, you can apply the patch available from http://compcert.inria.fr/release/MacOSX-includes.patch Download this file, then do: sudo /bin/bash cd / patch -p0 < ..../MacOSX-includes.patch INSTALLATION: 1- Configure the system. From the top directory, do: ./configure where is one of: ppc-macosx (PowerPC, MacOS X) ppc-linux (PowerPC, Linux) arm-linux (ARM, Linux) ia32-linux (x86 SSE2 32 bits, Linux) ia32-macosx (x86 SSE2 32 bits, MacOS X) ia32-cygwin (x86 SSE2 32 bits, Cygwin environment for Windows) This generates the Makefile.config file in the top directory. The "configure" script accepts the following options: -bindir (default: /usr/local/bin) Directory where the binaries will be installed -libdir (default: /usr/local/lib/compcert) Directory where the Compcert support library will be installed (needed only under MacOS X) -prefix (default: /usr/local) Set bindir and libdir to /bin and /lib/compcert, respectively. 2- Build the system. From the top directory, do make all This re-checks all the Coq proofs, then extracts Caml code from the Coq specification and combines it with supporting hand-written Caml code to generate the executable for Compcert. This step takes 20 minutes or so on a recent machine; be patient. 3- You can now install Compcert. This will create the "ccomp" command in the binary directory selected during configuration, and install supporting .h and .a files in the library directory. Become superuser if necessary and do make install USAGE: The executable for Compcert is called "ccomp". It has the standard command-line interface for a Unix C compiler. For instance, to compile the single-file program "src.c" and create an executable called "exec", just do ccomp -o exec src.c To compile a two-file program "src1.c" and "src2.c", do ccomp -c src1.c ccomp -c src2.c ccomp -o exec src1.o src2.o To see the generated assembly code for "src1.c", do ccomp -S src1.c The generated assembly code is left in file src1.s The subset of the C language accepted by Compcert is quite large. The main features of C that are not supported are: - The "long long" and "long double" types. - Non-structured forms of the "switch" statement (Duff's device). - Variable-argument functions. The "ccomp" command will issue errors and diagnostics if it encounters a C construct that it cannot process. The "ccomp" command recognizes the following classes of input files: .c C source file .cm Cminor source file .s Assembly file .S Assembly file, to be run through the C preprocessor .o Object code file .a Library file The "ccomp" command recognizes the following options: Processing options: -E Preprocess only, send result to standard output -S Compile to assembler only, save result in .s -c Compile to object file only (no linking), result in .o Preprocessing options: -I Add to search path for #include files -D= Define preprocessor symbol -U Undefine preprocessor symbol Language support options (use -fno- to turn off -f) : -fbitfields Emulate bit fields in structs [off] -flonglong Partial emulation of 'long long' types [on] -fstruct-passing Emulate passing structs and unions by value [off] -fstruct-assign Emulate assignment between structs or unions [off] -fvararg-calls Emulate calls to variable-argument functions [on] Code generation options: -fmadd Use fused multiply-add and multiply-sub instructions -fsmall-data Set maximal size for allocation in small data area -fsmall-const Set maximal size for allocation in small constant area Tracing options: -dparse Save C file after parsing and elaboration in .parse.c -dc Save generated Compcert C in .compcert.c -dclight Save generated Clight in .light.c -dcminor Save generated Cminor in .cm -drtl Save unoptimized generated RTL in .rtl -dtailcall Save RTL after tail call optimization in .tailcall.rtl -dcastopt Save RTL after cast optimization in .castopt.rtl -dconstprop Save RTL after constant propagation in .constprop.rtl -dcse Save RTL after CSE optimization in .cse.rtl -dalloc Save LTL after register allocation in .alloc.ltl -dmach Save generated Mach in .mach -dasm Save generated assembly in .s Linking options: -l Link library -L Add to search path for libraries -o Generate executable in (default: a.out) General options: -stdlib Set the path of the Compcert stdlib wrappers -v Print external commands before invoking them CONTACT: The authors can be contacted by e-mail at compcert@yquem.inria.fr