Introduction to the Tiger Project

Similar documents
A Set of Tools to Teach Compiler Construction

A Set of Tools to Teach Compiler Construction

CST-402(T): Language Processors

TWEAST: A Simple and Effective Technique to Implement Concrete-Syntax AST Rewriting Using Partial Parsing

Intermediate Representations

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Subprograms. Akim D le Étienne Renault Roland Levillain EPITA École Pour l Informatique et les Techniques Avancées

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

CPSC 411: Introduction to Compiler Construction

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Welcome to CSE131b: Compiler Construction

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Compiler Construction

General Course Information. Catalogue Description. Objectives

Undergraduate Compilers in a Day

Introduction (1) COMP 520: Compiler Design (4 credits) Alexander Krolik MWF 13:30-14:30, MD 279

Project Compiler. CS031 TA Help Session November 28, 2011

The Scanner and The Parser

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Who are we? Andre Platzer Out of town the first week GHC TAs Alex Crichton, senior in CS and ECE Ian Gillis, senior in CS

Compiler construction

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

List of Figures. About the Authors. Acknowledgments

Compilers and Interpreters

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

LECTURE 3. Compiler Phases

Compiling Techniques

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CS202 Compiler Construction. Christian Skalka. Course prerequisites. Solid programming skills a must.

Introduction to Compiler Construction

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

15-411/ Compiler Design

Introduction to Compiler Construction

INF5110 Compiler Construction

Introduction to Compilers and Language Design

Compiler Construction

The Structure of a Syntax-Directed Compiler

Front End. Hwansoo Han

CSE 401 Final Exam. December 16, 2010

Compilers Crash Course

LLVM code generation and implementation of nested functions for the SimpliC language

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Compilers and Code Optimization EDOARDO FUSELLA

Introduction. CS 2210 Compiler Design Wonsun Ahn

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Introduction to Java Programming

Compilers. Pierre Geurts

Chapter 2 A Quick Tour

Appendix A: Objectives and Courseware Locations

What do Compilers Produce?

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Semester Review CSC 301

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Principles of Programming Languages. Lecture Outline

Compilation I. Hwansoo Han

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

CS 415 Midterm Exam Spring 2002

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

Programming Languages FILS Andrei Vasilateanu

Why are there so many programming languages?

Appendix A The DL Language

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

CS A331 Programming Language Concepts

CSE 582 Autumn 2002 Exam 11/26/02

CS 415 Midterm Exam Spring SOLUTION

The Structure of a Compiler

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

Syntax-Directed Translation. Lecture 14

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Programming Languages, Summary CSC419; Odelia Schwartz

CSc 453 Interpreters & Interpretation

When do We Run a Compiler?

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

Lecture Notes on Compiler Design: Overview

EI326 ENGINEERING PRACTICE & TECHNICAL INNOVATION (III-G) Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

GUJARAT TECHNOLOGICAL UNIVERSITY

Intermediate Representations

Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery. Last modified: Mon Feb 23 10:05: CS164: Lecture #14 1

Pioneering Compiler Design

Development Tools. Akim D le Roland Levillain June 14, 2012

The Structure of a Syntax-Directed Compiler

COMPILERS AND INTERPRETERS Lesson 4 TDDD16

Programmiersprachen (Programming Languages)

Compiler Design (40-414)

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Generic Programming. Akim D le Étienne Renault Roland Levillain

CS 553 Compiler Construction Fall 2007 Project #1 Adding floats to MiniJava Due August 31, 2005

The Design and Implementation of Gnu Compiler Collection

Usually, target code is semantically equivalent to source code, but not always!

Formats of Translated Programs

TDDD55- Compilers and Interpreters Lesson 3

Compiler Construction

Principles of Compiler Design

Compiler Optimisation

Transcription:

Introduction to the Tiger Project Akim Demaille Étienne Renault Roland Levillain first.last@lrde.epita.fr EPITA École Pour l Informatique et les Techniques Avancées January 29th, 2018

Context and Motivation The Needs 19 years ago, EPITA asked for a long and challenging project. Should virtually be a potpourri of every subject from computer science courses taught in third year. A (Miraculous) Solution A compiler construction project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 2 / 34

Context and Motivation The Needs 19 years ago, EPITA asked for a long and challenging project. Should virtually be a potpourri of every subject from computer science courses taught in third year. A (Miraculous) Solution A compiler construction project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 2 / 34

Goals Aim Compiler construction as a by-product Complete Project Specifications, implementation, documentation, testing, distribution. Several iterations 5 (optionally up to 9) steps, for 3 (resp. up to 6) months. Algorithmically challenging Applied use of well known data structures and algorithms. Team Management Project conducted in group of three students. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 3 / 34

Goals Aim Compiler construction as a by-product Complete Project Specifications, implementation, documentation, testing, distribution. Several iterations 5 (optionally up to 9) steps, for 3 (resp. up to 6) months. Algorithmically challenging Applied use of well known data structures and algorithms. Team Management Project conducted in group of three students. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 3 / 34

Goals Aim Compiler construction as a by-product Complete Project Specifications, implementation, documentation, testing, distribution. Several iterations 5 (optionally up to 9) steps, for 3 (resp. up to 6) months. Algorithmically challenging Applied use of well known data structures and algorithms. Team Management Project conducted in group of three students. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 3 / 34

Goals Aim Compiler construction as a by-product Complete Project Specifications, implementation, documentation, testing, distribution. Several iterations 5 (optionally up to 9) steps, for 3 (resp. up to 6) months. Algorithmically challenging Applied use of well known data structures and algorithms. Team Management Project conducted in group of three students. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 3 / 34

Goals Aim Compiler construction as a by-product Complete Project Specifications, implementation, documentation, testing, distribution. Several iterations 5 (optionally up to 9) steps, for 3 (resp. up to 6) months. Algorithmically challenging Applied use of well known data structures and algorithms. Team Management Project conducted in group of three students. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 3 / 34

Goals (cont.) C++ Expressive power; uses both low- and high-level constructs; industry standard. Object-Oriented (OO) Design and Design Pattern (DP) Practice common OO idioms, apply DPs. Development Tools Autotools, Doxygen, Flex, Bison, GDB, Valgrind, Git, etc. Understanding Computers Compiler and languages are tightly related to computer architecture. English Everything is to be written in English (code, documentation, tests). A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 4 / 34

Goals (cont.) C++ Expressive power; uses both low- and high-level constructs; industry standard. Object-Oriented (OO) Design and Design Pattern (DP) Practice common OO idioms, apply DPs. Development Tools Autotools, Doxygen, Flex, Bison, GDB, Valgrind, Git, etc. Understanding Computers Compiler and languages are tightly related to computer architecture. English Everything is to be written in English (code, documentation, tests). A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 4 / 34

Goals (cont.) C++ Expressive power; uses both low- and high-level constructs; industry standard. Object-Oriented (OO) Design and Design Pattern (DP) Practice common OO idioms, apply DPs. Development Tools Autotools, Doxygen, Flex, Bison, GDB, Valgrind, Git, etc. Understanding Computers Compiler and languages are tightly related to computer architecture. English Everything is to be written in English (code, documentation, tests). A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 4 / 34

Goals (cont.) C++ Expressive power; uses both low- and high-level constructs; industry standard. Object-Oriented (OO) Design and Design Pattern (DP) Practice common OO idioms, apply DPs. Development Tools Autotools, Doxygen, Flex, Bison, GDB, Valgrind, Git, etc. Understanding Computers Compiler and languages are tightly related to computer architecture. English Everything is to be written in English (code, documentation, tests). A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 4 / 34

Goals (cont.) C++ Expressive power; uses both low- and high-level constructs; industry standard. Object-Oriented (OO) Design and Design Pattern (DP) Practice common OO idioms, apply DPs. Development Tools Autotools, Doxygen, Flex, Bison, GDB, Valgrind, Git, etc. Understanding Computers Compiler and languages are tightly related to computer architecture. English Everything is to be written in English (code, documentation, tests). A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 4 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Non Goal Writing a Compiler Paradoxically! Well, at least considered a secondary issue. Why? The vast majority of [Computer Science] students are unlikely to ever design a compiler [Debray, 2002]. But... Students interested in compiler construction should be given the opportunity to work on challenging, optional assignments. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 5 / 34

Introduction to the Tiger Project 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 6 / 34

Overview of the Tiger Project 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 7 / 34

A Core-Curriculum Compiler-Construction Project Based on Andrew Appel s Tiger language and Modern Compiler Implementation books [Appel, 1998]. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 8 / 34

A Core-Curriculum Compiler-Construction Project (cont.)...and largely adapted [Demaille, 2005]. Compiler (to be) written in C++. Initial Tiger language definition (a Pascal-descendant language, dressed in a clean ML-like syntax). Augmented with import statements, adjustable prelude, OO constructs, etc. Better defined (no implementation-defined behavior left). More compiler modules and features than in the initial design. In particular more tools to both help students develop and improve their compiler and make the maintenance easier to teachers and assistants. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 9 / 34

A Core-Curriculum Compiler-Construction Project (cont.)...and largely adapted [Demaille, 2005]. Compiler (to be) written in C++. Initial Tiger language definition (a Pascal-descendant language, dressed in a clean ML-like syntax). Augmented with import statements, adjustable prelude, OO constructs, etc. Better defined (no implementation-defined behavior left). More compiler modules and features than in the initial design. In particular more tools to both help students develop and improve their compiler and make the maintenance easier to teachers and assistants. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 9 / 34

A Core-Curriculum Compiler-Construction Project (cont.)...and largely adapted [Demaille, 2005]. Compiler (to be) written in C++. Initial Tiger language definition (a Pascal-descendant language, dressed in a clean ML-like syntax). Augmented with import statements, adjustable prelude, OO constructs, etc. Better defined (no implementation-defined behavior left). More compiler modules and features than in the initial design. In particular more tools to both help students develop and improve their compiler and make the maintenance easier to teachers and assistants. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 9 / 34

A Core-Curriculum Compiler-Construction Project (cont.)...and largely adapted [Demaille, 2005]. Compiler (to be) written in C++. Initial Tiger language definition (a Pascal-descendant language, dressed in a clean ML-like syntax). Augmented with import statements, adjustable prelude, OO constructs, etc. Better defined (no implementation-defined behavior left). More compiler modules and features than in the initial design. In particular more tools to both help students develop and improve their compiler and make the maintenance easier to teachers and assistants. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 9 / 34

Project s Modus Operandi The compiler is designed as a long pipe composed of several modules. The project is divided in several steps, where students have to implement one (or two) module(s). Code with gaps. Work is evaluated by a program at each delivery. Students defend their work every two steps in front of a teaching assistant. Several optional assignments are given as extra modules. Motivated students can choose to proceed with the implementation of the back-end of the compiler. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 10 / 34

Project s Modus Operandi The compiler is designed as a long pipe composed of several modules. The project is divided in several steps, where students have to implement one (or two) module(s). Code with gaps. Work is evaluated by a program at each delivery. Students defend their work every two steps in front of a teaching assistant. Several optional assignments are given as extra modules. Motivated students can choose to proceed with the implementation of the back-end of the compiler. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 10 / 34

Project s Modus Operandi The compiler is designed as a long pipe composed of several modules. The project is divided in several steps, where students have to implement one (or two) module(s). Code with gaps. Work is evaluated by a program at each delivery. Students defend their work every two steps in front of a teaching assistant. Several optional assignments are given as extra modules. Motivated students can choose to proceed with the implementation of the back-end of the compiler. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 10 / 34

Project s Modus Operandi The compiler is designed as a long pipe composed of several modules. The project is divided in several steps, where students have to implement one (or two) module(s). Code with gaps. Work is evaluated by a program at each delivery. Students defend their work every two steps in front of a teaching assistant. Several optional assignments are given as extra modules. Motivated students can choose to proceed with the implementation of the back-end of the compiler. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 10 / 34

Figures 19 years of existence. 300 students per year (on average). Project done in groups of 3 students. 6 mandatory steps (compiler front-end). 4 optional steps (compiler back-end). Reference compiler: 25KLOC. Students are expected to write about 5500 lines (or about 7000 lines, with the optional assignments). 250+ pages of documentation (reference manual [Demaille and Levillain, 2007b] and project assignments [Demaille and Levillain, 2007a]). 3 papers in international conferences [Demaille, 2005, Demaille et al., 2008, Demaille et al., 2009]. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 11 / 34

History I 2000 Beginning of the Tiger Project: a front-end, a single teacher, no assistant. 2001 Have students learn and use the Autotools for project maintenance. 2002 Teaching Assistants involved in the project. Interpreter for the Intermediate Representation (IR) language (HAVM). 2003 Addition of a MIPS back-end, partly from the work of motivated students. Interpreter for the MIPS language (Nolimips). The structures of the Abstract Syntax Tree (AST) and a visitor are generated from a description file. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 12 / 34

History II 2005 A second teacher in the project maintenance and supervision. First uses of some Boost libraries (Boost.Variant, Boost Graph Library (BGL), Smart Pointers). First use of concrete-syntax program transformations (code generation) using TWEASTs 2007 Tiger becomes an Object-Oriented Language (OOL). 2009 C++ objects on the parser stack. 2011 Extension of Bison s grammar to handle named parameters. 2012 Conversion of tc to C++11. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 13 / 34

History (2) I 2014 Code with gap now compile. 2015 Even more C++11/C++14, aiming at C++17. OO is now optional. Much simpler/faster build system. Support form ARM backend. 2016 Support for LLVM intermediate langage. 2017 Move to C++17. Introduce Dockerfile. 2018 Refactoring python bindings for jupyter-notebooks. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 14 / 34

Practical information 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 15 / 34

Entry Points Home page of the project: http://tiger.lrde.epita.fr Resources for the project: http://www.lrde.epita.fr/~tiger news.epita.fr newsgroup: cours.ccmp A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 16 / 34

Reference Documents Tiger Compiler Project Assignments: www.lrde.epita.fr/~tiger/assignments.html www.lrde.epita.fr/~tiger/assignments.split www.lrde.epita.fr/~tiger/assignments.pdf www.lrde.epita.fr/~tiger/assignments.info www.lrde.epita.fr/~tiger/assignments.txt Tiger Compiler Reference Manual (TCRM): www.lrde.epita.fr/~tiger/tiger.html www.lrde.epita.fr/~tiger/tiger.split www.lrde.epita.fr/~tiger/tiger.pdf www.lrde.epita.fr/~tiger/tiger.info www.lrde.epita.fr/~tiger/tiger.txt A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 17 / 34

Lectures notes Slides (like these ones): http: //www.lrde.epita.fr/~tiger/lecture-notes/slides/ Subdirectories: ccmp/ CCMP lecture notes tc/ TC-n presentations, given by the Assistants tyla/ TYLA lecture notes A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 18 / 34

Other Useful Resources Doxygen Documentation: http://www.lrde.epita.fr/~tiger/tc-doc/ Past exams: http://www.lrde.epita.fr/~tiger/exams/ Some artwork from previous classes: http://www.lrde.epita.fr/~tiger/humor/ A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 19 / 34

Rules of the Game 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 20 / 34

Nul n est censé ignorer la loi. www.lrde.epita.fr/~tiger/assignments.html 1 No copy between groups. 2 Tests are part of the project (test cases and frameworks should not be exchanged). 3 Fixing mistakes earlier is better (and less expensive). 4 Work between groups is encouraged! As long as they don t cheat. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 21 / 34

Nul n est censé ignorer la loi. www.lrde.epita.fr/~tiger/assignments.html 1 No copy between groups. 2 Tests are part of the project (test cases and frameworks should not be exchanged). 3 Fixing mistakes earlier is better (and less expensive). 4 Work between groups is encouraged! As long as they don t cheat. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 21 / 34

Nul n est censé ignorer la loi. www.lrde.epita.fr/~tiger/assignments.html 1 No copy between groups. 2 Tests are part of the project (test cases and frameworks should not be exchanged). 3 Fixing mistakes earlier is better (and less expensive). 4 Work between groups is encouraged! As long as they don t cheat. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 21 / 34

Nul n est censé ignorer la loi. www.lrde.epita.fr/~tiger/assignments.html 1 No copy between groups. 2 Tests are part of the project (test cases and frameworks should not be exchanged). 3 Fixing mistakes earlier is better (and less expensive). 4 Work between groups is encouraged! As long as they don t cheat. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 21 / 34

The Tiger Compiler 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 22 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? cpp (preprocessor) A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? cpp (preprocessor) cc1 (actual C compiler) A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? cpp (preprocessor) cc1 (actual C compiler) as (assembler) A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? cpp (preprocessor) cc1 (actual C compiler) as (assembler) ld (linker) A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

The C Compilation Model Which (coarse-grained) steps can we find in gcc? cpp (preprocessor) cc1 (actual C compiler) as (assembler) ld (linker) A pipe. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 23 / 34

tc: A Compiler as A Long Pipe scan.l parse.y ast.yml chars Flex Scan tokens Bison Parse AST AstGen Bind bound AST Type bound and typed AST mips.brg Translate MonoBURG asm Reg. alloc. IG Liveness an. Instr. sel. LIR Canon HIR Nolimips pre-asm HAVM generator input generator hand-written module interpreter generated module A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 24 / 34

tc: A Compiler as A Long Pipe scan.l parse.y ast.yml chars Flex Scan tokens Bison Parse AST AstGen Bind bound AST Type bound and typed AST mips.brg Translate MonoBURG asm Reg. alloc. IG Liveness an. Instr. sel. LIR Canon HIR Nolimips pre-asm HAVM generator input generator hand-written module interpreter generated module A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 24 / 34

tc: A Compiler as A Long Pipe scan.l parse.y ast.yml chars Flex Scan tokens Bison Parse AST AstGen Bind bound AST Type bound and typed AST mips.brg Translate MonoBURG asm Reg. alloc. IG Liveness an. Instr. sel. LIR Canon HIR Nolimips pre-asm HAVM generator input generator hand-written module interpreter generated module A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 24 / 34

Other Compiling Strategies Intermediate language-based strategy: SmartEiffel, GHC Bytecode strategy: Java bytecode (JVM), CIL (.NET) Hybrid approaches: GCJ (Java bytecode or native code) Retargetable optimizing back ends: MLRISC, VPO (Very Portable Optimizer), and somehow C- - (Quick C- -). Modular systems: LLVM (compiler as a library, centered on a typed IR). Contains the LLVM core libraries, Clang, LLDB, etc. Also: VMKit: a substrate for virtual machines (JVM, etc.). Emscripten: an LLVM-to-JavaScript compiler. Enables C/C++ to JS compilation. Intermediate Representations (IR) are fundamental. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 25 / 34

The Tiger Language 1 Overview of the Tiger Project 2 Practical information 3 Rules of the Game 4 The Tiger Compiler 5 The Tiger Language A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 26 / 34

Two flavors Appel s Defined in Modern Compiler Implementation books (see the Appendix). Ours Defined in the Tiger Compiler Reference Manual (TCRM). Features many extensions: import keyword, overloading, OOP,... Implemented by LRDE s reference compiler. This is the target language for your project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 27 / 34

Two flavors Appel s Defined in Modern Compiler Implementation books (see the Appendix). Ours Defined in the Tiger Compiler Reference Manual (TCRM). Features many extensions: import keyword, overloading, OOP,... Implemented by LRDE s reference compiler. This is the target language for your project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 27 / 34

Two flavors Appel s Defined in Modern Compiler Implementation books (see the Appendix). Ours Defined in the Tiger Compiler Reference Manual (TCRM). Features many extensions: import keyword, overloading, OOP,... Implemented by LRDE s reference compiler. This is the target language for your project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 27 / 34

Two flavors Appel s Defined in Modern Compiler Implementation books (see the Appendix). Ours Defined in the Tiger Compiler Reference Manual (TCRM). Features many extensions: import keyword, overloading, OOP,... Implemented by LRDE s reference compiler. This is the target language for your project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 27 / 34

Two flavors Appel s Defined in Modern Compiler Implementation books (see the Appendix). Ours Defined in the Tiger Compiler Reference Manual (TCRM). Features many extensions: import keyword, overloading, OOP,... Implemented by LRDE s reference compiler. This is the target language for your project. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 27 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Tiger Toy language (not industry-proof)...... but still effective. Imperative language, descendant of Algol. Functional flavour. a := if 1 then 2 else 3 function incr(x : int) : int = x + 1 Simple and sound grammar. Well defined semantics. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 28 / 34

Your first Tiger Program print("hello World!\n") A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 29 / 34

Your second Tiger program let function hello(name : string) = print(concat("hello ", name)) in hello("you"); print("\n") end A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 30 / 34

The classic Factorial function let /* Compute n! */ function fact(n : int) : int = if n = 0 then 1 else n * fact(n - 1) in print_int(fact(10)); print("\n") end A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 31 / 34

Bibliography I Appel, A. W. (1998). Modern Compiler Implementation in C, Java, ML. Cambridge University Press. Debray, S. (2002). Making compiler design relevant for students who will (most likely) never design a compiler. In Proceedings of the 33rd SIGCSE technical symposium on Computer science education, pages 341 345. ACM Press. Demaille, A. (2005). Making compiler construction projects relevant to core curriculums. In Proceedings of the Tenth Annual Conference on Innovation and Technology in Computer Science Education (ITICSE 05), pages 266 270, Universidade Nova de Lisboa, Monte da Pacarita, Portugal. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 32 / 34

Bibliography II Demaille, A. and Levillain, R. (2007a). The Tiger Compiler Project Assignment. EPITA Research and Development Laboratory (LRDE), 14-16 rue Voltaire, FR-94270 Le Kremlin-Bicêtre, France. http://www.lrde.epita.fr/~akim/ccmp/assignments.pdf. Demaille, A. and Levillain, R. (2007b). The Tiger Compiler Reference Manual. EPITA Research and Development Laboratory (LRDE), 14-16 rue Voltaire, FR-94270 Le Kremlin-Bicêtre, France. http://www.lrde.epita.fr/~akim/ccmp/tiger.pdf. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 33 / 34

Bibliography III Demaille, A., Levillain, R., and Perrot, B. (2008). A set of tools to teach compiler construction. In Proceedings of the Thirteenth Annual Conference on Innovation and Technology in Computer Science Education (ITICSE 08), pages 68 72, Universidad Politécnica de Madrid, Spain. Demaille, A., Levillain, R., and Sigoure, B. (2009). TWEAST: A simple and effective technique to implement concrete-syntax AST rewriting using partial parsing. In Proceedings of the 24th Annual ACM Symposium on Applied Computing (SAC 09), pages 1924 1929, Waikiki Beach, Honolulu, Hawaii, USA. A. Demaille, E. Renault, R. Levillain Introduction to the Tiger Project 34 / 34