GithubHelp home page GithubHelp logo

gangliao / tiger Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 10.0 42.49 MB

implement a full compiler based on c++ 11

License: Apache License 2.0

C++ 42.62% HTML 3.05% Python 3.11% Shell 0.12% CMake 0.49% Assembly 50.61%
compiler parser scanner graph-coloring code-generator cplusplus-11 front-end backend

tiger's Introduction

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

tiger's People

Contributors

gangliao avatar rachnas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tiger's Issues

Test case pass rate

Passing test cases ... @Rachnas

  • test 1
  • test 2
  • test 3
  • test 4
  • test 5
  • test 6
  • test 7
  • test 8
  • test 9
  • test 10
  • test 11
  • test 12
  • test 13
  • test 14
  • test 15
  • test 16
  • test 17 @gangliao while
  • test 18 while
  • test 19
  • test 20
  • test 21
  • test 22
  • test 23
  • test 24
  • test 25
  • test 26

Progress

  • naive mode
  • cfg
  • ebb
  • instruction selection
  • code generation
  • function call
  • pass all test cases

I think we do not have to implement ebb. @Rachnas

Symbol Table Design Doc

When I read source code from Semantic Analyzer directory, I found two files are important to implement symbol table, which is SymbolTablePair.hpp and SymbolTable.hpp.

The report states that we can utilize hash table data structure to accomplish this. Thus, to the best of my knowledge, SymbolTablePair includes Entry and name, Entry could be Variables, Constants, Types, Functions, Temporaries, name is something like terminal id in this language.

We can define

class SymbolTable {
   std::map<SymbolTablePair, Record> symbol_table_;
....
}

red-black tree in C++ STL, SymbolTablePair can be regarded as table entries, Record is actual stuff in this table.

Symbol table implementation is quite easy.
We can fit all things into map data structure, but the really tricky part is how to implement scoping.

I will read textbook to find some ideas...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.