implement a full compiler based on c++ 11
APACHE-2.0 License
This tiny compiler includes both front end and back end.
Front end: Grammar Rules, LL(1) Parse Table, Syntax and Semantic Check and Intermediate Code.
Back end: IR Optimization (Intra-block CFG optimization), MIPS Register Allocation, Instruction Selection and Code Generation.
You can access https://github.com/gangliao/TIGER to view the documentation!
development environment
Currently, this project repository is maintained on github publicly and also been deployed on Travis CI. It supports both Ubuntu and Mac OS X.
build:
# cd project dir
cd Tiger-Compiler
# build scanner, parser, generator
mkdir build && cd build
# cmake building tool
cmake ..
make -j4
run:
You can parsing test cases named *.tiger
under /testCases2
to generate IR code.
Default it will utilize CFG optimized technique to generate MIPS asm code.
# verbose mode: "-d to implement a verbose mode"
./src/parser <filename> -d
If you want to use the naive mode to generate asm code, simply issue:
./src/parser <filename> -d -naive
test:
In testCases2 directory, it includes a test script test.sh
to execute all test cases and
generate the corresponding asm files *.naive.s
and *.cfg.s
.
After souce code is compiled, you can simply issue the commands:
cd testCases2
sh ./test.sh
NOTE: This demo is gif
graph format. If you have problem to view it in the markdown file,
you can directly open it which located at img/demo.gif
.
This Demo shows that
(1) [Compile Source Code] How to compile and generate parser binary ?
(2) [Compiler Front End] How to transfrom raw tiger program into IR code ?
(3) [Compiler Back End] How to generate optimized MIPS asm code via IR code ?
Tiger Compiler Front End - Design Internals
Tiger Compiler Back End - Design Internals
We passed all tests cases which provided by TA.
Please check out the details in report Phase2_Testing_and_Output.pdf from current directory, which includes test cases and their quality comparisons for naive and CFG intra-block register allocation.