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

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

PLAGIARISM. Administrivia. Compilers. CS143 11:00-12:15TT B03 Gates. Text. Staff. Instructor. TAs. Office hours, contact info on 143 web site

Administrivia. Compilers. CS143 10:30-11:50TT Gates B01. Text. Staff. Instructor. TAs. The Purple Dragon Book. Alex Aiken. Aho, Lam, Sethi & Ullman

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Introduction. Compilers and Interpreters

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1)

Compiler Design 1. Introduction to Programming Language Design and to Compilation

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

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

Compiler Construction LECTURE # 1

Introduction to Compilers

Formal Languages and Compilers Lecture I: Introduction to Compilers

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Software Lesson 2 Outline

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

You may work with a partner on this quiz; both of you must submit your answers.

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

Compiler Construction D7011E

CS241 Computer Organization Spring Loops & Arrays

CS 415 Midterm Exam Spring 2002

Compilers. Lecture 2 Overview. (original slides by Sam

CS 242. Fundamentals. Reading: See last slide

Computer Organization & Assembly Language Programming

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

Lecture 1: Course Introduction

Overview. Overview. Programming problems are easier to solve in high-level languages

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

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

CS 415 Midterm Exam Spring SOLUTION

Lecture 1: Course Introduction

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Compilers Crash Course

Programming. translate our algorithm into set of instructions machine can execute

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation

CS 2505 Computer Organization I

Code Optimization. What is code optimization?

Compilers. Prerequisites

Profilers and Debuggers. Introductory Material. One-Slide Summary

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

Sungkyunkwan University

CS 526 Advanced Topics in Compiler Construction. 1 of 12

Compilers and Interpreters

administrivia final hour exam next Wednesday covers assembly language like hw and worksheets

Compiler Construction 2010 (6 credits)

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

CS241 Computer Organization Spring Introduction to Assembly

System Programming and Computer Architecture (Fall 2009)

ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections)

CS61 Section Solutions 3

Homework 0: Given: k-bit exponent, n-bit fraction Find: Exponent E, Significand M, Fraction f, Value V, Bit representation

Credits and Disclaimers

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

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

Lecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

Credits and Disclaimers

Principles of Compiler Construction ( )

Programming Language Design and Implementation. Wes Weimer MW 2:00 3:15 Thornton E-303

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

(the bubble footer is automatically inserted in this space)

Code Generation. Lecture 30

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

CPS104 Computer Organization Lecture 1. CPS104: Computer Organization. Meat of the Course. Robert Wagner

Optimizing Compilers. Vineeth Kashyap Department of Computer Science, UCSB. SIAM Algorithms Seminar, 2014

trends in programming languages

CS143 Final Fall 2009

CPS104 Computer Organization Lecture 1

Machine-Level Programming II: Control and Arithmetic

CMPSCI 201: Architecture and Assembly Language

Introduction & First Content Comp 412

Finding People and Information (1) G53CMP: Lecture 1. Aims and Motivation (1) Finding People and Information (2)

COMP 210 Example Question Exam 2 (Solutions at the bottom)

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

Overview of the Course

COSE212: Programming Languages. Lecture 0 Course Overview

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Administration. Prerequisites. Meeting times. CS 380C: Advanced Topics in Compilers

More Lambda Calculus and Intro to Type Systems

Credits to Randy Bryant & Dave O Hallaron

Operational Semantics. One-Slide Summary. Lecture Outline

CS 250 VLSI Design Lecture 11 Design Verification

The Hardware/Software Interface CSE351 Spring 2013

Computer Science and Programming. CPS 06 Program Design and Methodology I. What is Computer Science? Computer Science

CSE 417 Practical Algorithms. (a.k.a. Algorithms & Computational Complexity)

Compiler Construction

CSE 351 Spring 2017 Final Exam (7 June 2017)

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

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

Principles of Compiler Construction ( )

CS 2505 Computer Organization I

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

Assignment 11: functions, calling conventions, and the stack

The von Neumann Machine

Transcription:

Compilers Lecture 1 Introduction Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts)

Discussion What does a compiler do? Why do you need that? Name some compilers you have used 2

A Brief History of High-Level Languages 1953 IBM develops the 701 Memory: 4096 words of 36 bits Speed: 60 msec for addition All programming done in assembly code 3

Programming What s the problem? Assembly programming very slow and error-prone Software costs exceeded hardware costs! John Backus: Speedcoding Simulate a more convenient machine But, ran 10-20 times slower than hand-written assembly Backus Idea: translate high-level code to assembly Many thought this impossible Had already failed in other projects 1954-7 FORTRAN I project By 1958, >50% of all code is in FORTRAN Cut development time dramatically from weeks to hours 4

FORTRAN I The first compiler Huge impact on computer science Produced code almost as good as hand-written Led to an enormous body of work Theoretical work on languages, compilers Program semantics Thousands of new languages Modern compilers preserve the outlines of FORTRAN I 5

Language implementations Two major strategies: Interpretation Compilation Can you think of another strategy a hybrid? What are the main differences? Online : read program, execute immediately Offline : convert high-level program into assembly code Compilation is a language translation problem What are the languages? 6

Languages involved int i = 10; while (i > 0) { x = x * 2; i = i 1; } Source movl %esp, %ebp subl $4, %esp movl $10, -4(%ebp).L2: cmpl $0, -4(%ebp) jle.l3 movl 8(%ebp), %eax sall %eax movl %eax, 8(%ebp) leal -4(%ebp), %eax decl (%eax) jmp.l2.l3: movl 8(%ebp), %eax Target 7

The compilation problem Assembly language Converts trivially into machine code No abstraction: load, store, add, jump, etc. Extremely painful to program What are other problems with assembly programming? High-level language Easy to understand and maintain Abstractions: control (loops, branches); data (variables, records, arrays); procedures Problem: how do we get from one to the other? (systematically) 8

Translation process Meaning Sentences Sentences Words Words Letters Letters High-level language Assembly/machine code 9

Sounds easy! Translation can be tricky Infallible source: the Internet I saw the Pope ( el Papa ) I saw the potato ( la papa ) It won't leak in your pocket and embarrass you ( no los embarass ) It takes a tough man to make a tender chicken It won't leak in your pocket and make you pregnant ( no embarazado ) It takes a hard man to make a chicken affectionate 10

Job #1 What is our primary concern? Words or code: translate it correctly How do we know the translation is correct? Specifically, how do we know the resulting machine code does the same thing Does the same thing What does that even mean? 11

Correctness Practical solution: automatic tools Parser generators, regular expressions, rewrite systems, dataflow analysis frameworks, code generator-generators Extensive testing Theoretical solution: a bunch of math Formal description of semantics A proof that the translation is correct Topic of current research 12

Incorrectness What is this? The infamous Blue Screen of Death Internal failure in the operating system Buggy device driver 13

Good enough? Is there more than correctness? Our wines leave you nothing to hope for. -Swiss menu When passenger of foot heave in sight, tootle the horn. Trumpet him melodiously at first, but if he still obstacles your passage then tootle him with vigor. Drop your pants here for best results. -Tokyo dry cleaner -Car rental brochure 14

Job #2 Produce a good translation What does that mean for compilers? Good performance optimization Reduce the amount of work ( be concise ) Utilize the hardware effectively ( choose your words carefully ) How hard could that be? 15

Past processors 8086 29,000 transistors More speed, more complexity Pentium M 140,000,000 transistors But, same machine code why is that nice? 16

Tomorrow s processors Intel Core Duo Parallel, heterogeneous Really hard to program! Xbox 360 PS-3 CELL 17

Structure of a compiler Meaning Sentences Sentences Words Words Letters Letters Front End Back End 18

Structure of a compiler Organized as a series of passes Lexical Analysis Parsing Semantic Analysis Optimization Code Generation Front End Back End We will follow this outline in the class 19

What I want you to get out of this class Understand how compilers work Duh See how theory and practice work together Yes, theory of computation is good for something Also: graph algorithms, lattice theory, more Work with a large-ish software systems Learn to think about tradeoffs System design always involves tradeoffs Impossible to maximize everything 20

Study of compilers Brings together many parts of CS Practical and theoretical Some solved problems, others unsolved Theory of computation Programming languages Compiler Algorithms Operating systems Computer architecture 21

Course Structure Course has theoretical and practical aspects Programming assignments = practice Four homeworks Late policy: 55% of final grade Three late days per assignment, 5% penalty per day Final exam: 50% Need to pass both for grade to count 22

Project Build a compiler for a subset of Java Implemented in Java 23