1 / 27

Project: ACM Compiler 2014

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:

norman
Download Presentation

Project: ACM Compiler 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Introduction

  3. 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 • …

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

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

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

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

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

  9. 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 • ...

  10. Q & A

  11. Compiler Overview

  12. Compilers vs. Interpreters • Compilers: • Interpreters:

  13. Compiler Phases • Syntactic Analysis (Lexing, Parsing) • Semantic Analysis (Types, Scopes, …) • Intermediate Representation (IR) • Optimization (CPU, Registers, Memory, …) • Code Generation • Difference between compilers and interpreters?

  14. Example • int a = 1; • print(a); • int b = “hello” • print(b) • When will a compiler and a interpreter raise the error.

  15. Compiler Phases

  16. Example • a = b + 42 • ID(a) OP(=) ID(b) OP(+) NUM(42)

  17. Example • t3 := t1 + 42 • t2 := t3 • lw $t1, -8($fp) • addi $t2, $t1, 42 • sw $t2, -4($fp)

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

  19. Q & A

  20. Phase 1: Syntactic Analysis

  21. Example: Input #include <stdio.h> int main(intargc) { printf(“Hello World!\n”); return 0 }

  22. Task 1: Tokenlize <string, “Hello World!\n”> ) ; return <number, 0> ; } int <id, main> ( int <id, argc> ) { <id, printf> (

  23. Task 2: Parsering (funcint main[(argintargc)]) (stmtlist (expr (callprintf[“Hello World!\n”])) (stmtlist (return (number 0)))) • Note: you need to print out a AST NOT a Parser Tree.

  24. Syntactic Specification • Tokens: http://acm.sjtu.edu.cn/wiki/Compiler_2014:_Tokens • Grammar: http://acm.sjtu.edu.cn/wiki/Compiler_2014:_Grammar

  25. 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!

  26. Q & A

  27. Thanks for listening… Contact: xiedong1993@gmail.com

More Related