Skip to content
A Small C Compiler
Branch: master
Clone or download
rui314 Merge pull request #85 from mame/fix-incdec-struct
The movement of inc/decrement must follow its type
Latest commit b8a46ab Dec 23, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
include Update copyright notice. Mar 28, 2015
test The movement of inc/decrement must follow its type Dec 22, 2016
.gitignore .gitignore: remove obsolete entries and sort the lines. Nov 30, 2014
8cc.h Fix NetBSD build: Include missing header for va_list in 8cc.h Oct 4, 2016
HACKING.md Add HACKING.md. Dec 17, 2014
LICENSE Rename COPYING -> LICENSE. Mar 29, 2015
Makefile Always use 8cc to build test/*.o Dec 7, 2016
README.md Add a comment on the draft versions of the C standards. Mar 22, 2015
buffer.c Update copyright notice. Mar 28, 2015
cpp.c Try user include paths before standard ones Nov 5, 2016
debug.c Update copyright notice. Mar 28, 2015
dict.c Update copyright notice. Mar 28, 2015
encoding.c Update copyright notice. Mar 28, 2015
error.c Preprocessor: Print accurate error locations. Mar 29, 2015
file.c Preprocessor: Print accurate error locations. Mar 29, 2015
gen.c The movement of inc/decrement must follow its type Dec 22, 2016
keyword.inc Update copyright notice. Mar 28, 2015
lex.c Allow universal-character-name in identifiers. Apr 6, 2015
main.c Update copyright notice. Mar 28, 2015
map.c Update copyright notice. Mar 28, 2015
parse.c Initialize Type object created by make_numtype Sep 9, 2016
path.c Update copyright notice. Mar 28, 2015
set.c Update copyright notice. Mar 28, 2015
utiltest.c Update copyright notice. Mar 28, 2015
vector.c Update copyright notice. Mar 28, 2015

README.md

8cc C Compiler

8cc is a compiler for the C programming language. It's intended to support all C11 language features while keeping the code as small and simple as possible.

The compiler is able to compile itself. You can see its code both as an implementation of the C language and as an example of what this compiler is able to compile.

8cc's source code is carefully written to be as concise and easy-to-read as possible, so that the source code becomes good study material to learn about various techniques used in compilers. You may find the lexer, the preprocessor and the parser are already useful to learn how C source code is processed at each stage.

It's not an optimizing compiler. Generated code is usually 2x or more slower than GCC. I plan to implement a reasonable level of optimization in the future.

8cc supports x86-64 Linux only. I have no plan to make it portable until I fix all known miscompilations and implement an optimization pass. As of 2015, I'm using Ubuntu 14 as my development platform. It should work on other x86-64 Linux distributions though.

Note: Do not have high expectations on this compiler. If you try to compile a program other than the compiler itself, there's a good chance to see compile errors or miscompilations. This is basically a one-man project, and I have spent only a few months of my spare time so far.

Build

Run make to build:

make

8cc comes with unit tests. To run the tests, give "test" as an argument:

make test

The following target builds 8cc three times to verify that stage1 compiler can build stage2, and stage2 can build stage3. It then compares stage2 and stage3 binaries byte-by-byte to verify that we reach a fixed point.

make fulltest

Author

Rui Ueyama rui314@gmail.com

Links for C compiler development

Besides popular books about compiler, such as the Dragon Book, I found the following books/documents are very useful to develop a C compiler. Note that the standard draft versions are very close to the ratified versions. You can practically use them as the standard documents.

You can’t perform that action at this time.