C是一种编辑性语言,c-compiler: 8cc 是一个小型的 C 编译器,它旨在支持所有C11语言功能,同时使代码尽可能的小而简单...

8cc C Compiler

Note: 8cc is no longer an active project. The successor is

chibicc.

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值