Git Product home page Git Product logo

tiger2's Introduction

tiger2

A compiler written in Haskell for the Tiger language targeting MIPS.

Features

  • Successfully compiles and runs queens.tig and merge.tig
  • Uses alex and happy for lexing and parsing
  • FindEscape is completed
  • Register allocator implements spilling and coalescing
  • Spill cost is weighted by occurrences of uses and defs in loops
  • Handles functions with > 4 parameters

How to use

You need SPIM installed in order to run the compiled programs.


To compile and run all of the programs in the programs/ folder:

sh compile_and_run_all.sh

If you want to compile a single program, like for example, programs/queens.tig:

cabal exec tiger2 -- queens

In order to generate a Happy info table for debugging the parser:

sh gen_info_table.sh

The resulting info table will be in src/Tiger/Grammar.info.


You can also experiment in the REPL. First run:

chmod 644 .ghci

in order to turn off the write permissions for .ghci (ghci ignores that file otherwise). Then run:

cabal repl

and enter :ss in the prompt:

ghci> :ss

This unpacks all the functions in each compiler "module" to the toplevel along with everything in the Tiger.State record so you can run things like newTemp and allocLocal directly.

ghci> newTemp
25
ghci> regRa
4
ghci> :t allocLocal
allocLocal :: MipsFrame -> Bool -> IO (F.Access MipsFrame)

Also preexisting testing functions testParse, testTc, testTrans, testCanon, testCodegen, and compile are available from the REPL toplevel.

ghci> testTc "let type rec = { a: int, b: string } in rec { a = 1, b = \"hello\" } end"
(ESeqExp (SeqStm (MoveStm (TempExp 26) (CallExp (NameExp allocRecord) [ConstExp 8])) (SeqStm (MoveStm (MemExp (BinOpExp Plus (TempExp 26) (ConstExp 0))) (ConstExp 1)) (MoveStm (MemExp (BinOpExp Plus (TempExp 26) (ConstExp 4))) (NameExp L25)))) (TempExp 26),RecordTy [(a,IntTy),(b,StringTy)] Unique)

tiger2's People

Contributors

darinm223 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.