A C++ implementation of a compiler for a subset of the Rust programming language.
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
This project implements RCompiler-Spec as homework of Compilers 2025 at Shanghai Jiao Tong University.
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.
-
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
implblocks tostruct/traitdefinitions
- Promote
- Fourth Pass
- Pattern Binding
- Type Checking
- Borrow Checking
- Expression Analysis
- Control Flow Analysis
- Return Path Verification
- First Pass
-
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