gangliao / TIGER

implement a full compiler based on c++ 11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TIGER - A Tiny Full Compiler

Build Status

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!

How to Build

  1. 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.

  2. build:

    	# cd project dir
    	cd Tiger-Compiler
    	# build scanner, parser, generator
    	mkdir build && cd build
    	# cmake building tool
    	cmake ..
    	make -j4
  3. 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
  4. 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

Demo

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 ?

Desgin Internals

Tiger Compiler Front End - Design Internals

Tiger Compiler Back End - Design Internals

Test Cases

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.

Accomplishment

  • Register allocation code
    • Naive
    • CFG and intra block allocation
    • EBB and intra-EBB allocation
    • Whole function register allocation
    • Live Range Analysis and Graph Coloring
  • Instruction selection and generation code
  • Passes tests using generated code executing on simulator.
  • Report (desgin Internals, how to build, run, code quality comparisions, etc.)

About

implement a full compiler based on c++ 11

License:Apache License 2.0


Languages

Language:Assembly 50.6%Language:C++ 42.6%Language:Python 3.1%Language:HTML 3.1%Language:CMake 0.5%Language:Shell 0.1%