Course introduction. Advanced Compiler Construction Michel Schinz

Similar documents
COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

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

CS453 Compiler Construction

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

Running class Timing on Java HotSpot VM, 1

Compilers. Computer Science 431

CS 360 Programming Languages Interpreters

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

LECTURE 2. Compilers and Interpreters

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

Compiling Regular Expressions COMP360

General Course Information. Catalogue Description. Objectives

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

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

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

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Compiler construction 2009

Compiler Construction

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Undergraduate Compilers in a Day

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

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

COMPILER DESIGN. For COMPUTER SCIENCE

Structure of Programming Languages Lecture 10

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Spring 2015

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

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

Compilers and Interpreters

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

HOLY ANGEL UNIVERSITY COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY COMPILER THEORY COURSE SYLLABUS

History of Compilers The term

CS 406/534 Compiler Construction Putting It All Together

Principles of Compiler Construction ( )

Working of the Compilers

What do Compilers Produce?

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Time : 1 Hour Max Marks : 30

COSE312: Compilers. Lecture 1 Overview of Compilers

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

Compilers. Lecture 2 Overview. (original slides by Sam

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

When do We Run a Compiler?

The Structure of a Syntax-Directed Compiler

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

G Programming Languages - Fall 2012

Compiler Design (40-414)

CS 415 Midterm Exam Spring SOLUTION

Compilers and Code Optimization EDOARDO FUSELLA

CS 415 Midterm Exam Fall 2003

Principles of Compiler Construction ( )

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

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

Compiler Design Spring 2018

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Interpreters. Prof. Clarkson Fall Today s music: Step by Step by New Kids on the Block

CS153: Compilers Lecture 1: Introduction

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures


About this exam review

DCS/100: Procedural Programming

Winter Compiler Construction Who. Mailing list and forum

CS 415 Midterm Exam Spring 2002

Compiler Code Generation COMP360

CS558 Programming Languages

Advanced Programming & C++ Language

Compilers Crash Course

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Compiler Construction D7011E

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

Formats of Translated Programs

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

Compiler Construction LECTURE # 1

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

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

Introduction to Asynchronous Programming Fall 2014

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

CS558 Programming Languages

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

Compiling Techniques

Programming Languages Third Edition. Chapter 7 Basic Semantics

Outline. When we last saw our heros. Language Issues. Announcements: Selecting a Language FORTRAN C MATLAB Java

Compiler Structure. Lexical. Scanning/ Screening. Analysis. Syntax. Parsing. Analysis. Semantic. Context Analysis. Analysis.

LECTURE 3. Compiler Phases

Programming Language Implementation

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL

CSE 401/M501 Compilers

Compiler Construction

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

4. An interpreter is a program that

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

Semantic Analysis. Compiler Architecture

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

CS558 Programming Languages

Compilers. History of Compilers. A compiler allows programmers to ignore the machine-dependent details of programming.

CA Compiler Construction

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Transcription:

Course introduction Advanced Compiler Construction Michel Schinz 2016 02 25

General information

Course goals The goal of this course is to teach you: how to compile high-level functional and objectoriented programming languages, how to optimize the generated code, and how to support code execution at run time. To achieve these goals, the course is roughly split in three parts of unequal length: a part covering the compilation of high-level concepts (e.g. closures), a part covering intermediate languages and optimizations, a part covering virtual machines and garbage collection.

Prerequisite skills To complete the project successfully, you need: excellent knowledge of functional programming in Scala, good knowledge of (relatively) low-level programming in C. Beware: acquiring these skills during the course can be challenging.

Evaluation The grade will be based on three aspects: several group projects, to be completed in groups of at most two people, one or more (depending on class size) individual projects, to be completed alone, an individual oral exam. Note: the course is evaluated during the semester, which has two important consequences: 1. there is no retake exam, 2. the oral exam will take place during the last week of the semester, not during the official exam period.

Grading scheme The final grade will be based on your results in: the various project parts, spread over 11 weeks, which contribute to 80% of the grade, the final exam, which contributes to 20% of the grade.

Resources Lecturer: Michel Schinz Assistants: Dmitry Petrashko Manos Koukoutos Web page: lamp.epfl.ch/teaching/advanced_compiler Forum: piazza.com/epfl.ch/spring2016/cs420/home

Course overview

What is a compiler? Your current view of a compiler must be something like this: Lexical analysis Syntactical analysis Name & type analysis Code generation Scanner Parser Analyzer Generator Character stream Token stream Tree Attributed tree Executable code

What is a compiler, really? Real compilers are often more complicated multiple simplification and optimization phases Scanner Parser Analyzer Generator sophisticated run time system

Additional phases Simplification (or lowering) phases transform the program so that complex concepts of the language pattern matching, anonymous functions, etc. are translated using simpler ones. Optimization phases transform the program so that it hopefully makes better use of some resource e.g. CPU cycles, memory, etc. Of course, all these phases must preserve the meaning of the original program!

Simplification phases Example of a simplification phase: Java compilers have a phase that transforms nested classes to top-level ones. class Out { void f1() { } class In { void f2() { f1(); } } } class Out { void f1() { } } class Out$In { final Out this$0; Out$In(Out o) { this$0 = o; } void f2() { this$0.f1(); } }

Optimization phases Example of an optimization phase: Java compilers optimize expressions involving constant values. That includes removing dead code, i.e. code that can never be executed. class C { public final static boolean debug =!true; int f() { if (debug) { System.out.println("C.f() called"); } return 10; } }

Optimization phases Example of an optimization phase: Java compilers optimize expressions involving constant values. That includes removing dead code, i.e. code that can never be executed. class C { public final static boolean debug =!true; int f() { if (debug) { System.out.println("C.f() called"); } return 10; } dead code, } removed during compilation

Intermediate representations To manipulate the program, simplification and optimization phases must represent it in some way. One possibility is to use the representation produced by the parser the abstract syntax tree (AST). The AST is perfectly suited to certain tasks, but other intermediate representations (IR) exist and are more appropriate in some situations.

Run time system Implementing a high-level programming language usually means more than just writing a compiler. A complete run time system must be written, to provide various services to executing programs, like: code loading and linking, code interpretation, compilation and optimization, memory management (garbage collection), concurrency, etc. This is quite a lot, and modern Java Virtual Machines, for example, are more complex than Java compilers!

Memory management Most modern programming languages offer automatic memory management: the programmer allocates memory explicitly, but deallocation is performed automatically. The deallocation of memory is usually performed by a part of the run time system called the garbage collector (GC). A garbage collector periodically frees all memory that has been allocated by the program but is not reachable anymore.

Virtual machines Instead of targeting a real processor, a compiler can target a virtual one, usually called a virtual machine (VM). The produced code is then interpreted by a program emulating the virtual machine. Virtual machines have many advantages: the compiler can target a single architecture, the program can easily be monitored during execution, e.g. to prevent malicious behavior, or provide debugging facilities, the distribution of compiled code is easier. The main (only?) disadvantage of virtual machines is their speed: it is always slower to interpret a program in software than to execute it directly in hardware.

Dynamic (JIT) compilation To make virtual machines faster, dynamic, or just-in-time (JIT) compilation was invented. The idea is simple: Instead of interpreting a piece of code, the virtual machine translates it to machine code, and hands that code to the processor for execution. This is usually faster than interpretation.

Summary Compilers for high-level languages are more complex than the ones you ve studied, since: they must translate high-level concepts like patternmatching, anonymous functions, etc. to lower-level equivalents, they must be accompanied by a sophisticated run time system, and they should produce optimized code. This course will be focused on these aspects of compilers and run time systems.