Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
/ compiler-sysy Public archive

NKU CS major compulsory course in 5th semester, taught by Prof. Wang Gang. Finish a compiler of language SysY(A subset of language C), by using auxiliary tools bison and yacc. It is widely regarded as the most difficult compulsory course in computer science.

Notifications You must be signed in to change notification settings

tinsir888/compiler-sysy

Repository files navigation

Machine Code Generation

2021Fall NKUCS Course - Principle of Compilers

Date: 2021/11/28

编译器命令

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

Makefile使用

  • 修改测试路径:

默认测试路径为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

清除编译器可执行文件。

About

NKU CS major compulsory course in 5th semester, taught by Prof. Wang Gang. Finish a compiler of language SysY(A subset of language C), by using auxiliary tools bison and yacc. It is widely regarded as the most difficult compulsory course in computer science.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published