Skip to content

onehr/crust

Repository files navigation

CRUST

Build Status Gitter FOSSA Status GitHub commit activity GitHub

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).

Project Goal

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.

Milestone 0.1 Goal

  1. Finish the preprocessor.
  2. Support all C11 grammar rules.
  3. replace gcc with it's own assembler to generate binary code
  4. Stabilize the interfaces among different layers.
  5. With some possible optimizations.

Track of current progress

  • 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, ...)
  • 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)]

Requirements

You need a valid rust environment, Cargo.

Build

(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> ...

Running Tests

Run:

$ ./test_dev.sh

Benchmark

(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.

License

FOSSA Status