A SysY2022 to ARMv7 optimizing compiler built for the 2023 Compiler System Design contest (Bisheng Cup). The project emphasizes a clean end-to-end pipeline, solid IR/SSA-based optimization, and a practical backend that produces linkable ARMv7 assembly.
SysY2022 is a C subset with extensions used in the contest.
- Source files end in
.syand contain a singlemainplus optional globals and helper functions - Types:
int(32-bit signed) andfloat(32-bit IEEE single), plus multi-dimensional row-major arrays constsupported; variables must be declared before use- Statements: assignment, expression, block,
if,while,break,continue,return - Expressions: arithmetic, relational, logical with C-like precedence and short-circuiting
- Functions:
int/floatreturn types orvoid; arrays passed by address - Implicit
int<->floatconversion is allowed - I/O and timing are provided by the SysY runtime library (
libsysy.a):getint,getfloat,putint,putfloat,putf,starttime,stoptime, etc.
The graph below highlights the compiler stages I built and integrated.
flowchart LR
A[SysY2022 .sy] --> B[Lexer / Parser]
B --> C[AST + Semantic Analysis]
C --> D[MIR]
D --> E[SSA + Optimizations]
E --> F[ARMv7 ASM .s]
classDef me fill:#FFE7C2,stroke:#8A5A00,stroke-width:1px,color:#2B1B00;
class B,C,D,E,F me;
- SSA construction with CFG-based passes
- Constant propagation, dead-code elimination, copy/replicate propagation
- Global value numbering and redundant computation removal
- Array motion and peephole cleanup
- Graph-coloring register allocation with spill handling
This chart is a qualitative view of where each optimization tends to land in impact vs. engineering effort.
quadrantChart
title Optimization Impact Map (qualitative)
x-axis Low Effort --> High Effort
y-axis Low Impact --> High Impact
quadrant-1 "Sweet Spots"
quadrant-2 "Big Bets"
quadrant-3 "Low ROI"
quadrant-4 "Quick Wins"
"Const Prop" : [0.35, 0.75]
"DCE" : [0.30, 0.70]
"GVN" : [0.75, 0.85]
"GCM" : [0.85, 0.80]
"Copy/Replicate" : [0.55, 0.65]
"Peephole" : [0.25, 0.55]
"Reg Alloc" : [0.90, 0.90]
cmake -S src -B build
cmake --build build -j./build/compiler path/to/test.sy
# emits path/to/test.sEnable extra optimization:
./build/compiler path/to/test.sy -O1Link and run (ARMv7 cross toolchain + QEMU):
arm-linux-gnueabihf-gcc -march=armv7 path/to/test.s src/libsysy.a --static -o test.bin
qemu-arm test.bin < test.in > test.outsrc/frontend: lexer/parser (Flex/Bison) and front-end gluesrc/structure/ast: AST and semantic analysissrc/structure/mir: MIR and ARMv7 code generationsrc/backend: SSA, CFG, optimizations, and register allocationsrc/utils: shared utilities
- Target output is ARMv7 assembly (32-bit)
- Runtime library is linked statically via
src/libsysy.a - The compiler is designed as a clear, modular pipeline suitable for extension