Giter VIP home page Giter VIP logo

tiger-compiler's Introduction

Tiger Compiler Labs in C++

Contents

Tips

  1. 使用docker
     sudo make docker-run
     cd tiger-compiler
     make clean
     make gradelabX
  2. 运行单个测试用例
  • lab2
    cd build
    ./test_lex /home/stu/tiger-compiler/testdata/lab2/testcases/merge.tig
  • lab3
    cd build
    ./test_parse /home/stu/tiger-compiler/testdata/lab3/testcases/merge.tig
  • lab4
    cd build
    ./test_semant /home/stu/tiger-compiler/testdata/lab4/testcases/test10.tig
  • lab5-part1
    cd build
    ./test_translate /home/stu/tiger-compiler/testdata/lab5or6/testcases/bsearch.tig
  • lab5
      cd build
     ./test_codegen /home/stu/tiger-compiler/testdata/lab5or6/testcases/bsearch.tig
     cd ../scripts/lab5_test
     python3 main.py -d ../../testdata/lab5or6/testcases/tfo.tig.s
     python3 main.py ../../testdata/lab5or6/testcases/tfo.tig.s
     cd ../../build
     p label_->Name()
  • lab6
     ./tiger-compiler /home/stu/tiger-compiler/testdata/lab5or6/testcases/tfo.tig
     gcc -Wl,--wrap,getchar -m64 /home/stu/tiger-compiler/testdata/lab5or6/testcases/tfo.tig.s /home/stu/tiger-compiler/src/tiger/runtime/runtime.c -o test.out
     ./test.out
     objdump -d test.out > test-fact.asm
  • lab7
    cmake -DCMAKE_BUILD_TYPE=DEBUG ..
    ./tiger-compiler /home/stu/tiger-compiler/testdata/lab7/testcases/simple_array.tig
    g++ -g -Wl,--wrap,getchar -m64 /home/stu/tiger-compiler/src/tiger/runtime/runtime.cc /home/stu/tiger-compiler/testdata/lab7/testcases/simple_array.tig.s /home/stu/tiger-compiler/src/tiger/runtime/gc/heap/derived_heap.cc -o test.out

Overview

We rewrote the Tiger Compiler labs using the C++ programming language because some features in C++ like inheritance and polymorphism are more suitable for these labs and less error-prone.

We provide you all the codes of all labs at one time. In each lab, you only need to code in some of the directories.

Difference Between C Labs and C++ Labs

  1. Tiger compiler in C++ uses flexc++ and bisonc++ instead of flex and bison because flexc++ and bisonc++ is more flexc++ and bisonc++ are able to generate pure C++ codes instead of C codes wrapped in C++ files.

  2. Tiger compiler in C++ uses namespace for modularization and uses inheritance and polymorphism to replace unions used in the old labs.

  3. Tiger compiler in C++ uses CMake instead of Makefile to compile and build the target.

Installing Dependencies

We provide you a Docker image that has already installed all the dependencies. You can compile your codes directly in this Docker image.

  1. Install Docker.

  2. Run a docker container and mount the lab directory on it.

# Run this command in the root directory of the project
docker run -it --privileged -p 2222:22 -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest  # or make docker-run

Compiling and Debugging

There are five makeable targets in total, including test_slp, test_lex, test_parse, test_semant, and tiger-compiler.

  1. Run container environment and attach to it
# Run container and directly attach to it
docker run -it --privileged -p 2222:22 \
    -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest  # or `make docker-run`
# Or run container in the backend and attach to it later
docker run -dt --privileged -p 2222:22 \
    -v $(pwd):/home/stu/tiger-compiler ipadsse302/tigerlabs_env:latest
docker attach ${YOUR_CONTAINER_ID}
  1. Build in the container environment
mkdir build && cd build && cmake .. && make test_xxx  # or `make build`
  1. Debug using gdb or any IDEs
gdb test_xxx # e.g. `gdb test_slp`

Note: we will use -DCMAKE_BUILD_TYPE=Release to grade your labs, so make sure your lab passed the released version

Testing Your Labs

Use make

make gradelabx

You can test all the labs by

make gradeall

Submitting Your Labs

Push your code to your GitLab repo

git add somefiles
git commit -m "A message"
git push

Note, each experiment has a separate branch, such as lab1. When you finish the lab1, you must submit the code to the lab1 branch. Otherwise, you won't get a full score in your lab.

Formatting Your Codes

We provide an LLVM-style .clang-format file in the project directory. You can use it to format your code.

Use clang-format command

find . \( -name "*.h" -o -iname "*.cc" \) | xargs clang-format -i -style=file  # or make format

or config the clang-format file in your IDE and use the built-in format feature in it.

Other Commands

Utility commands can be found in the Makefile. They can be directly run by make xxx in a Unix shell. Windows users cannot use the make command, but the contents of Makefile can still be used as a reference for the available commands.

Contributing to Tiger Compiler

You can post questions, issues, feedback, or even MR proposals through our main GitLab repository. We are rapidly refactoring the original C tiger compiler implementation into modern C++ style, so any suggestion to make this lab better is welcomed.

External Documentations

You can read external documentations on our course website:

tiger-compiler's People

Contributors

zhaohaoru avatar jinzesi avatar pleiadesian avatar sjtu-jump-2022 avatar

Stargazers

 avatar LittleQi avatar Steven.Liu avatar Eason Wang avatar

Watchers

 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.