



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Midterm ii exam questions for cs164, spring 2000 course. The questions cover various topics such as typing and code generation, type checking, runtime organization and code generation, and global analysis and optimization. Students are required to give appropriate cool typing rules, cool operational semantics rules, write code generation functions, draw control flow graphs, and write definitions for in and out sets.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Midterm II CS164, Spring 2000
April 11, 2000
Assume that we extend the Cool language with a new looping construct "do e1 until e2". The intended execution of this construct is that the expression e1 (the loop body) is evaluated by e2 (the terminal condition). If the value of e2 is false then the execution of the loop body starts again with e1. Otherwise the execution of the loop terminates and the value of the expression is the value of e1 in the last iteration
O, M, C |- e1 : Bool O, M, C |- e2 : t2 O, M, C |- e2 : T O, M, C |- if e1 then e2 else e3 fi : T2 |_| T
The typing rules of Cool contain many details whose presence and correctness is important to achieving a couple of goals:
O, M, C |- e1 : T1 T <= T0 O[T0/x], M, C |- e2 : T O, M, C |- let x : T0 <- e1 in e2 | T We propose below a number of changes to the typing rule for "let". Some of these proposed changes fail to achieve one or both of these two goals. Here is what you must do:
Problem #1:: Typing and Code Generation (15 points) 1
class A { a() : Int {0}; } class B inherits A { b() : Int {1 }; }
We replace O[T0/x] in the third hypothesis by O.
We replace T2 in the conclusion by T0.
We remove the second hypothesis T1 <= T
We replace the second hypothesis by T0 <=T
We replace O[T0/x] in the third hypothesis by O[T1/x]
In this problem you will have to write the code generation fuynctions for generating MIPS assembly using a calling convention different from the one used in the lecture. Here is the sequence of operations that a caller and the called function must perform (as shown in the figure):
Remember that the code that computes an expression should preserve the register $fp and should return the
Problem #2:: Type Checking (20 points) 2
We say that an expression y op z is available in variable x at some point in the program if no matter how the execution reaches that point the value of the variable is the same as that of the expression y oi z. We write "x = y op z" to denote such an available expression. For each instruction we define two sets,e ach containing elements of the form "x = y op z" :
*Write the definition of Out(i) as a function of In(i) if the instruction i is x := x op y. Out(i)=
*Write the definition of Out(i) as a function of In(i) if the instruction is x:=y Out(i)=
*Write the definition of Out(i) as a function of In(i) if the instruction i is goto n Out(i)=
Optimization The sets In(i) can be used to detect both common subexpressions and equality of variables at all points in the program. Describe how you can use the set In(i) to optimize the instruction i in each of the following cases. *The instruction i is x := y op z
*The instruction i is if x = y goto n