CS153: Compilers Lecture 1: Introduction

Similar documents
15-411/ Compiler Design

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

CS 241 Data Organization using C

378: Machine Organization and Assembly Language

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

Compilers. Computer Science 431

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

ECE573 Introduction to Compilers & Translators

CS 241 Data Organization. August 21, 2018

General Course Information. Catalogue Description. Objectives

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

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014

CMPE 152 Compiler Design

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

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

ECE Introduction to Compilers and Translation Engineering

Lecture 1: Course Introduction

CST-402(T): Language Processors

CS/SE 153 Concepts of Compiler Design

Welcome to CS 135 (Winter 2018)

Programming Languages and Techniques (CIS120)

CS153: Compilers Lecture 15: Local Optimization

EECS 482 Introduction to Operating Systems

Computer Science 210: Data Structures

Course introduction. Advanced Compiler Construction Michel Schinz

CS 4349 Lecture August 21st, 2017

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

Working of the Compilers

Compilers for Modern Architectures Course Syllabus, Spring 2015

Syllabus. ICS103: Computer Programming in C 2017 / 2018 First Semester (Term 171) INSTRUCTOR Office Phone Address Office Hours

CSE 504: Compiler Design

CS 3304 Comparative Languages. Lecture 1: Introduction

Lecture 1: Course Introduction

MAT128A: Numerical Analysis Lecture One: Course Logistics and What is Numerical Analysis?

COSE212: Programming Languages. Lecture 0 Course Overview

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

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

CMPE 152 Compiler Design

CS/SE 153 Concepts of Compiler Design

Administration Computers Software Algorithms Programming Languages

Syllabus COSC-051-x - Computer Science I Fall Office Hours: Daily hours will be entered on Course calendar (or by appointment)

COSC 115: Introduction to Web Authoring Fall 2013

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

Undergraduate Compilers in a Day

Welcome to CS 135 (Fall 2018) Themes of the course. Lectures. cs135/

ECE Object-Oriented Programming using C++ and Java

LECTURE 3. Compiler Phases

Compilers. Prerequisites

CMSC Introduction to Database Systems

Database Systems (INFR10070) Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

CMPE 152 Compiler Design

CS 375 UNIX System Programming Spring 2014 Syllabus

CS 406/534 Compiler Construction Putting It All Together

ECE 3574: Applied Software Design

IT 341 Fall 2017 Syllabus. Department of Information Sciences and Technology Volgenau School of Engineering George Mason University

Languages and Automata

Welcome to CS 241 Systems Programming at Illinois

CS457/557 Functional Languages

Course Title: Network+/Networking Fundamentals. Course Section: CNS-101-I1. FORMAT: Online

Data Structures and Algorithms

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

Welcome to CSE131b: Compiler Construction

CSC 443: Web Programming

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

CSSE2002/7023 The University of Queensland

CS 3110 Lecture 1 Course Overview


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

CSCE 441 Computer Graphics Fall 2018

Advanced Programming CMPS 109

Lecture Notes on Compiler Design: Overview

Lecture Notes on Intermediate Representation

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

CIS*1500 Introduction to Programming

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

CSCI 2041: Advanced Language Processing

Syllabus Revised 03/05/2015

Programming Language Design and Implementation. Cunning Plan. Your Host For The Semester. Wes Weimer TR 9:30-10:45 MEC 214. Who Are We?

CS101: Intro to Computing Summer Week 1

Intelligent Agents in CloudDeakin

Compiling Techniques

CPSC 411: Introduction to Compiler Construction

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

CS 415 Midterm Exam Spring SOLUTION

Instructions PLEASE READ (notice bold and underlined phrases)

CS162 Week 1. Kyle Dewey. Friday, January 10, 14

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

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

University of Maryland at College Park Department of Geographical Sciences GEOG 477/ GEOG777: Mobile GIS Development

MODULE CODE MODULE NAME. NQF level. [Number of credits] Name of department. Faculty. Compiled by (Name of lecturer) YEAR

Welcome to CS 115 (Winter 2019)

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

Slide 1 CS 170 Java Programming 1

OHJ-306x: Software Testing Introduction to the Course Project Part 1: General Information and Project phases 1 & 2: Unit testing

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Welcome to CS 241 Systems Programming at Illinois

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

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

MS6021 Scientific Computing. MatLab and Python for Mathematical Modelling. Aimed at the absolute beginner.

Transcription:

CS153: Compilers Lecture 1: Introduction Stephen Chong https://www.seas.harvard.edu/courses/cs153

Source Code What is this course about?? Compiler! Target Code 2

What is this course about? How are programs written in a high-level language transformed into machine code? How can we ensure a program is somewhat meaningful? How is the program s memory managed? How can we analyze programs to discover invariant properties and improve their runtime performance? 3

Basic Architecture Source Code Parsing Front end Elaboration Lowering Optimization Back end Code Generation Target Code 4

Front end Lexing & Parsing From strings to data structures Usually split into two phases: Strings/Files Tokens Abstract Syntax Trees Lexing Parsing 5

Parsing tools Parsing is something that happens in essentially all applications. E.g., Google search bar, calendar, etc. First step in going from raw data to information Lots of CS theory (121) to help out Regular expressions (finite state automata) Context-free grammars (push-down automata) These abstractions show up in optimization too! Lots of tool support E.g., Lex and Yacc; Antlr, parsing combinators; etc. 6

Elaboration Type-checking Resolve variables, modules, etc. Check that operations are given values of the right types Infer types for sub-expressions Check for other safety/security problems Untyped Abstract Syntax Trees Typed Abstract Syntax Trees 7

Lowering Translate high-level features into a small number of target-like constructs e.g., while, for, do-loops all compiled to code using goto s e.g., objects, closures to records and function pointers e.g., make type-tests, array-bounds checks, etc. explicit Typed Abstract Syntax Trees Intermediate Code ASTs 8

Optimization Rewrite expensive sequences of operations into less expensive e.g., constant folding: 3+4 7 e.g., lift an invariant computation out of a loop e.g., parallelize a loop Intermediate Code ASTs Optimization Intermediate Code ASTs 9

Code generation Translate intermediate code into target code Register assignment Instruction selection Instruction scheduling Machine-specific optimization Intermediate Code ASTs Machine Code 10

Who should take CS153? People fascinated by languages & compilers Why does[n t] this language include this feature? Systems programmers Know the one tool that you use every day. What can[ t] a compiler do well? Architecture designers Interdependence between compiler and architecture See Intel iapx 432 and Intel Itanium (compiler-related) failures; register windows These days, architecture folks use compilers too! API designers A language is the ultimate API c.f., Facebook 11

Suggested prerequisites Ideally CS51 and CS61 CS51 alone is likely enough We assume Knowledge of OCaml A bit about how machines work e.g., 2 s complement arithmetic First project is a good time to get up to speed If you don t know something, ask! 12

Course Staff Aaron Bembenek Andrew Wong-Rolle Contact course staff at or via Piazza cs153-staff@seas.harvard.edu Don t send email to individual course staff (slower response, all of us need to be informed) 13

Administrivia Website https://www.seas.harvard.edu/courses/cs153 Piazza https://piazza.com/class#fall2018/cs153 In general, post questions publicly unless you think question or answer might be inappropriate sharing of project solutions Can post anonymously to classmates if you wish Office hours Will be announced later. Start next week Look on course website No section TF hours will be spent on office hours instead 14

Textbook Modern Compiler Implementaton in ML by Andrew W. Appel Recommended but not required. In most cases, class materials should suffice Lecture slides posted after the lecture (or before if they are ready in time) 15

Programming environment OCaml Ideal for writing compilers! SPIM MIPS simulator Ideal target for compilers. GitHub... 16

Assessment Roughly 70% projects (~8 projects total) 25% final exam 5% participation E.g., Piazza posting/answering, attend lectures and engage in discussion, attend office hours,... 17

Projects 8(ish) projects Mostly implementing parts of a compiler Typically 1-2 weeks per project In OCaml Plan ahead! No late days! No late submissions! But plenty of time to work on it All submissions must type-check and compile Multiple projects out at same time Implementation heavy course! Strongly encourage you to work with a partner! Next lecture will give Google form if you are looking for project partner 18

Projects 1. MIPS simulator Source Code 2 Understand the machine we are targeting 2. Fortran-ish front end Front end Parsing Elaboration Lowering 4 Back end Parsing and lexing Optimization Code Generation 3 3. Fortran-ish MIPS Simple front-end Simple lowering & code generation 4. C-ish MIPS 1st-order procedures, structs, arrays 1 Target Code 19

Projects 5. Scheme-ish C-ish Higher-order procedures, type-tests 6. ML-ish Scheme-ish Type inference 7. Algebraic optimization Tree-based rewriting Source Code Front end Parsing 2 6 Elaboration 5 Lowering 4 Optimization 7 Back end Code Generation 3 8 Target Code 8. Control-flow graphs Rip out naïve C-ish backend and replace with one based on control-flow graphs. Implement liveness analysis Implement graph-coloring register allocation 1 20

Learning outcomes Understand how compilers work Parsing, type-checking & inference, lowering, analysis, optimization, code generation. How to rewrite your code so that the compiler can do its job better. Programming experience Ability to abstract and improve an API with a formal language 21

Collaboration/Academic integrity Discussion and exchange of ideas good! Consult with your classmates as you work on problem sets. But: work you submit for evaluation should be result only of your and your project partner's efforts Do not share code nor accept code from other students Do not post course materials (including projects, solutions, exams, etc.) to websites (including public GitHub repositories, and similar) or course-content archives Don't look on the web for solutions If you are ever in doubt, ask the course staff to clarify what is and isn't appropriate. 22

Diversity and Inclusion Aim: create a learning environment that supports a diversity of thoughts, perspectives and experiences, and honors your identities (including race, gender, class, sexuality, religion, ability, etc.) 23

Diversity and Inclusion To help accomplish this: If you have a name and/or set of pronouns that differ from those that appear in your official Harvard records, please let me know! If you feel like your performance in the class is being impacted by your experiences outside of class, please don't hesitate to come and talk with me. I want to be a resource for you. If you prefer to speak with someone outside of the course, members of the SEAS Committee on Diversity, Inclusion, and Belonging are excellent resources. I (like many people) am still in the process of learning about diverse perspectives and identities. If something was said (by anyone) in class, office hours, Piazza, or project group work that made you feel uncomfortable, please talk to me about it. As a participant in course discussions, office hours, and group projects, you should also strive to honor the diversity of your classmates. If you ever are struggling and just need someone to talk to, feel free to stop by office hours, or to reach out to me and we can arrange a private meeting. 24

Questions/comments? 25