Skip to content
TheUnknownThingPublic

About

A compiler designed for the subset of Rust (https://github.com/peterzheng98/RCompiler-Spec).

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

RCompiler

A C++ implementation of a compiler for a subset of the Rust programming language.

Project Structure

RCompiler/
├── src/
│   ├── ast/
│   ├── backend/
│   ├── ir/
│   ├── lexer/
│   ├── opt/
│   ├── preprocessor/
│   ├── semantic/
│   ├── utils/
│   └── main.cpp
├── include/
│   ├── ast/
│   ├── backend/
│   ├── common/
│   ├── ir/
│   ├── lexer/
│   ├── opt/
│   ├── preprocessor/
│   ├── semantic/
│   └── utils/
├── tests/
│   └── ci_*.cpp
├── CMakeLists.txt
├── README.md
└── whitelist.md

Original Repo

This project implements RCompiler-Spec as homework of Compilers 2025 at Shanghai Jiao Tong University.

Implemented Features

See whitelist.md for the concrete, implementable subset of the Rust language that the RCompiler parser and type checker will support. This subset is derived from the current Rust specification, excluding features that are explicitly removed or marked as undefined behavior.

Implementation Status

  • Preprocessor

    • Remove Comments
    • Check invalid ASCII character
  • Lexer

    • Identify keywords / identifiers
    • Classify literals (strings, numbers, etc.)
  • Parser

    • Parse expr, stmts, items
  • Semantic Checking

    • First Pass
      • Symbol Table Construction
      • Scope Management
    • Builtin Types and Functions
    • Second Pass
      • Type Resolution
      • Function Signature Verification
      • Constant Evaluation
    • Third Pass
      • Promote impl blocks to struct/trait definitions
    • Fourth Pass
      • Pattern Binding
      • Type Checking
      • Borrow Checking
      • Expression Analysis
    • Control Flow Analysis
      • Return Path Verification
  • IR Codegen

    • LLVM IR Emission
    • Module / function / basic block IR construction
  • IR Optimization

    • CFG construction and refresh
    • Aggressive Dead Code Elimination (DCE)
      • Remove instructions after terminators
      • Fold constant conditional branches
      • Eliminate unreachable blocks
      • Remove dead instructions (those with no side effects and whose results are not used)
    • Mem2Reg / SSA promotion
    • Function inlining
    • Instruction combining
      • Constant folding
      • Algebraic simplification
      • Strength reduction
    • Sparse Conditional Constant Propagation (SCCP)
    • CFG simplification
      • Remove unreachable blocks
      • Fold trivial phi nodes
      • Merge trivial basic blocks
    • GVN & GCM (TBD)
  • Backend Codegen

About

A compiler designed for the subset of Rust (https://github.com/peterzheng98/RCompiler-Spec).

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages