07 Functions

# 07 Functions - Course Outline Introduction Control-flow...

This preview shows pages 1–11. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Course Outline Introduction Control-flow analysis Dataflow analysis and abstract interpretation Sparse analysis Adding indirection (pointers) Adding functions Type- and constraint-based analysis Ben Hardekopf () CS 290C Program Analysis Fall 2011 1 / 49 Section Outline Functions Extending Lingo Control-flow Redux Context-Sensitive Analysis Functions + Pointers Ben Hardekopf () CS 290C Program Analysis Fall 2011 2 / 49 Extending Lingo with Functions Syntax n ∈ Z b ∈ B x ∈ Variable ⊕ ∈ Op ::= + | - | * | / | < | < = | = | ! = | && | || e ∈ Exp ::= n | b | x | e ⊕ e rhs ∈ Rhs ::= e | x 1 ( x 2 ,... ) c ∈ Cmd ::= c ; c | x := rhs | skip | while ( e ) do { c } | if ( e ) then { c } else { c } f ∈ FDef ::= def x 1 = fun ( x 2 ,... ) { c ; return x 3 } p ∈ Prog ::= c | f · p Ben Hardekopf () CS 290C Program Analysis Fall 2011 3 / 49 Example Example (Lingo with Functions) def id = fun (p) { q := p ; return q } def main = fun (dummy_arg) { x := 1 ; y := 2 ; a := id(x) ; b := id(y) ; return dummy_arg } dummy := 0 ; result := main(dummy) Ben Hardekopf () CS 290C Program Analysis Fall 2011 4 / 49 Example Example (Lingo with Functions) def id = fun (p) { q := p ; return q } def main = fun (dummy_arg) { x := 1 ; y := 2 ; a := id(x) ; b := id(y) ; return dummy_arg } dummy := 0 ; result := main(dummy) For simplicity, we require: Functions have ≥ 1 parameter(s) and exactly one return statement Function arguments and return values are variables Function calls are only on the right-hand side of an assignment Ben Hardekopf () CS 290C Program Analysis Fall 2011 4 / 49 Section Outline Functions Extending Lingo Control-flow Redux Context-Sensitive Analysis Functions + Pointers Ben Hardekopf () CS 290C Program Analysis Fall 2011 5 / 49 Interprocedural Control-Flow Now that we have functions, we need to represent control-flow caused by function calls and function returns. There are two main choices: Call-Graph Interprocedural CFG Ben Hardekopf () CS 290C Program Analysis Fall 2011 6 / 49 Call-Graph Definition (Call-Graph) Formally, a call-graph G = ( N , E ) is: A set of nodes N , one for each function A set of edges E ⊆ N × N , such that x → y iff function x contains a call to function y Ben Hardekopf () CS 290C Program Analysis Fall 2011 7 / 49 Call-Graph Definition (Call-Graph) Formally, a call-graph G = ( N , E ) is: A set of nodes N , one for each function A set of edges E ⊆ N × N , such that x → y iff function x contains a call to function y This is a coarse representation of control-flow (there is no indication of how many calls exist in a function or where they occur). Note that: Unlike the CFG, control passes back from destination to source Cycles in the call-graph correspond to recursive functions Ben Hardekopf () CS 290C Program Analysis Fall 2011 7 / 49 Example Draw the call-graph for the following program: Program def id = fun (p) { q := p ; return q } x := 1 ; y := 2 ; a := id(x) ; b := id(y) Ben Hardekopf () CS 290C Program Analysis Fall 2011 8 / 49 Interprocedural Control-Flow...
View Full Document

{[ snackBarMessage ]}

### Page1 / 67

07 Functions - Course Outline Introduction Control-flow...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online