Skip to content

This is the source code of my programming assignment of Principles and Techniques of Compiler courses (2020 Spring) at NJU.

Notifications You must be signed in to change notification settings

StardustDL/NJU-PTC-Lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

This is the source code of my programming assignment of Principles and Techniques of Compiler courses (2020 Spring) at NJU.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published