此仓库为2022年NKU编译原理课程的大作业,构建过程切换分支可见。代码仅供参考。如果你觉得有用,请给我一颗星,非常感谢!
This repository is the final project for the NKU Compiler Principles course in 2022. The building process can be seen by switching branches.
The code is provided for reference only. If you find it helpful, please give me a star. Thank you very much!
Usage:build/compiler [options] infile
Options:
-o <file> Place the output into <file>.
-t Print tokens.
-a Print abstract syntax tree.
-i Print intermediate code
-S Print assembly code
提供了VSCode调试所需的json文件,使用前需正确设置launch.json中miDebuggerPath中gdb的路径。launch.json中args值即为编译器的参数,可自行调整。
- 修改测试路径:
默认测试路径为test,你可以修改为任意要测试的路径。我们已将最终所有测试样例分级上传。
如:要测试level1-1下所有sy文件,可以将makefile中的
TEST_PATH ?= test
修改为
TEST_PATH ?= test/level1-1
- 编译:
make
编译出我们的编译器。
- 运行:
make run
以example.sy文件为输入,输出相应的汇编代码到example.s文件中。
- 测试:
make testlab7
该命令会搜索TEST_PATH目录下所有的.sy文件,逐个输入到编译器中,生成相应的汇编代码.s文件。你还可以指定测试目录:
make testlab7 TEST_PATH=dirpath
- 批量测试:
make test
对TEST_PATH目录下的每个.sy文件,编译器将其编译成汇编代码.s文件, 再使用gcc将.s文件汇编成二进制文件后执行, 将得到的输出与标准输出对比, 验证编译器实现的正确性。错误信息描述如下:
| 错误信息 | 描述 |
|---|---|
| Compile Timeout | 编译超时, 可能是编译器实现错误导致, 也可能是源程序过于庞大导致(可调整超时时间) |
| Compile Error | 编译错误, 源程序有错误或编译器实现错误 |
| Assemble Error | 汇编错误, 编译器生成的目标代码不能由gcc正确汇编 |
| Execute Timeout | 执行超时, 可能是编译器生成了错误的目标代码 |
| Execute Error | 程序运行时崩溃, 可能原因同Execute Timeout |
| Wrong Answer | 答案错误, 执行程序得到的输出与标准输出不同 |
具体的错误信息可在对应的.log文件中查看。
- GCC Assembly Code
make gccasm
使用gcc编译器生成汇编代码。
- 清理:
make clean
清除所有可执行文件和测试输出。
make clean-test
清除所有测试输出。
make clean-app
清除编译器可执行文件。