Git Product home page Git Product logo

nju-ptc-lab's Introduction

NJU PTC Lab

CI

A compiler of C--, a C-like programming language introduced for the compiler lesson in Nanjing University.

  • This is the source codes of my programming assignment of Principles and Techniques of Compiler courses (2020 Spring).
  • Each push (or pull request) will be tested, goto Actions for details.
  • There are still some bugs, but won't be fixed for now.

Sources

The main workflow is

CMM source -> Lexical -> Syntax -> Semantics -> IR -> Assembly
File Description
main.c Entry point
lexical.h, lexical.l, _lexical.c Lexical
syntax.h, syntax.y, _syntax.c Syntax
semantics.h, semantics.c Semantics
ir.h, ir.c IR code
asm.h, asm.c Assembly code

There are some helper functions, macros and structs in other files.

File Description
common.h Shared header
debug.h Debugging
hash.h, hash.c Hasher
object.h, object.c Object creating and destroying, wrapper for malloc/free
list.h, list.c Linked-list
type.h, type.c Types in CMM language
symbol.h, symbol.c Symbol and symbol table
ast.h, ast.c Syntax tree and IR code
optimize.h, optimize.c Optimizer for IR code

Build

Environment:

  • OS: Ubuntu 16.04 or 18.04
  • Compiler: gcc 7.5
  • Flex: 2.6
  • Bison: 3.0
  • Spim

Instructions:

  1. Install dependencies:
apt-get install bison flex build-essential spim
  1. Build project:
cd src && make

Run

Lexical

Check lexical analysis.

./src/ncc a.cmm --lexcial

Syntax

Parse source codes into syntax tree.

./src/ncc a.cmm --syntax

Semantics

Check semantics analysis.

./src/ncc a.cmm --semantics

IR

Translate source codes to intermediate codes.

# output to stdout
./src/ncc a.cmm --ir

# output to file
./src/ncc a.cmm a.ir --ir

Assembly

Generate MIPS-32 assembly codes.

# output to stdout
./src/ncc a.cmm

# output to file
./src/ncc a.cmm a.s

Test

cd test && ./testall.sh

Thanks & Related projects

nju-ptc-lab's People

Contributors

stardustdl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

joejiong shuhaohe

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.