27
Project: ACM Compiler 2014 Shanghai Jiao Tong University Class ACM 2011 Dong Xie

Project: ACM Compiler 2014

  • Upload
    norman

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

Project: ACM Compiler 2014. Shanghai Jiao Tong University Class ACM 2011 Dong Xie. Introduction. Introduction. Task: Write a compiler of simplified C in full-featured Java to MIPS . Main Reference Book: Compilers Principles Techniques and Tools You may also need more materials: - PowerPoint PPT Presentation

Citation preview

Page 1: Project: ACM Compiler 2014

Project: ACM Compiler 2014

Shanghai Jiao Tong UniversityClass ACM 2011

Dong Xie

Page 2: Project: ACM Compiler 2014

Introduction

Page 3: Project: ACM Compiler 2014

Introduction Task: Write a compiler of simplified C in full-featured Java to

MIPS.

Main Reference Book: Compilers Principles Techniques and Tools

You may also need more materials: Modern Compiler Implementation in Java/C/ML MIPS-SPIM document All kinds of papers …

Page 4: Project: ACM Compiler 2014

Introduction You are allowed to use a language other than Java

Whoever bootstrapping C will get a full score NO bonus needed for other language BUT you may not have a good support from your TAs.

Apply it explicitly to TAs if you want to do this.

Page 5: Project: ACM Compiler 2014

TA List 贺天行 cloudygooseg [at] gmail.com 解东 xiedong1993 [at] gmail.com 吴航 wuzhongminghang [at] gmail.com 金天行 121665841 [at] qq.com

Google Groups: tiger-acm-sjtu [at] googlegroups.com IMPORTANT Be sure you have join this group.

Page 6: Project: ACM Compiler 2014

Schedule & Principles Lecture: every Friday 7 PM at SEIEE Building 3-404 Project Checkpoint Due: on some Friday 6 PM There will be TWO code reviews during the project

NO CHEATING NO LATE SUBMISSION

All test cases will be publicly available.

Page 7: Project: ACM Compiler 2014

Versioning & Submission Version your compiler codes using BitBucket. You are NOT allowed to publish your code on the Internet

Create a private repo named compiler2014 Add username acmcompiler to your repository with read

permission

Submit your code for each phase by creating a tag.

Page 8: Project: ACM Compiler 2014

Grading Data Correctness (60 points) Performance (20 points) Code review (5 points) Attendance (5 points) Bonus

Report Mail list Summary Helper Book Reader Performance Winners

Page 9: Project: ACM Compiler 2014

Possible Bonus List Use C language to implement the compiler. Implement typedef Implement higher order functions. (lambda expression, etc.) Static analyzer (abstract interpreter) Garbage collection (If you pass our testcases, you can get this

bonus.) Optimization (loop-unrolling, constants propagation, inline

functions, dead code elimination, etc.) Concurrency and scheduling Reconstruct the AST ...

Page 10: Project: ACM Compiler 2014

Q & A

Page 11: Project: ACM Compiler 2014

Compiler Overview

Page 12: Project: ACM Compiler 2014

Compilers vs. Interpreters Compilers:

Interpreters:

Page 13: Project: ACM Compiler 2014

Compiler Phases Syntactic Analysis (Lexing, Parsing) Semantic Analysis (Types, Scopes, …) Intermediate Representation (IR) Optimization (CPU, Registers, Memory, …) Code Generation

Difference between compilers and interpreters?

Page 14: Project: ACM Compiler 2014

Example int a = 1; print(a); int b = “hello” print(b)

When will a compiler and a interpreter raise the error.

Page 15: Project: ACM Compiler 2014

Compiler Phases

Page 16: Project: ACM Compiler 2014

Example a = b + 42

ID(a) OP(=) ID(b) OP(+) NUM(42)

Page 17: Project: ACM Compiler 2014

Example t3 := t1 + 42 t2 := t3

lw $t1, -8($fp) addi $t2, $t1, 42 sw $t2, -4($fp)

Page 18: Project: ACM Compiler 2014

An Appetizer A toy compiler as a tutorial written by Xiao Jia Notice: you may not find IR phase in it. You will find it VERY IMPORTANT if you have no idea to start.

Description: http://acm.sjtu.edu.cn/wiki/Compiler_2014:_An_appetizer

Source Code: https://github.com/stfairy/appetizer

Page 19: Project: ACM Compiler 2014

Q & A

Page 20: Project: ACM Compiler 2014

Phase 1: Syntactic Analysis

Page 21: Project: ACM Compiler 2014

Example: Input

#include <stdio.h>

int main(int argc) {

printf(“Hello World!\n”);

return 0

}

Page 22: Project: ACM Compiler 2014

Task 1: Tokenlizeint

<id, main>

(

int <id, argc>

)

{

<id, printf>

(

<string, “Hello World!\n”>

)

;

return

<number, 0>

;

}

Page 23: Project: ACM Compiler 2014

Task 2: Parsering(func int main[(arg int argc)])

(stmtlist

(expr (call printf[“Hello World!\n”]))

(stmtlist

(return (number 0))))

Note: you need to print out a AST NOT a Parser Tree.

Page 25: Project: ACM Compiler 2014

Tools & Grading Following tools are allowed:

lex / yacc / Quex / flex / bison re2c / lemon Jflex / CUP ANTLR (v3 or v4) Ragel

This phase will be manually judged in code review. Feel free to design your own output formats!

Page 26: Project: ACM Compiler 2014

Q & A

Page 27: Project: ACM Compiler 2014

Thanks for listening…Contact: [email protected]