Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

8cc

A Small C Compiler

Subscribe to updates I use 8cc


Statistics on 8cc

Number of watchers on Github 3226
Number of open issues 32
Average time to close an issue 14 days
Main language C
Average time to merge a PR about 12 hours
Open pull requests 9+
Closed pull requests 21+
Last commit over 2 years ago
Repo Created over 7 years ago
Repo Last Updated over 1 year ago
Size 1.31 MB
Organization / Authorrui314
Contributors7
Page Updated
Do you use 8cc? Leave a review!
View open issues (32)
View 8cc activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating 8cc for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

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.

  • LCC: A Retargetable C Compiler: Design and Implementation http://www.amazon.com/dp/0805316701, https://github.com/drh/lcc

  • TCC: Tiny C Compiler http://bellard.org/tcc/, http://repo.or.cz/w/tinycc.git/tree

  • C99 standard final draft http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

  • C11 standard final draft http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

  • Dave Prosser's C Preprocessing Algorithm http://www.spinellis.gr/blog/20060626/

  • The x86-64 ABI http://www.x86-64.org/documentation/abi.pdf

8cc open issues Ask a question     (View All Issues)
  • over 3 years internal error for the use of rvalue struct
  • over 3 years Make libFirm frontend (C11) and backend (x86-64)
  • almost 4 years Error in tag scoping
  • almost 4 years tentative definitions not handled
  • almost 4 years Struct arguments size 8 - 32 bytes not passed in registers
  • about 4 years Compound assignment lvalue evaluated twice.
  • about 4 years failed to parse function return function pointers
  • over 4 years Test suite single file tests
  • over 4 years Miscompilation bug
  • over 4 years Miscompilation bug
  • over 4 years Miscompilation bug
  • over 4 years Miscompilation bug
  • over 4 years 72 crashing files
  • over 4 years maybe bug in gen.c
  • over 4 years segfault
  • over 4 years Various problems.
  • about 5 years Static initializers with complex address constants.
8cc open pull requests (View All Pulls)
  • Define -a flag as dumpast.
  • Run tests on travis
  • Fix nested parens in declarators.
  • 8cc codegen is accessing (potentially) uninitialized struct fields
  • Fix a parser bug in struct initialization.
  • fix a spelling error
  • Remove extra goto statement.
  • Fix memory leak.
  • Fix typos in comment; slightly reword for brevity
8cc list of languages used
More projects by rui314 View all
Other projects in C