Constraint Based Analysis

Size: px
Start display at page:

Download "Constraint Based Analysis"

Transcription

1 Seminar Constraint Based Analysis Toni Suter Fall Term 2014 Supervised by Prof. Peter Sommerlad

2 Abstract Static program analysis is used in compilers and refactoring tools as a means to examine the structure of a program. The result of an analysis can help in optimizing the program and in finding bugs in the source code. Many analyses need some knowledge about the control flow of the program in order to do their job. However, some programming language features can make this difficult because their use leads to code that is very dynamic and therefore hard to analyse at compile time. This paper briefly explains these problems and then shows how Constraint Based Control Flow Analysis can be used as a tool that enables the analysis of such code. Finally, it walks through an example which illustrates the steps that are involved in this process. I

3 Contents 1 Introduction Types of static program analysis Intraprocedural analysis Interprocedural analysis Control flow analysis How to represent an analysis result Acceptability Constraint generation Constraint resolution Graph Formulation Conclusion 18 1

4 1 Introduction Constraint Based Analysis is a form of static program analysis that uses systems of set contraints to describe certain aspects of a program. It can be used for many different kinds of analyses (e.g. to perform typechecking in a statically typed programming language or to analyse the control flow in a dynamic programming language where functions are first-class objects). This paper gives an overview over the various kinds of static program analyses and explores control flow analysis with the use of constraints in more detail. 1.1 Types of static program analysis Static program analysis is often used in compilers to perform optimizations such as constant folding and common subexpression elimination [ALSU06]. It can also be used to support stand-alone analysis and refactoring tools that help in finding bugs and improving the software quality. The subsections and describe the two main types of static program analysis: intraprocedural analysis and interprocedural analysis Intraprocedural analysis In intraprocedural analysis, the analyser examines individual procedures in isolation without the context of the entire program. As mentioned above, static program analysis is often used in compilers to optimize a program. Such an optimization consists of an analysis and a transformation. The analysis examines the program to determine whether it is possible and worthwhile to do the transformation. The transformation makes the actual changes that should lead to a better (e.g, faster, smaller, more energy-efficient, etc.) program. Many optimizations are based on intraprocedural analyses [CT11]. 2

5 1 Introduction For example, Common Subexpression Elimination (CSE) is an optimization that is based on an intraprocedural data flow analysis called Available Expression Analysis. Consider the pseudo-code in Listing 1.1: Listing 1.1: Before optimization 1 a := (c + d) * 2 2 b := (c + d) * 5 The Available Expression Analysis determines for each point p in the procedure, the expressions that are available. An expression is considered available if: 1. the expression is evaluated on every path to the point p 2. and the expression is not invalidated (killed) after the evaluation but before the point p (e.g, by assigning a new value to a variable that is used in the expression) Therefore, the expression (c + d) is considered available on line 2 and the result of the expression can be reused. This is shown in Listing 1.2: Listing 1.2: After optimization 1 tmp := c + d 2 a := tmp * 2 3 b := tmp * 5 This optimization improves the speed of the program by storing the result of the expression (c + d) in a temporary variable thereby removing the need to calculate the result twice. Live Variable Analysis, Reaching Definitions Analysis and Very Busy Expressions Analysis are other examples of intraprocedural analyses [NNH99]. All of these techniques depend on the fact that it is relatively easy to determine the control flow within a procedure. For example, if the control flow reaches the condition of an if-else statement, there are exactly 2 positions where it can continue; either in the if-block or the else-block. Since intraprocedural analysis doesn t analyse the interactions between different functions, the control flow is more or less predictable at compile time Interprocedural analysis Some intraprocedural optimizations may be used on a whole-program level. For example, Dead Code Elimination is an optimization technique that removes code which is never executed. If the analyser starts 3

6 1 Introduction analysing the control flow between functions (inter-flow), it may be able to apply this optimization across function calls. Consider the C++ code in Listing 1.3: Listing 1.3: Example for possible Dead Code Elimination 1 void f(int x) { 2 if(x < 0) { 3 //do something 4 } 5 else { 6 //do something else 7 } 8 } 9 10 int main() { 11 f(10); 12 f(5); 13 } In this example, an optimizing compiler may be able to use interprocedural data flow analysis to find out that the parameter x in the function f only ever takes on positive values in this program and that it s therefore possible to eliminate the if-branch from the code. However, calculating the interprocedural control flow of a program is often not a straightforward task. For example, at the end of a procedure there could be many different places where the control flow continues because procedures are usually called from various locations. Additionally, modern programming languages often support a form of dynamic dispatch which means that it is sometimes not possible to determine at compile time which function body is executed as a result of a function application. The following two subsections describe these problems in more detail. 4

7 1 Introduction Higher-order functions in JavaScript In JavaScript, functions are first-class objects which means that they can be stored in variables, passed as an argument or returned from another function [AS96]. Higher-order functions take one or more functions as an input or return a function [Lip11]. Listing 1.4 shows a higher-order function in JavaScript: Listing 1.4: Higher-order function in JavaScript 1 //filters an array based on a custom predicate 2 function filter(arr, predicate) { 3 var filtered = []; 4 5 for(var i = 0; i < arr.length; ++i) 6 if(predicate(arr[i])) 7 filtered.push(arr[i]); 8 9 return filtered; 10 } function is_even(x) { 13 return x % 2 == 0; 14 } var numbers = [0,1,2,3,4,5,6,7,8,9,10]; 17 console.log(numbers); //[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] var even_numbers = filter(numbers, is_even); 20 console.log(even_numbers); //[0, 2, 4, 6, 8, 10] At the point inside the filter()-function where the predicate()-function is called, it is not immediately clear where the control flow continues. In this simple program it is easy to find out from the context that the function is_even() will be called. However, in a real world program, a utility function like filter() will be called many times, possibly with different predicates. Thus, there is no single specific predicate function body that will be executed each time the filter() function is called. The function body that is actually executed depends on the function that is stored in the parameter predicate at the time of invocation. 5

8 1 Introduction Dynamic dispatch through inheritance in C++ Many programming languages support dynamic dispatch through inheritance. This can be used to implement polymorphic types, that is, multiple types that provide a common interface [Str14]. Listing 1.5 shows an example of dynamic dispatch in C++: Listing 1.5: Dynamic dispatch through inheritance in C++ 1 #include <iostream> 2 #include <string> 3 4 class Person { 5 std::string name; 6 public: 7 Person(std::string const& n):name{n} {} 8 virtual std::string description() const { 9 return name; 10 } 11 virtual ~Person()=default; 12 }; class Student : public Person { 15 int student_id; 16 public: 17 Student(std::string const& n, int i):person{n}, student_id{i} {} 18 std::string description() const override { 19 return Person::description() + " (" + std::to_string(student_id) + ")"; 20 } 21 }; void print(person const& p) { 24 std::cout << p.description() << std::endl; 25 } int main(int argc, char *argv[]) { 28 Person p{"toni Suter"}; 29 Student s{"toni Suter", 1234}; 30 print(p); // "Toni Suter" 31 print(s); // "Toni Suter (1234)" 32 } Like in the JavaScript example in Listing 1.4, there is not just one function body that can be executed as a result of calling p.description(). Depending on whether the argument that is passed to the function print() is a Person object or an instance of a Person subclass the results may vary. The function body that is actually executed depends on the dynamic type of the parameter p. 6

9 1 Introduction Motivation for Constraint Based Control Flow Analysis (CFA) Constraints can be used to calculate the control flow between functions (inter-flow) even for programs written in programming languages that support higher-order functions and dynamic dispatch as shown in the examples in Listing 1.4 and Listing 1.5. The general process of a Constraint Based Analysis is as follows: 1. Start with an initial solution 2. Generate a system of constraints (section 2.3) 3. Resolve the constraints to get the final solution (section 2.4) For example, in the JavaScript code in Listing 1.4, the analyser would start with an initial solution by assigning to each subexpression the set of functions that it may evaluate to. In the beginning those sets are incomplete. Constraints that describe relationships and dependencies between the sets of different subexpressions are then used to propagate the values from one set to another if necessary [Aik99]. Finally, after the constraints are resolved, the analyser knows that the parameter predicate can only evaluate to the is_even() function and may be able to perform interprocedural optimizations based on that knowledge. Therefore, control flow analysis somewhat depends on data flow analysis, because in order for the analyser to know where the control flow continues when the expression predicate(arr[i]) is executed, it has to know the values that the variable predicate can evaluate to. 7

10 2 Control flow analysis This section describes how to analyse the control flow of a program using constraints. As described in section 1.1, control flow analysis is particularly interesting in programming languages that support some form of dynamic dispatch. In this paper simple JavaScript examples are used to show the process of Constraint Based Control Flow Analysis. Some of the code is derived from the examples in the book Principles of Program Analysis [NNH99] where the untyped lambda calculus [Chu32] with a few extensions is used. 2.1 How to represent an analysis result The goal of a Constraint Based Control Flow Analysis is to determine the control flow between functions (inter-flow). As described in subsection the control flow of a program often depends on its data flow. For example, in a programming language like JavaScript where functions are first-class objects, the control flow may depend on the function that is currently stored in a variable / parameter. Therefore, the result of an analysis must contain for each subexpression the set of functions that it may evaluate to. Usually, such an analysis result is defined by a pair (Ĉ, p). The abstract cache Ĉ is a function that maps each subexpression of the program to the set of functions that it may evaluate to. The function p is called the abstract environment and it maps the variables of the program to the set of functions that may be stored in them. In order to be able to refer to each of the different subexpressions in the program they need to have a unique label. Listing 2.1 shows a simple, labelled JavaScript program: 8

11 2 Control flow analysis Listing 2.1: JavaScript example (the labels are not part of JavaScript) 1 (function apply_two(f) { 2 (return f 1 (2);) 2 3 }) (function square(x) { 6 (return x 4 * x 5 ;) 6 7 }) (function triple(y) { 10 (return y 8 + 3;) 9 11 }) (apply_two(square 11 );) (apply_two(triple 13 );) 14 The function apply_two() is a higher-order function which has one function parameter f. It calls f with the argument 2 and returns the result of this function call. The most interesting part of this program is at label 1 where dynamic dispatch happens. Table 2.1 and Table 2.2 show the analysis result in terms of the abstract cache and the abstract environment, respectively: Table 2.1: Abstract cache Ĉ Label Ĉ 1 { square, triple } 2 {} 3 { apply_two } 4 {} 5 {} 6 {} 7 { square } 8 {} 9 {} 10 { triple } 11 { square } 12 {} 13 { triple } 14 {} Table 2.2: Abstract environment p Variable p apply_two { apply_two } square { square } triple { triple } f { square, triple } x {} y {} 9

12 2 Control flow analysis The sections 2.3 and 2.4 show how one may get to such a result by generating and resolving a set of constraints. Since this is a pure control flow analysis, the result contains only function values. This is also the reason why there are so many empty sets in the result. For example, in this program the parameters x and y can only ever have the value 2. Because this is a number and not a function value it does not appear in the abstract environment p. The abstract cache for label 1 is the set { square, triple }. We therefore know, that the control flow at this point either continues in the function square() or the function triple(). As described in subsection this may enable the compiler to perform intraprocedural optimizations on a whole-program level. 2.2 Acceptability An analysis result is considered acceptable/valid, if it contains for each subexpression the set of functions that it may evaluate to. Thus, a result that contains the set of all functions for each subexpression would be a valid result, altough not a very useful one. The goal is to narrow the result down to the least solution because this increases the chances of being able to perform additional optimizations [NNH99]. There are a few simple rules that define for each type of expression (e.g. function application, binary expression, etc.) the conditions that have to be true in order for an analysis result to be valid. These rules are used to check whether an analysis result is acceptable for a particular program. Consider for example Listing 2.2: Listing 2.2: Acceptability example 1 (function my_func(f) { 2 (f 1 ();) 2 3 }) (my_func((function() { 6 //brilliant code 7 }) 4 );) 5 It should be clear, that an analysis result is only acceptable for this program, if Ĉ(4) p(f) or in other words, if the anonymous function in subexpression 4 is in the set of possible values for the parameter f. 10

13 2 Control flow analysis 2.3 Constraint generation Constraint generation is the process of building a set of constraints for a particular program. The constraints describe relationships between the abstract cache and the abstract environment of each subexpression. The goal is to generate a set of constraints and then to find the least solution that satisfies these constraints and is still considered acceptable. The constraints can be constructed by following specific rules for each kind of language construct. For example, consider the following rule var: [var] C x l = { p(x) Ĉ(l) } C is a function that maps expressions to the set of constraints that they generate. The rule var defines the constraints that are generated for expressions that consist of a single variable. In this case it s only one constraint: p(x) Ĉ(l). This means that the abstract cache Ĉ for the subexpression with the label l should at least contain all the values from the abstract environment of the variable x. In other words, if a variable x can take on a certain set of values, an expression that only consists of this variable can evaluate to the same set of values. This was a very simple example. The rule for function definition fn is a little more complex: [fn] C (function(x) { return e 0 ; }) l = {{function(x) { return e 0 ; }} Ĉ(l)} C e 0 The rule fn defines the constraints that are generated for function definitions. First, the constraint {function(x) { return e 0 ; }} Ĉ(l) is generated which causes the function value to propagate to the abstract cache of the surrounding expression with the label l. Additionally, the constraints that are generated by the expression e 0 are added to the set as well. Similar to the examples above, there are rules that define the set of constraints that needs to be generated for every language construct (e.g., function application, binary expression, etc.). 11

14 2 Control flow analysis 2.4 Constraint resolution Constraint resolution is the process in which the constraints of a program are turned into an actual analysis result. The goal of the constraint resolution is to find the least solution without actually running the program. A solution is considered to be the least solution if the abstract cache and the abstract environment are narrowed down as much as possible and the result is still acceptable Graph Formulation One way to solve a system of constraints is to build a graph from the environment p, the cache Ĉ and the constraints and then use a special algorithm to propagate the contents of the sets through the graph. Therefore, we have to start with an initial cache and environment. This initial result should contain just the values that can be identified by looking at each subexpression in isolation of the rest of the program. For example, consider the labelled JavaScript code in Listing 2.3: Listing 2.3: Graph Formulation example code 1 ((function(x) { 2 return x 1 ; 3 }) 2 ((function(y) { 4 return y 3 ; 5 }) 4 )) 5 In this simple example, an anonymous identity function is defined and immediately called with another anonymous identity function passed as argument. This may be a strange example, but longer, more meaningful programs would make it very hard to illustrate the Graph Formulation algorithm concisely. For this example, the initial result would just contain Ĉ(2) = {id x} and Ĉ(4) = {id y } where id x and id y are shorthands for the two identity functions. 12

15 2 Control flow analysis Furthermore, let s assume that there is already an existing set of constraints that was generated from rules similar to those shown in section 2.3: p(x) Ĉ(1) p(y) Ĉ(3) id x Ĉ(2) Ĉ(1) Ĉ(5) id x Ĉ(2) Ĉ(4) p(x) id y Ĉ(2) Ĉ(3) Ĉ(5) id y Ĉ(2) Ĉ(4) p(y) The following subsections describe the different steps in the Graph Formulation algorithm. Each step description contains a figure that shows the state of the graph after the step has been executed as well as an explanation of what happened. Additionally, each step title contains the state of the worklist W. The worklist W is the list of nodes that has to be processed (orange nodes in the figures). 13

16 2 Control flow analysis Step 1 : W = [Ĉ(4), Ĉ(2)] Step 1 is the starting position of the algorithm. The graph has nodes for the cache of each subexpression and for the environment of each variable. For each constraint, there is at least one directed edge in the graph that connects the nodes that are involved in this constraint. For example, the constraint p(x) Ĉ(1) is responsible for the edge that leads from the environment of the variable x to the cache of the subexpression with the label 1. Figure 2.1: Step 1 Step 2 : W = [Ĉ(4), Ĉ(2)] In step 2, some constraints are grayed out. The edges of these constraints should not be traversed by the algorithm. This is because the first part of these constraints is not true. For example, in the constraint id y Ĉ(2) Ĉ(4) p(y) the first part of the implication is not true and therefore the whole constraint is inactive. Figure 2.2: Step 2 14

17 2 Control flow analysis Step 3 : W = [p(x), Ĉ(2)] In step 3, the first node in the worklist (Ĉ(4)) is processed by traversing each of its outgoing, active edges. In this case, there is only one such edge, namely the one with the constraint id x Ĉ(2) Ĉ(4) p(x). Since the first part of the implication is true, the values in Ĉ(4) can be propagated to p(x). Additionally, the node p(x) is added to the worklist. Figure 2.3: Step 3 Step 4 : W = [Ĉ(1), Ĉ(2)] The same thing happens when the node p(x) is processed. The values in p(x) can be propagated to Ĉ(1) because of the edge that leads from p(x) to Ĉ(1). The node Ĉ(1) becomes a new member of the worklist. Figure 2.4: Step 4 15

18 2 Control flow analysis Step 5 : W = [Ĉ(5), Ĉ(2)] The constraint id x Ĉ(2) Ĉ(1) Ĉ(5) causes the values from Ĉ(1) to be propagated to the node Ĉ(5). Figure 2.5: Step 5 Step 6 : W = [] The node Ĉ(5) doesn t have any outgoing edges, so it can be removed from the worklist. The node Ĉ(2) is the only remaining member of the worklist. It can be removed too, because its outgoing edges are due to constraints that have already been processed. This is the final result of the analysis. Figure 2.6: Step 6 16

19 2 Control flow analysis Final result The tables 2.3 and 2.4 show the final result of the Graph Formulation in tabular form: Table 2.3: Abstract cache Ĉ Label Ĉ 1 {id y } 2 {id x } 3 {} 4 {id y } 5 {id y } Table 2.4: Abstract environment p Variable p x {id y } y {} This represents the least solution for the code in Listing 2.3. For example, it shows that the overall expression with the label 5 can only evaluate to the identity function id y. Since all the possible function values for each subexpression are now known, the analyser also knows which function bodies may be executed as a result of calling a function (inter-flow). In larger, more meaningful programs this knowledge may be useful to perform intraprocedural optimizations on a whole-program level as shown in subsection

20 3 Conclusion My goal for this paper was to give a brief overview over different kinds of static program analysis as well as a more detailed description of Constraint Based Control Flow Analysis (CFA). After reading this paper it should be clear to the reader that Constraint Based CFA is a powerful tool to analyse the control flow between procedures (inter-flow) which can lead to further optimization possibilities. It is worth noting that there exist more constraint based analysis techniques than the one that was described in this paper. However, explaining all of them in detail would be beyond the scope of this paper. 18

21 Bibliography [Aik99] Alexander Aiken. Introduction to Set Constraint-Based Program Analysis [ALSU06] Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. Compilers - Principles, Techniques and Tools [AS96] Harold Abelson and Gerald Jay Sussman. Structure and Interpretation of Computer Programs [Chu32] Alonzo Church. A Set of Postulates for the Foundation of Logic [CT11] Keith Cooper and Linda Torczon. Engineering a Compiler [Lip11] Miran Lipovaca. Learn You a Haskell for Great Good! [NNH99] [Str14] Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. Principles of Program Analysis Bjarne Stroustrup. Bjarne Stroustrup s C++ Glossary, December

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example Interprocedural Analysis with Data-Dependent Calls Circularity dilemma In languages with function pointers, first-class functions, or dynamically dispatched messages, callee(s) at call site depend on data

More information

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

COMP 3002: Compiler Construction. Pat Morin School of Computer Science COMP 3002: Compiler Construction Pat Morin School of Computer Science Course Information Instructor: Pat Morin morin@scs.carleton.ca Just "Pat" Office Hours: Tuesdays 9:00-10:00, 13:30-14:30 Webpage: http://cg.scs.carleton.ca/~morin/teaching/3002/

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example Interprocedural Analysis with Data-Dependent Calls Circularity dilemma In languages with function pointers, first-class functions, or dynamically dispatched messages, callee(s) at call site depend on data

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit. C++ Basics January 19, 2012 Brian A. Malloy Slide 1 of 24 1. Many find Deitel quintessentially readable; most find Stroustrup inscrutable and overbearing: Slide 2 of 24 1.1. Meyers Texts Two excellent

More information

Programming Language Processor Theory

Programming Language Processor Theory Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern

More information

Lecture Notes on Alias Analysis

Lecture Notes on Alias Analysis Lecture Notes on Alias Analysis 15-411: Compiler Design André Platzer Lecture 26 1 Introduction So far we have seen how to implement and compile programs with pointers, but we have not seen how to optimize

More information

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 19, 2014

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 19, 2014 Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2014 November 19, 2014 Instructions This exam contains 10 pages, including this one. Make sure you have all the pages. Write your name on the top

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Hello world : a review Some differences between C and C++ Let s review some differences between C and C++ looking

More information

Control Flow Analysis with SAT Solvers

Control Flow Analysis with SAT Solvers Control Flow Analysis with SAT Solvers Steven Lyde, Matthew Might University of Utah, Salt Lake City, Utah, USA Abstract. Control flow analyses statically determine the control flow of programs. This is

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Intermediate Code Generation (ICG)

Intermediate Code Generation (ICG) Intermediate Code Generation (ICG) Transform AST to lower-level intermediate representation Basic Goals: Separation of Concerns Generate efficient code sequences for individual operations Keep it fast

More information

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation CSE 501: Compiler Construction Course outline Main focus: program analysis and transformation how to represent programs? how to analyze programs? what to analyze? how to transform programs? what transformations

More information

Lecture Notes on Data Representation

Lecture Notes on Data Representation Lecture Notes on Data Representation 15-814: Types and Programming Languages Frank Pfenning Lecture 9 Tuesday, October 2, 2018 1 Introduction In this lecture we ll see our type system in action. In particular

More information

Interprocedural Dataflow Analysis. Galeotti/Gorla/Rau Saarland University

Interprocedural Dataflow Analysis. Galeotti/Gorla/Rau Saarland University Interprocedural Dataflow Analysis Galeotti/Gorla/Rau Saarland University int divbyx(int x) { [result := 10/x] 1 ; void caller1() { [x := 5] 1 ; [y := divbyx(x)] 2 ; [y := divbyx(5)] 3 ; [y := divbyx(1)]

More information

Data Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto

Data Structures and Algorithms in Compiler Optimization. Comp314 Lecture Dave Peixotto Data Structures and Algorithms in Compiler Optimization Comp314 Lecture Dave Peixotto 1 What is a compiler Compilers translate between program representations Interpreters evaluate their input to produce

More information

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016 Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2016 November 21, 2016 Instructions This exam contains 7 pages, including this one. Make sure you have all the pages. Write your name on the top

More information

Intra-procedural Data Flow Analysis Introduction

Intra-procedural Data Flow Analysis Introduction The Setting: Optimising Compilers The Essence of Program Analysis Reaching Definitions Analysis Intra-procedural Data Flow Analysis Introduction Hanne Riis Nielson and Flemming Nielson email: {riis,nielson}@immdtudk

More information

Exam Duration: 2hrs and 30min Software Design

Exam Duration: 2hrs and 30min Software Design Exam Duration: 2hrs and 30min. 433-254 Software Design Section A Multiple Choice (This sample paper has less questions than the exam paper The exam paper will have 25 Multiple Choice questions.) 1. Which

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

Programming Language Implementation

Programming Language Implementation A Practical Introduction to Programming Language Implementation 2014: Week 12 Optimisation College of Information Science and Engineering Ritsumeikan University 1 review of last week s topics why primitives

More information

C++ Primer. CS 148 Autumn

C++ Primer. CS 148 Autumn C++ Primer CS 148 Autumn 2018-2019 1 Who is this for? If you are taking this class and are not familiar with some of the features of C++, then this guide is for you. In other words, if any of these words

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New exercise out today, due Wednesday morning Exam Friday

More information

3/18/18. Program Analysis. CYSE 411/AIT 681 Secure Software Engineering. Learning Goal. Program Analysis on Security. Why Program Representations

3/18/18. Program Analysis. CYSE 411/AIT 681 Secure Software Engineering. Learning Goal. Program Analysis on Security. Why Program Representations Program Analysis CYSE 411/AIT 681 Secure Software Engineering Topic #14. Program Analysis Instructor: Dr. Kun Sun The process of automatically analyzing the behavior of computer programs regarding a property

More information

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 11, 2015

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 11, 2015 Name: Midterm 2 CMSC 430 Introduction to Compilers Fall 2015 November 11, 2015 Instructions This exam contains 8 pages, including this one. Make sure you have all the pages. Write your name on the top

More information

The Software Stack: From Assembly Language to Machine Code

The Software Stack: From Assembly Language to Machine Code COMP 506 Rice University Spring 2018 The Software Stack: From Assembly Language to Machine Code source code IR Front End Optimizer Back End IR target code Somewhere Out Here Copyright 2018, Keith D. Cooper

More information

CS 6110 S14 Lecture 1 Introduction 24 January 2014

CS 6110 S14 Lecture 1 Introduction 24 January 2014 CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions

More information

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova You reuse code by creating new classes, but instead of creating them from scratch, you use existing classes that someone else has built and debugged. In composition

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CYSE 411/AIT 681 Secure Software Engineering Topic #14. Program Analysis

CYSE 411/AIT 681 Secure Software Engineering Topic #14. Program Analysis CYSE 411/AIT 681 Secure Software Engineering Topic #14. Program Analysis Instructor: Dr. Kun Sun Program Analysis The process of automatically analyzing the behavior of computer programs regarding a property

More information

ECE 462 Fall 2011, Third Exam

ECE 462 Fall 2011, Third Exam ECE 462 Fall 2011, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 12 pages total (including this cover sheet). Please let Prof.

More information

Supporting Class / C++ Lecture Notes

Supporting Class / C++ Lecture Notes Goal Supporting Class / C++ Lecture Notes You started with an understanding of how to write Java programs. This course is about explaining the path from Java to executing programs. We proceeded in a mostly

More information

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY G.PULLAI COLLEGE OF ENGINEERING & TECNOLOGY Nandikotkur Road, Kurnool 518002 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Semester VI (2017-2018) COURSE DESCRIPTION Course Code : 15A05601 Course Title

More information

An introduction to C++ template programming

An introduction to C++ template programming An introduction to C++ template programming Hayo Thielecke University of Birmingham http://www.cs.bham.ac.uk/~hxt March 2015 Templates and parametric polymorphism Template parameters Member functions of

More information

CS

CS CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and

More information

Static Vulnerability Analysis

Static Vulnerability Analysis Static Vulnerability Analysis Static Vulnerability Detection helps in finding vulnerabilities in code that can be extracted by malicious input. There are different static analysis tools for different kinds

More information

On Meaning Preservation of a Calculus of Records

On Meaning Preservation of a Calculus of Records On Meaning Preservation of a Calculus of Records Emily Christiansen and Elena Machkasova Computer Science Discipline University of Minnesota, Morris Morris, MN 56267 chri1101, elenam@morris.umn.edu Abstract

More information

Weeks 6&7: Procedures and Parameter Passing

Weeks 6&7: Procedures and Parameter Passing CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

More information

Advanced Topics in Programming Languages Lecture 2 - Introduction to Haskell

Advanced Topics in Programming Languages Lecture 2 - Introduction to Haskell Advanced Topics in Programming Languages Lecture 2 - Introduction to Haskell Ori Bar El Maxim Finkel 01/11/17 1 History Haskell is a lazy, committee designed, pure functional programming language that

More information

IR Optimization. May 15th, Tuesday, May 14, 13

IR Optimization. May 15th, Tuesday, May 14, 13 IR Optimization May 15th, 2013 Tuesday, May 14, 13 But before we talk about IR optimization... Wrapping up IR generation Tuesday, May 14, 13 Three-Address Code Or TAC The IR that you will be using for

More information

CS115 - Module 9 - filter, map, and friends

CS115 - Module 9 - filter, map, and friends Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Intermezzo 3 (Section 18); Sections 19-23. Abstraction abstraction, n. 3a.... The process of isolating properties or

More information

General Computer Science II Course: B International University Bremen Date: Dr. Jürgen Schönwälder Deadline:

General Computer Science II Course: B International University Bremen Date: Dr. Jürgen Schönwälder Deadline: General Computer Science II Course: 320102-B International University Bremen Date: 2004-04-28 Dr. Jürgen Schönwälder Deadline: 2004-05-14 Problem Sheet #7 This problem sheet focusses on C++ casting operators

More information

Why C++ is much more fun than C (C++ FAQ)?

Why C++ is much more fun than C (C++ FAQ)? From C to C++ Why C++ is much more fun than C (C++ FAQ)? 1. Classes & methods - OO design 2. Generic programming - Templates allow for code reuse 3. Stricter type system (e.g. function args) 4. Some run-time

More information

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions CS162: Introduction to Computer Science II A typical way to handle error conditions is through the return value. For example, suppose we create a loadfile() function that returns true if it loaded the

More information

2 ADT Programming User-defined abstract data types

2 ADT Programming User-defined abstract data types Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct

More information

Local Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code

Local Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code COMP 412 FALL 2017 Local Optimization: Value Numbering The Desert Island Optimization Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,

More information

G53CMP: Lecture 1. Administrative Details 2016 and Introduction to Compiler Construction. Henrik Nilsson. University of Nottingham, UK

G53CMP: Lecture 1. Administrative Details 2016 and Introduction to Compiler Construction. Henrik Nilsson. University of Nottingham, UK G53CMP: Lecture 1 Administrative Details 2016 and Introduction to Compiler Construction Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 1 p.1/39 Finding People and Information (1) Henrik Nilsson

More information

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

Finding People and Information (1) G53CMP: Lecture 1. Aims and Motivation (1) Finding People and Information (2) Finding People and Information (1) G53CMP: Lecture 1 Administrative Details 2017 and Introduction to Compiler Construction Henrik Nilsson Henrik Nilsson Room A08, Computer Science Building e-mail: nhn@cs.nott.ac.uk

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

HW3a solution. L1 implies there must be an f1 in Base L2 implies there must be an f2 in Base. So we know there is an f1 and f2 in Base

HW3a solution. L1 implies there must be an f1 in Base L2 implies there must be an f2 in Base. So we know there is an f1 and f2 in Base HW 3 Solution int main(int argc, char **argv) { Base *b = new Base( ); Derived *d = new Derived( ); b->f1( ); // prints "Base f1" L1 b->f2( ); // prints "Base f2" L2 d->f1( ); // prints "Base f1" L3 d->f2(

More information

Lecture Notes on Common Subexpression Elimination

Lecture Notes on Common Subexpression Elimination Lecture Notes on Common Subexpression Elimination 15-411: Compiler Design Frank Pfenning Lecture 18 October 29, 2015 1 Introduction Copy propagation allows us to have optimizations with this form: l :

More information

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++ Introduction to Programming in C++ Course Text Programming in C++, Zyante, Fall 2013 edition. Course book provided along with the course. Course Description This course introduces programming in C++ and

More information

ST. XAVIER S COLLEGE

ST. XAVIER S COLLEGE ST. XAVIER S COLLEGE MAITIGHAR, KATHMANDU Compiler Design and Construction Lab Assignment #1 Submitted by: Aashish Raj Shrestha 013BSCCSIT002 Submitted to: Mr. Ramesh Shahi Lecturer, Department of Computer

More information

ECE573 Introduction to Compilers & Translators

ECE573 Introduction to Compilers & Translators ECE573 Introduction to Compilers & Translators Tentative Syllabus Fall 2005 Tu/Th 9:00-10:15 AM, EE 115 Instructor Prof. R. Eigenmann Tel 49-41741 Email eigenman@ecn Office EE334C Office Hours Tu 10:15-11:30

More information

The structure of a compiler

The structure of a compiler The structure of a compiler O(n) A compiler is a lot of fast stuff followed by hard problems scanning parsing intermediate code generation Polynomial time Code optimization: local dataflow, global dataflow,

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

Advanced Compiler Construction

Advanced Compiler Construction CS 526 Advanced Compiler Construction http://misailo.cs.illinois.edu/courses/cs526 INTERPROCEDURAL ANALYSIS The slides adapted from Vikram Adve So Far Control Flow Analysis Data Flow Analysis Dependence

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

The Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer

The Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer Evaluation and universal machines What is the role of evaluation in defining a language? How can we use evaluation to design a language? The Eval/Apply Cycle Eval Exp & env Apply Proc & args Eval and Apply

More information

Functional Programming in Haskell for A level teachers

Functional Programming in Haskell for A level teachers Functional Programming in Haskell for A level teachers About this document Functional Programming is now part of the A level curriculum. This document is intended to get those who already have some programming

More information

ECE Fall 20l2, Second Exam

ECE Fall 20l2, Second Exam ECE 30862 Fall 20l2, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 12:20 to take this exam. Your exam should have 16 pages total (including this cover

More information

Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus. Variables and Functions. cs3723 1 Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

More information

Code Optimization. Code Optimization

Code Optimization. Code Optimization 161 Code Optimization Code Optimization 162 Two steps: 1. Analysis (to uncover optimization opportunities) 2. Optimizing transformation Optimization: must be semantically correct. shall improve program

More information

Faculty of Science FINAL EXAMINATION

Faculty of Science FINAL EXAMINATION Faculty of Science FINAL EXAMINATION COMPUTER SCIENCE COMP 250 INTRODUCTION TO COMPUTER SCIENCE Examiner: Prof. Michael Langer April 27, 2010 Associate Examiner: Mr. Joseph Vybihal 9 A.M. 12 P.M. Instructions:

More information

Calvin Lin The University of Texas at Austin

Calvin Lin The University of Texas at Austin Interprocedural Analysis Last time Introduction to alias analysis Today Interprocedural analysis March 4, 2015 Interprocedural Analysis 1 Motivation Procedural abstraction Cornerstone of programming Introduces

More information

Compiler Theory Introduction and Course Outline Sandro Spina Department of Computer Science

Compiler Theory Introduction and Course Outline Sandro Spina Department of Computer Science Compiler Theory 001 - Introduction and Course Outline Sandro Spina Department of Computer Science ( course Books (needed during this My slides are based on the three books: Compilers: Principles, techniques

More information

Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems

Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems University of California, Berkeley College of Engineering Computer Science Division EECS Spring 2016 Anthony D. Joseph Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems Your Name: SID AND

More information

Interprocedural Analysis. Motivation. Interprocedural Analysis. Function Calls and Pointers

Interprocedural Analysis. Motivation. Interprocedural Analysis. Function Calls and Pointers Interprocedural Analysis Motivation Last time Introduction to alias analysis Today Interprocedural analysis Procedural abstraction Cornerstone of programming Introduces barriers to analysis Example x =

More information

Introduction to Optimization Local Value Numbering

Introduction to Optimization Local Value Numbering COMP 506 Rice University Spring 2018 Introduction to Optimization Local Value Numbering source IR IR target code Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights

More information

COMP 3141 Software System Design and Implementation

COMP 3141 Software System Design and Implementation Student Number: Family Name: Given Names: Signature: THE UNIVERSITY OF NEW SOUTH WALES Sample Exam 2018 Session 1 COMP 3141 Software System Design and Implementation Time allowed: 2 hours, plus 10 minutes

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

C The new standard

C The new standard C++11 - The new standard Lars Kühne Institut für Informatik Lehrstuhl für theoretische Informatik II Friedrich-Schiller-Universität Jena January 16, 2013 Overview A little bit of history: C++ was initially

More information

CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

More information

CS 426 Fall Machine Problem 4. Machine Problem 4. CS 426 Compiler Construction Fall Semester 2017

CS 426 Fall Machine Problem 4. Machine Problem 4. CS 426 Compiler Construction Fall Semester 2017 CS 426 Fall 2017 1 Machine Problem 4 Machine Problem 4 CS 426 Compiler Construction Fall Semester 2017 Handed out: November 16, 2017. Due: December 7, 2017, 5:00 p.m. This assignment deals with implementing

More information

LECTURE NOTES ON COMPILER DESIGN P a g e 2

LECTURE NOTES ON COMPILER DESIGN P a g e 2 LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER

More information

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7 Compiler Optimizations Chapter 8, Section 8.5 Chapter 9, Section 9.1.7 2 Local vs. Global Optimizations Local: inside a single basic block Simple forms of common subexpression elimination, dead code elimination,

More information

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc CS61C L4 C Pointers (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Strings, Arrays, & Malloc Albert Chae Instructor 2008-06-26 Review: C Strings A string in C is just an array

More information

R O O T S Interprocedural Analysis

R O O T S Interprocedural Analysis R O O T S Interprocedural Analysis Aleksandra Biresev s6albire@cs.uni-bonn.de Interprocedural Analysis An interprocedural analysis operates across an entire program, flowing information from call sites

More information

I m sure you have been annoyed at least once by having to type out types like this:

I m sure you have been annoyed at least once by having to type out types like this: Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more

More information

Appendix B Boost.Python

Appendix B Boost.Python Financial Modelling in Python By S. Fletcher & C. Gardner 2009 John Wiley & Sons Ltd Appendix B Boost.Python The Boost.Python library provides a framework for seamlessly wrapping C++ classes, functions

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1 COMP6771 Advanced C++ Programming Week 11 Object Oriented Programming 2016 www.cse.unsw.edu.au/ cs6771 2 Covariants and Contravariants Let us assume that Class B is a subtype of class A. Covariants:

More information

Lecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations

Lecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations Lecture Outline Intermediate code Intermediate Code & Local Optimizations Lecture 14 Local optimizations Next time: global optimizations Prof. Aiken CS 143 Lecture 14 1 Prof. Aiken CS 143 Lecture 14 2

More information

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End COMP 412 FALL 2017 Code Shape Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at

More information

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information

Binghamton University. CS-140 Fall Functional Java

Binghamton University. CS-140 Fall Functional Java Functional Java 1 First Class Data We have learned how to manipulate data with programs We can pass data to methods via arguments We can return data from methods via return types We can encapsulate data

More information

CSE 303, Winter 2006, Final Examination 16 March Please do not turn the page until everyone is ready.

CSE 303, Winter 2006, Final Examination 16 March Please do not turn the page until everyone is ready. CSE 303, Winter 2006, Final Examination 16 March 2006 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

More information

Functional Java Lambda Expressions

Functional Java Lambda Expressions Functional Java Lambda Expressions 1 Functions as a First Class Citizen If there was just some way of packaging the compare function And then passing that function as an argument to sort Then we wouldn

More information

MIT Introduction to Program Analysis and Optimization. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

MIT Introduction to Program Analysis and Optimization. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology MIT 6.035 Introduction to Program Analysis and Optimization Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Program Analysis Compile-time reasoning about run-time behavior

More information

Pointers. Pointers. Pointers (cont) CS 217

Pointers. Pointers. Pointers (cont) CS 217 Pointers CS 217 Pointers Variables whose values are the addresses of variables Operations address of (reference) & indirection (dereference) * arithmetic +, - Declaration mimics use char *p; *p is a char,

More information

A brief introduction to C++

A brief introduction to C++ A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne

More information

Lecture: Functional Programming

Lecture: Functional Programming Lecture: Functional Programming This course is an introduction to the mathematical foundations of programming languages and the implementation of programming languages and language-based tools. We use

More information

CO444H. Ben Livshits. Datalog Pointer analysis

CO444H. Ben Livshits. Datalog Pointer analysis CO444H Ben Livshits Datalog Pointer analysis 1 Call Graphs Class analysis: Given a reference variable x, what are the classes of the objects that x refers to at runtime? We saw CHA and RTA Deal with polymorphic/virtual

More information

Patterns for polymorphic operations

Patterns for polymorphic operations Patterns for polymorphic operations Three small object structural patterns for dealing with polymorphism Alexander A. Horoshilov hor@epsylontech.com Abstract Polymorphism is one of the main elements of

More information