Skip to content

shioyama18/rcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust C Compiler (rcc)

About

rcc is a toy C compiler written in Rust (In Progress). This compiler is inspired by the article - Writing a C Compiler. Tests are taken from the author's repository.

Usage

This program will output x64 Assembly in Intel syntax. Given the c program below as the first argument, rcc will emit the assembly language to stdout.

// test.c
int add(int a, int b) {
    return a + b;
}

int main() {
    int sum = add(1 + 2, 4);
    return sum + sum;
}
$ cargo run test.c > test.s
$ gcc -o test test.s && ./test
$ echo $?
14

Progress

Although "int" is the only supported type, you can define variables and functions. Below are list of implemented features:

  1. Arithmetic Operator
    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
    • Modulus (%)
  2. Logical Operator
    • AND (&&)
    • OR (||)
    • NOT (!)
  3. Bitwise Operator
    • AND (&)
    • OR (|)
    • XOR (^)
    • Complement (~)
    • Left Shift (<<)
    • Right Shift (>>)
  4. Assignment Operator
    • Assignment (=)
    • Add and assign (+=)
    • Subtract and assign (-=)
    • Multiply and assign (*=)
    • Divide and assign (/=)
    • Modulo and assign (%=)
  5. Relational Operator
    • Equal (==)
    • Not Equal (!=)
    • Less Than (<)
    • Less Than Or Equal (<=)
    • Greater Than (>)
    • Greater Than or Equal (>=)
  6. Conditional
    • if
    • Ternary Operator (?)
  7. Loops
    • for
    • while
    • do .. while
    • break
    • continue

About

Toy C compiler implemented with Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages