Skip to content

Emanual20/2021NKUCS-Compilers-Lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2021Fall NKUCS Course - Principle of Compilers

Lab7: Machine Code Generation

Author: Emanual20 YoungCoder feilll

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

Framework for Experiments of Course "the Principle of Compilers", NKUCS 2021fall

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published