Code Monkey home page Code Monkey logo

crust's Introduction

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

crust's People

Contributors

austinpgraham avatar b00f avatar bors[bot] avatar kinggoesgaming avatar onehr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.