Giter Site home page Giter Site logo

tinsir888 / compiler-sysy Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 2.0 6.99 MB

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.

Makefile 1.37% C++ 88.33% Lex 3.17% Yacc 4.25% Java 1.28% C 1.60%
yacc-lex bison-yacc sysy parser

compiler-sysy's Introduction

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

清除编译器可执行文件。

compiler-sysy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.