A simple C compiler written in the Rust-lang. (early development stage, started at Mar 30, 2019)
(PS. this is the development branch, if you want to see how to write a simple c compiler in rust, you should check branch toy, which contains a simple c compiler written in rust without extra libs, it can read simple c source code and produce x86-64 assembly code).
Should follow the C11 Standard and generate binary code from C source code.
This compiler is in the very early development stage, the plan is to continue developing it until it can compile real-world applications.
If you are interested in crust
and want to contribute, feel free to join the Gitter chat room,
we have already got some contributors now who are interested in building this project.
- Finish the preprocessor.
- Support all C11 grammar rules.
- replace gcc with it's own assembler to generate binary code
- Stabilize the interfaces among different layers.
- With some possible optimizations.
- Preprocessor (working on)
- support
#include "local-header"
, nested-include is supported (need to add more features) - Trigraph translation
- comment support
/**/ and //
- line concatenation with
\
- object-like macro expansion
- function-like macro expansion
- should support all directives (ifdef, elif, endif, ...)
- support
- Lexer (working on)
- lex all c11 keywords
- the floating point number and number with postfix should be supported later.
- Parser (almost done, need to be carefully tested)
- support c11 standard and generate ast tree
- better ast printer
- should be able handle typedef
- add more tests for parser
- Semantics Analyzer (working on)
- Type system
- Type checker
- Benchmark (working on)
- Use Criterion.rs to do benchmarks.
- Generate more informations from benchmarking.
- IR generator (TODO)
- Optimizer (TODO)
- Assembly code generator (TODO)
- Code clean up
- Remove
#[allow(dead_code)]
- Remove
You need a valid rust environment, Cargo.
(PS. Now the crust can only preprocess, lex, and parse the source code, the generator was disabled now).
$ cargo build # use this command to build the project
run
$ cargo run [FLAGS] <files> ...
Run:
$ ./test_dev.sh
(PS. This is pretty time consuming, cause benchmark will do lots of iterations to test different layers' performance.
Might take 20 to 30 minutes until it is finished. ) Run:
$ cargo bench
After it is finished,
you can open target/criterion/report/index.html
in your web browser to see the details of performance.