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.
-
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.
-
Tiger compiler in C++ uses namespace for modularization and uses inheritance and polymorphism to replace unions used in the old labs.
-
Tiger compiler in C++ uses CMake instead of Makefile to compile and build the target.
We provide you a Docker image that has already installed all the dependencies. You can compile your codes directly in this Docker image. Visit https://ipads.se.sjtu.edu.cn/courses/compilers/tiger-compiler-environment.html to find a detailed guide.
There are five makeable targets in total, including test_slp, test_lex, test_parse, test_semant, test_translate_llvm, test_codegen and tiger-compiler.
- Run container environment and attach to it, here is a simple example:
# 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}You can also follow the guide on https://ipads.se.sjtu.edu.cn/courses/compilers/tiger-compiler-environment.html to build a container. It offers a user-friendly script for Windows users and addresses most networking issues related to Docker Hub.
- Build in the container environment
mkdir build && cd build && cmake .. && make test_xxx # or `make build`- Debug using gdb or any IDEs
gdb test_xxx # e.g. `gdb test_slp`Use make
make gradelabxYou can test all the labs by
make gradeallPush your code to your GitLab repo
git add somefiles
git commit -m "A message"
git pushNote, 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.
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.
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.
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.
You can read external documentations on our course website: