You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
8cc is a small C compiler. It supports a broad range of C99 features, such as
compound literals or designated initializers. Some GNU extensions, such as
computed gotos, are also supported. 8cc is self-hosting, which means 8cc can
compile itself.
8cc's source code is carefully written to be as concise and easy-to-read as
possible, so that the source code will eventually be a good study material to
learn various techniques used in compilers. You might find the lexer, the
preprocessor and the parser are already useful to learn how C source code is
processed at each stage.
It does not produce optimized assembly code; 8cc treats the CPU as a stack
machine. Local variables are always assigned on the stack. Operations in the
form of A = B op C are executed in the following way.
Load B and C to registers
Apply op to yield a result
Write the results back to A's location
Producing optimized assembly is being planned.
Build
Run make to build:
make
8cc comes with unit tests. To run the tests, give "test" as an argument:
make test
The following command compiles 8cc three times. The second generation
binary and the third are self-compiled ones, and it's tested that they
are identical. The unit tests are run for each generation of binaries.
make fulltest
8cc supports x86-64 Linux only. I'm using Ubuntu 11 as a development platform.
It should work on other x86-64 Linux distributions.