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

Similar documents
15-411/ Compiler Design

Lecture Notes on Compiler Design: Overview

CS153: Compilers Lecture 1: Introduction

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

COMP 105 Homework: Type Systems

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

CS457/557 Functional Languages

General Course Information. Catalogue Description. Objectives

Compilers for Modern Architectures Course Syllabus, Spring 2015

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

15-213/18-213/15-513, Fall 2017 C Programming Lab: Assessing Your C Programming Skills

Lecture Notes on Intermediate Representation

Compiler Design Spring 2018

Computer Science 210: Data Structures

Languages and Compilers

ECE573 Introduction to Compilers & Translators

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

CS4120/4121/5120/5121 Spring /6 Programming Assignment 4

CS 152 Computer Architecture and Engineering Lecture 1 Single Cycle Design

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

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

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

Please put your cellphone on vibrate

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

COMP 117: Internet-scale Distributed Systems Lessons from the World Wide Web

Programming Project 4: COOL Code Generation

Project Compiler. CS031 TA Help Session November 28, 2011

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Course introduction. Advanced Compiler Construction Michel Schinz

Introduction to LLVM. UG3 Compiling Techniques Autumn 2018

Introduction to Computer Systems

CPSC 213. Introduction to Computer Systems. Introduction. Unit 0

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

Mathematical Logic Part One

Important Project Dates

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Review! Lecture 5 C Memory Management !

CS61C : Machine Structures

15-213/18-213/15-513, Spring 2018 C Programming Lab: Assessing Your C Programming Skills

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator

Welcome to CSE131b: Compiler Construction

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

378: Machine Organization and Assembly Language

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

Compiler Design: Lab 3 Fall 2009

CS 241 Data Organization. August 21, 2018

Welcome to Solving Problems with Computers I

Course Overview CSCE 312. Instructor: Daniel A. Jiménez. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

CS61C : Machine Structures

Introduction to Computer Systems

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

Boot Camp. Dave Eckhardt Bruce Maggs

While waiting for the lecture to begin, please complete. the initial course questionnaire.

COSE212: Programming Languages. Lecture 0 Course Overview

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

Menu. Class 1: Introduction. Staff. Course Structure and Expectations. Contacting Us. Contacting You

Announcements. Written Assignment 2 due today at 5:00PM. Programming Project 2 due Friday at 11:59PM. Please contact us with questions!

6.035 Project 3: Unoptimized Code Generation. Jason Ansel MIT - CSAIL

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

CS 241 Data Organization using C

CS 6371: Advanced Programming Languages

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

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

CS 3304 Comparative Languages. Lecture 1: Introduction

CS 520 Theory and Practice of Software Engineering Fall 2018

CS 3110 Lecture 1 Course Overview

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

IR Generation. May 13, Monday, May 13, 13

CS243 Homework 2. Winter Due: January 31, 2018

Overview of the ECE Computer Software Curriculum. David O Hallaron Associate Professor of ECE and CS Carnegie Mellon University

CS 406/534 Compiler Construction Putting It All Together

Languages and Automata

CSci 5103 Operating Systems. Jon Weissman. Administrivia

Introduction to Data Structures

CISC 124: Introduction To Computing Science II

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

18-600: Recitation #3

Introduction to Computer Systems

COMP 2150 CS 2: Object-Oriented Programming and Data Structure Fall 2018 Dr. James Yu

: Principles of Imperative Computation. Summer Assignment 4. Due: Monday, June 11, 2012 in class

CSci Introduction to Operating Systems. Administrivia, Intro

CSCE-608 Database Systems. COURSE PROJECT #2 (Due December 5, 2018)

Chris Riesbeck, Fall Introduction to Computer Systems

Introduction to Security

Introduction to Computer Systems

Verification and Parallelism in Intro CS. Dan Licata Wesleyan University

Review! * follows a pointer to its value! & gets the address of a variable! Pearce, Summer 2010 UCB! ! int x = 1000; Pearce, Summer 2010 UCB!

Lab 4 - Linked Lists

Three-Address Code IR

Announcements. Course Staff. Course Staff. Lectures 10/19/11. CS/ENGRD 2110 Fall Instructor. Administrative Assistant

CS61C : Machine Structures

More C Pointer Dangers

Worksheet #4. Foundations of Programming Languages, WS 2014/15. December 4, 2014

Decaf PP2: Syntax Analysis

Programming Languages and Compilers (CS 421)

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

The role of semantic analysis in a compiler

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

Transcription:

15-411 Compilers

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

Logistics symbolaris.com/course/compiler12.html symbolaris.com -> Teaching -> Compiler 12 autolab.cs.cmu.edu/15411-f12 Lectures Tues/Thurs 1:30-2:50pm GHC 4211 Recitations - none! Office Hours More coming soon...

Contact us 15411@symbolaris.com Course staff Individually Andre - aplatzer@cs.cmu.edu Alex - acrichto@andrew.cmu.edu Ian - igillis@andrew.cmu.edu Office Hours

Waitlisted? Long waitlist Room may become available! Beware of partnering If admitted but no singles left, you must solo Talk to me after lecture

Course Overview No exams Not even a final! 5 homeworks 6 Labs Required tests for each lab Paper at the end

Textbook(s) Modern Compiler Implementations in ML Andrew W. Appel Optional Compiler Construction William M. Waite and Gerhard Goos Optional Supplement lecture Do not replace it

Homeworks One before each lab is due About a week to work on each one Submitted through autolab individually Must be your own work 30% of the final grade (300 points total) Each homework is 6% of your grade Due at the beginning of lecture Can turn two homeworks in late Only up to the next lecture Excludes Thanksgiving

Labs - Overview Also submitted through autolab May be done in pairs (same pair for all labs) Must be entirely team's work Acknowledge outside sources in readme 70% of final grade (700 points total) 6 labs First 5 are 100 points each Last is 200

Labs - Overview Cumulatively build a compiler for C0 Expressions Control flow Functions Structs and arrays Memory safety and optimizations Choose your own adventure Each lab is a subset of C0 Also superset of previous lab

Labs - Language Can write compiler in language of choice Starter code (initial parser/layout) SML Haskell Scala Java Grading process make./bin/l{1,2,3,4,5,6}c

Labs - Layout Each lab has two parts Part 1: submit 10 tests 20% of the lab grade Based on number of tests submitted Can be as creative as you like Part 2: submit a compiler 80% of the lab grade Based on number of tests passed Tested against everyone's tests And previous labs And last years' And the year before that

Labs - Tests Very good way to test compilers Aren't comprehensive, however Purpose is to find individual bugs You are graded on everyone's tests assert(1 + 1 == 2)

Labs - Submission SVN repositories set up Work is submitted through SVN into autolab Only most recent submission is relevant We publish updates to tests and runtime You just run 'svn update' Only one autolab submission is necessary per team for labs We don't grade SVN, so submit updates to autolab!

Labs - Timing Two weeks for each lab Tests due at end of first week (11:59) Compiler due at end of second (11:59) No late days for tests 6 late days for compiler At most two per lab

Labs - Partners Can do labs alone Can also do with a partner Should remain the same for all labs Email 15411@symbolaris.com with partner We will then assign you a team name

Labs - Partners If partnering, choose wisely Must work as a team to be effective Cannot let the other "do all the work" Trouble arises Email 15411@symbolaris.com before too late Day before lab is due is too late Beginning of second lab is not too late

Labs - Warnings Labs are hard and take time Don't start the compiler only after submitting tests Errors in one lab carry over to the next Each lab still runs previous tests Do not take labs lightly, plan accordingly This class will consume much time 15-411 is by no means easy Compilers take a lot of work

Labs - Suggestions Start early Fixing tests takes a long time If submitted compiler has errors, fix quickly Errors for lab 1 must be fixed for lab 2! Schedule with partner Specifically set aside time for 15-411 Talk to us! Talk about design plans Especially if soloing Office hours or email Remember that this is exciting!

Labs - My suggestions Do not cram entire compiler into one week Compiler passes own tests when tests due Get to know the driver well You will be running this many many times Ask us if you want it do have feature X Write difficult tests Forces you to think Submit early to autolab Avoid the rush

Paper After 6th lab, a paper is required Technical paper demonstrating what you learned What design decisions did you make? What design decisions were good? Which ones ended badly? Were certain tests good or tricky? More details when time comes

Questions? Waitlist Course outline Homework Labs Partners Paper

Writing a Compiler

Course Goals Understand how compilers work General structure of compilers Influence of target/source language on design Restrictions of hardware Gain experience with a complex project Both maintain it and work with others Develop in a modular fashion Each lab builds on the next

What is a compiler? Translator from one language to another Might have a few changes in the middle Adheres to 5 principles Correctness Efficiency Interoperability Usability Retargetability

Compiler Principles - 1 Correctness How useful is an incorrect compiler? What if it were extremely fast? How do you know? Language specification Formal proof Tests, lots of tests

Compiler Principles - 1 What to test for correctness? 1 + 1 == 2 1 + 1!= 1 *a == 3 *NULL is a segv while (1) ; loops forever Language design Can make correctness a lot easier Or harder C0 is much better specified than C

Compiler Principles - 2 Efficiency Generated code is fast Compiling process is also fast Cannot forsake correctness "But I got the wrong answer really fast!"

Compiler Principles - 3 Interoperability Most binaries are not static Run with code from other compilers Interface, or an ABI C0 uses the C ABI x86 is different than x86-64 arm is very different

Compiler Principles - 4 Usability Error messages Error. Error in file foo.c Error at foo.c:3 Error at foo.c:3:5 Type Error at foo.c:3:5 Type Error at foo.c:3:5, did you mean...? Not formally tested in this class You're still writing code!

Compiler Principles - 5 Retargetability Multiple sources? Multiple targets? We will not emphasize this Does not mean you should disregard it

Designing a Compiler Correctness Efficiency Interoperability Usability Retargetability

Designing a Compiler Source Executable Compiler

Designing a Compiler Source Executable C to x86

Designing a Compiler Source Executable C to x86-64 C to x86

Designing a Compiler Source Executable Need common language

Designing a Compiler Source Executable Intermediate Representation

Designing a Compiler Source Executable Java C Intermediate x86-64 Representation x86

Designing a Compiler Source Executable C0 Intermediate x86-64 Representation

Designing a Compiler Source Executable C0 Intermediate x86-64 Representation What is this line?

Designing a Compiler C0 Source Executable Lex Intermediate Representation x86-64

Designing a Compiler C0 Source Executable Lex tokens Intermediate Representation x86-64

Designing a Compiler C0 Source Executable Lex Parse tokens Intermediate Representation x86-64

Designing a Compiler C0 Source Executable Lex Parse tokens Intermediate Representation x86-64 AST

Designing a Compiler C0 Source Executable Lex Parse tokens Intermediate Representation x86-64 AST Semantic Analysis

Designing a Compiler C0 Source Executable Lex Parse tokens Intermediate Representation x86-64 AST Semantic Analysis AST attributed

Designing a Compiler C0 Source Executable Lex Parse tokens AST Semantic Analysis Intermediate Representation Translate AST attributed x86-64

Designing a Compiler C0 Source Executable Lex Parse tokens AST Semantic Analysis Intermediate Representation Translate AST attributed x86-64 How about this?

Designing a Compiler C0 Source Executable Lex tokens Intermediate Representation Parse AST Semantic Analysis Translate AST attributed Optimize

Designing a Compiler C0 Source Executable Lex tokens Intermediate Representation Parse AST Semantic Analysis Translate AST attributed Optimize IR

Designing a Compiler C0 Source Executable Lex tokens Intermediate Representation Parse AST Semantic Analysis Translate AST attributed Optimize IR Reg. Alloc & Codegen

Designing a Compiler C0 Source Executable Lex tokens Intermediate Representation Parse AST Semantic Analysis Translate AST attributed Optimize IR ASM Reg. Alloc & Codegen

Designing a Compiler C0 Source Executable Lex Parse tokens AST Semantic Analysis Intermediate Representation Translate AST attributed Optimize IR ASM+Link ASM Reg. Alloc & Codegen

The Compiler 'W' C0 Source Executable Lex Parse tokens AST Semantic Analysis Intermediate Representation Translate AST attributed Optimize IR ASM+Link ASM Reg. Alloc & Codegen

The Compiler 'W' Easy to re-target all source languages Just add a new back end from the IR Easy to optimize all sources Just add a pass to the IR Easy to add a new source language Just add a new front end into the IR

The Compiler 'W' Variants Split register allocation and code generation Another optimize pass in codegen Reorder passes in backend

What to compile? Simple Goal is to learn how compilers work, not feature X Safe Semantics should be well defined Enables many optimizations

What to compile? What should happen here? int foo(int a, int b, int *c) { if (a / b == 1 *c == 3) return 3; return 4; }

What to compile? C Java C0? Simple Unsafe Not simple Safe(er)

What to compile? C0 is a safe variant of C Developed at CMU by Frank Pfenning and others All C0 programs are deterministic given same input Differences No pointer arithmetic No casting No stack allocated structs Hard(er) to shoot yourself in the foot Can enable memory safety

What to target? ISA Runnable? Oddities? x86 CISC x86-64 CISC arm, mips RISC simulators

What to target? We have chosen x86-64 You generate assembly, gcc links it Lots of fun caveats to deal with still

Questions? Compiler Principles The compiler 'W' C0 Lexing/Parsing Semantic analysis IR/optimizations Codegen/register allocation Well-defined semantics "safer C"

Remember... symbolaris.com Choose a partner Email 15411@symbolaris.com Labs are cumulative Don't fall behind Think about language you'll write in