Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wuruoyu/a-working-c-compiler
Implement a working compiler for a C language subset (front-end + various optimizatons on LLVM IR + back-end)
https://github.com/wuruoyu/a-working-c-compiler
c compiler llvm
Last synced: 23 days ago
JSON representation
Implement a working compiler for a C language subset (front-end + various optimizatons on LLVM IR + back-end)
- Host: GitHub
- URL: https://github.com/wuruoyu/a-working-c-compiler
- Owner: wuruoyu
- Created: 2022-09-16T20:26:01.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-19T18:24:10.000Z (about 2 years ago)
- Last Synced: 2024-08-08T21:39:42.816Z (6 months ago)
- Topics: c, compiler, llvm
- Language: C++
- Homepage:
- Size: 5.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## A working compiler for a C language subset
This project, USCC, builds out a working compiler for a C language subset called USC ([language reference](./USCLanguage.pdf)).
USCC uses the LLVM framework as its code generation engine.#### Project 1: Recursive Descent Parsing
Implemented a `LL(1) parser` that parses the program into AST. [[Handout]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/P1.pdf) [[Report]](https://github.com/wuruoyu/CS502-Compiler/blob/master/uscc/uscc/report/reportP1.pdf)#### Project 2: Semantic Analysis
Implemented scoped symbol table that enable scoped identifier declarations, and type checking/conversion that enables conversion between `char` and `int`. [[Handout]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/p2.pdf) [[Report]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/reportP2.pdf).#### Project 3: LLVM IR Generation
Implemented an `IREmitter` that lowers various types of AST node (e.g., `While` statement, `If` statement) to LLVM IR using `llvm::IRBuilder`. [[Handout]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/P3.pdf) [[Report]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/reportP3.pdf)#### Project 4: Static Single Assignment (SSA) generation
Implemented a fairly new approach to generate SSA form as outlined in [this paper](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/Simple%20and%20Efficient%20Construction%20of%20Static%20Single%20Assignment%20Form.pdf), which directly generate SSA form from the high-level AST, without generating non-SSA form first as in Clang/LLVM. [[Handout]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/P4.pdf) [[Report]](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/reportP4.pdf)#### Project 5: LLVM Optimization Passes
Implemented three LLVM optimization passes, including constant branch folding, dead block removal and loop invariant code motion (LICM).#### Project 6: Register Allocation (via graph-coloring)
Implemented a graph-coloring register allocator with LLVM infrastructure (using `RegAllocBase` interface), following this helpful [tutorial](https://github.com/nael8r/How-To-Write-An-LLVM-Register-Allocator). The algorithm is described in the [Chatin-Brigg’s paper](https://github.com/wuruoyu/A-Working-C-Compiler/blob/master/uscc/uscc/report/Chaitin-Briggs.pdf).