CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Exam, Dec 6, 2011

Similar documents
CS 132 Compiler Construction, Fall 2012 Instructor: Jens Palsberg Multiple Choice Exam, Nov 6, 2012

FORM 2 (Please put your name and form # on the scantron!!!!)

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

The code generator must statically assign a location in the AR for each temporary add $a0 $t1 $a0 ; $a0 = e 1 + e 2 addiu $sp $sp 4 ; adjust $sp (!

CS4215 Programming Language Implementation

Compilation 2012 Static Analysis

Linear-Scan Register Allocation. CS 352 Lecture 12 11/28/07

Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields

Following is the general form of a typical decision making structure found in most of the programming languages:

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester

CS3360 Design and Implementation of Programming Languages Final Exam May 16, pm to 12:45pm (2 hour and 40 minutes) NAME:

Variables and Java vs C++

CS159. Nathan Sprague

ECE232: Hardware Organization and Design

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

CS111: PROGRAMMING LANGUAGE II

Polynomial Functions I

Compiler Architecture

Math 1050 Lab Activity: Graphing Transformations

CS143 Final Spring 2016

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++

Semantics. Names. Binding Time

INTERMEDIATE REPRESENTATIONS RTL EXAMPLE

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code

CS 352 Compilers: Principles and Practice Final Examination, 12/11/05

CS 139 Practice Midterm Questions #2

Introduction to Computer Science Midterm 3 Fall, Points

Intermediate Code Generation

Object-Oriented Design Lecture 7 CSU 370 Fall 2008 (Pucella) Friday, Oct 3, 2008

B + -trees. Kerttu Pollari-Malmi

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

Question 1a) Trace of program

Key Java Simple Data Types

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum

CMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC

Decision Structures. Selection. Selection options (in Java) Plain if s (3 variations) Each action could be any of: if else (3 variations)

Homework #3: CMPT-379 Distributed on Oct 23; due on Nov 6 Anoop Sarkar

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 19: Efficient IL Lowering 5 March 08

Building Interpreters

Homework I - Solution

COMP-520 GoLite Tutorial

Module Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check?

Intermediate Code Generation

Data, memory. Pointers and Dynamic Variables. Example. Pointers Variables (or Pointers) Fall 2018, CS2

Section 1.4: Graphing Calculators and Computers

Process Synchronization and Communication

Register Allocation. CS 502 Lecture 14 11/25/08

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CS 6353 Compiler Construction Project Assignments

Java Identifiers, Data Types & Variables

CS 231 Data Structures and Algorithms, Fall 2016

Implicit differentiation

CS 455 Midterm Exam 1 Fall 2013 [Bono] Wednesday, Oct. 2, 2013

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

CS 432 Fall Mike Lam, Professor. Code Generation

THEORY OF COMPILATION

CS S-11 Memory Management 1

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Math 1131 Practice Exam 1 Spring 2018

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

Java Simple Data Types

Common Misunderstandings from Exam 1 Material

Programming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point

CS 161 Exam II Winter 2018 FORM 1

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

5. Semantic Analysis!

Midterm II CS164, Spring 2006

Languages and Compiler Design II IR Code Generation I

CSCI565 Compiler Design

BASIC ELEMENTS OF A COMPUTER PROGRAM

Name: Thus, y-intercept is (0,40) (d) y-intercept: Set x = 0: Cover the x term with your finger: 2x + 6y = 240 Solve that equation: 6y = 24 y = 4

Examination Questions Midterm 1

Variables vs. Registers/Memory. Simple Approach. Register Allocation. Interference Graph. Register Allocation Algorithm CS412/CS413

100 points 4 Pages of problems + 1 equation sheet 48 minutes. Recitation Instructor (circle one): Cardwell Griffith Nilsen Schoun Shiroyanagi Willis

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

CS2 Practical 1 CS2A 22/09/2004

CS302: Self Check Quiz 2

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Problem Grade Total

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

Arithmetic and Bitwise Operations on Binary Data

Programming Languages and Techniques (CIS120)

Intermediate Representa.on

System Software Assignment 1 Runtime Support for Procedures

Lecture 22: Java. Overall Structure. Classes & Objects. Every statement must end with ';' Carl Kingsford, , Fall 2015

5. Minimizing Circuits

3. (5 points) Name the 5 components of a computer

Global Register Allocation

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Code Generation. CS 540 George Mason University

Motivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return

CS 430 Computer Architecture. C/Assembler Arithmetic and Memory Access William J. Taffe. David Patterson

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

Transcription:

CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Eam, Dec 6, 2011 ID Name This eam consists of 22 questions. Each question has four options, eactl one of which is correct, while the other three options are incorrect. For each question, ou can check multiple options. I will grade each question in the following wa. If ou check none of the options, ou get 0 points. If ou check all four options, ou get 0 points. Check one option. If ou check one option, and that option is correct, ou get 2 points. If ou check one option, and that option is wrong, ou get 0.667 points (es, negative!). Check two options. If ou check two options, and one of those options is correct, ou get 1 point. If ou check two options, and both of them are wrong, ou get 1 point (es, negative!). Check three options. If ou check three options, and one of those options is correct, ou get 0.415 points. If ou check three options, and all three of them are wrong, ou get 1.245 points (es, negative!). The maimum point total is 22 2 = 44 points. I will calculate a percentage based on the points in the following wa: ma(0, point total) 100 44 Notice that if our point total is negative, ou will get 0 percent.

Eample Consider the following Java program: class C { C ; int f; void run(boolean b, int ) { C ; = new C(); if (b) { this.bump(,); } else { f = this..f + 1; } } } void bump(c z, int j) { z.f=j; } Question 1 Does the program tpe check? 20 a Yes 3 b No c The question cannot be answered based on the given information. 2 d A Java tpe checker would throw an eception.

Question 2 What is the smboltable at the point where the tpe checker will tr to tpe check the statement f = this..f +1;. 1 a The following smboltable in which we search for identifiers from the bottom: Id b Tpe boolean int C 1 b The following smboltable in which we search for identifiers from the top: Id b Tpe boolean int C 20 c The following smboltable in which we search for identifiers from the bottom: Id f b Tpe C int boolean int C 6 d The following smboltable in which we search for identifiers from the top: Id f b Tpe C int boolean int C

Question 3 Consider the translation of the method run to intermediate code in the stle of Vapor. What is reasonable Vapor-stle code for = new C();? 21 a = heapallocate 12 t.1 = heapallocate 8 store + 0 := t.1 store t.1 + 0 := C.run store t.1 + 4 := C.bump 1 b = heapallocate 8 t.1 = heapallocate 12 store + 4 := t.1 store t.1 + 0 := C.run store t.1 + 4 := C.bump 1 c = heapallocate 12 t.1 = heapallocate 8 store + 0 := t.1 store t.1 + 4 := C.run store t.1 + 8 := C.bump 1 d = heapallocate 8 t.1 = heapallocate 12 store + 4 := t.1 store t.1 + 4 := C.run store t.1 + 8 := C.bump

Question 4 Consider the translation of the method run to intermediate code in the stle of Vapor. What is reasonable Vapor-stle code for this.bump(,);? 22 a load t.2 := this + 0 load t.3 := t.2 + 4 call t.3(this,, ) 3 b load t.2 := this + 0 load t.3 := t.2 + 4 call t.3(t.2,, ) c load t.2 := this + 0 load t.3 := t.2 + 0 call t.3(this,, ) d load t.2 := this + 0 load t.3 := t.2 + 0 call t.3(t.2,, ) Question 5 Consider the translation of the method run to intermediate code in the stle of Vapor. What is reasonable Vapor-stle code for f = this..f + 1;? 24 a load t.4 := this + 0 load t.5 := t.4 + 4 move t.6 := t.5 + 1 store this + 4 := t.6 b load t.4 := this + 4 load t.5 := t.4 + 0 move t.6 := t.5 + 1 store this + 4 := t.6 c load t.4 := this + 0 load t.5 := t.4 + 4 move t.6 := t.4 + 1 store this + 4 := t.5 d load t.4 := this + 4 load t.5 := t.4 + 0 move t.6 := t.4 + 1 store this + 4 := t.5

Question 6 Consider the translation of the method run to intermediate code in the stle of Vapor. Let S 1 denote this.bump(,);, and let S 2 denote f = this..f + 1;. Assume that we represent true b 1 and that we represent false b 0. What is reasonable Vapor-stle code for if (b) S 1 else S 2? 22 a if0 b goto :else translation of S 1 goto :end else: translation of S 2 end: 2 b if b goto :else translation of S 1 goto :end else: translation of S 2 end: c d if0 b goto :else translation of S 2 goto :end else: translation of S 1 end: if b goto :else translation of S 2 goto :end else: translation of S 1 end:

Question 7 Assume that the compiler does not map an temporaries, variables, or arguments to registers. What is the MIPS stack laout for the method run in class C? In each of the possible answers, the stack pointer points to bottom element. 17 a b return address temporaries generated b the compiler saved registers 4 b b return address temporaries generated b the compiler saved registers f 5 c b return address temporaries generated b the compiler 1 d b return address temporaries generated b the compiler f

Eample Consider the following program that uses the variables b, i, and : L1: i = 1 L2: = i + b L3: b = i + 2 L4: if i > 20 then goto L10 L5: b = b+ L6: = i+1 L7: if > 10 then goto L3 L8: i = b+1 L9: goto L5 L10: return Question 8 In the control-flow graph for the program, which variables are live along an of the edges to L1? 21 a b b 2 c i 1 d None Question 9 In the control-flow graph for the program, which variables are live along an of the edges to L2? 22 a b, i b b, 1 c i, 1 d b, i, Question 10 In the control-flow graph for the program, which variables are live along an of the edges to L3? 19 a i, 2 b b, i c b, 3 d b, i, Question 11 In the control-flow graph for the program, which variables are live along an of the edges to L4? 20 a b, i, b b, i c b, 4 d i,

Question 12 In the control-flow graph for the program, which variables are live along an of the edges to L5? 21 a b, i, b b, i 2 c b, 1 d i, Question 13 In the control-flow graph for the program, which variables are live along an of the edges to L6? 21 a b, i b b, 2 c i, 1 d b, i, Question 14 In the control-flow graph for the program, which variables are live along an of the edges to L7? 21 a b, i, b b, i 3 c b, 1 d i, Question 15 In the control-flow graph for the program, which variables are live along an of the edges to L8? 21 a b, 1 b b, i 1 c i, 1 d b, i, Question 16 In the control-flow graph for the program, which variables are live along an of the edges to L10? 24 a b i c b d None

Eample The following is the bod of an entire procedure that uses si temporaries a, b, c, d, e, f. a = 1 b = a + 2 c = a + 3 d = b + c e = c + 4 f = d + 5 a = c + e e = a + f f = c + e e = e + f return e + 9 Question 17 Assume that we must assign one register to each of the si variables. What is the fewest number of registers that is needed for this program, without spilling? 12 a 3 11 b 4 1 c 5 d 6 Question 18 Assume that four registers r1,r2,r3,r4 are available, and that we run the linear scan register allocation algorithm on the program. Which variables get spilled to memor? 22 a None b e,f 1 c e 1 d f Question 19 Assume that three registers r1,r2,r3 are available, and that we run the linear scan register allocation algorithm on the program. Which variables get spilled to memor? 21 a e b None 1 c e,f 1 d f Question 20 Assume that two registers r1,r2 are available, and that we run the linear scan register allocation algorithm on the program. Which variables get spilled to memor? 22 a c,e 1 b e,f 1 c c,f d e

Eample The following fragment of the above procedure uses five temporaries a, b, c, d, e: c = a + 3 d = b + c e = c + 4 Assume that we have done register allocation for the entire procedure that contains this program fragment, and that we have assigned a to register r1, b to register r2, c to a memor location that we denote b c, d to a memor location that we denote b d, and e to register r1. Assume also that we have a spare register v0. Question 21 What is correct code for the program fragment? 24 a move v0 := r1 + 3 store c := v0 move v0 := v0 + r2 store d := v0 load v0 := c move r1 := v0 + 4 b move v0 := r1 + 3 store c := v0 move v0 := v0 + r2 store d := v0 move r1 := v0 + 4 c move v0 := r1 + 3 store c := v0 load v0 := c move v0 := v0 + r2 store d := v0 move r1 := v0 + 4 d move v0 := r1 + 3 store c := v0 load v0 := c move v0 := v0 + r2 move r1 := v0 + 4

Eample The following fragment of the above procedure uses three temporaries c, e, f: f = c + e e = e + f Assume that we have done register allocation for the entire procedure that contains this program fragment, and that we have assigned c to register r1, e to a memor location that we denote b e, and f to a memor location that we denote b f. Assume also that we have a spare registers v0 and v1. Question 22 What is correct code for the program fragment? a load v0 := e move r1 := r1 + v0 store f := r1 move v0 := v0 + r1 store e := v0 b c load v0 := e move v1 := r1 + v0 store f := v1 move v0 := v0 + r1 store e := v0 None of the other three answers are correct. 24 d load v0 := e move v1 := r1 + v0 store f := v1 move v0 := v0 + v1 store e := v0