{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

slides2

# slides2 - Principles of Program Analysis Data Flow Analysis...

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

Principles of Program Analysis: Data Flow Analysis Transparencies based on Chapter 2 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis . Springer Verlag 2005. c ± Flemming Nielson & Hanne Riis Nielson & Chris Hankin. PPA Chapter 2 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 1

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

View Full Document
Example Language Syntax of While-programs a ::= x | n | a 1 op a a 2 b ::= true | false | not b | b 1 op b b 2 | a 1 op r a 2 S ::= [ x := a ] ` | [ skip ] ` | S 1 ; S 2 | if [ b ] ` then S 1 else S 2 | while [ b ] ` do S Example: [ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) Abstract syntax – parentheses are inserted to disambiguate the syntax PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 2
Building an “Abstract Flowchart” Example: [ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) init ( ··· ) = 1 ﬁnal ( ) = { 2 } labels ( ) = { 1 , 2 , 3 , 4 } ﬂow ( ) = { (1 , 2) , (2 , 3) , (3 , 4) , (4 , 2) } ﬂow R ( ) = { (2 , 1) , (2 , 4) , (3 , 2) , (4 , 3) } [ x:=x-1 ] 4 [ z:=z*y ] 3 [ x>0 ] 2 [ z:=1 ] 1 ? ? ? - ? ? yes no PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 3

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

View Full Document
Initial labels init ( S ) is the label of the ﬁrst elementary block of S : init : Stmt Lab init ([ x := a ] ` ) = ` init ([ skip ] ` ) = ` init ( S 1 ; S 2 ) = init ( S 1 ) init ( if [ b ] ` then S 1 else S 2 ) = ` init ( while [ b ] ` do S ) = ` Example: init ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = 1 PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 4
Final labels ﬁnal ( S ) is the set of labels of the last elementary blocks of S : ﬁnal : Stmt → P ( Lab ) ﬁnal ([ x := a ] ` ) = { ` } ﬁnal ([ skip ] ` ) = { ` } ﬁnal ( S 1 ; S 2 ) = ﬁnal ( S 2 ) ﬁnal ( if [ b ] ` then S 1 else S 2 ) = ﬁnal ( S 1 ) ﬁnal ( S 2 ) ﬁnal ( while [ b ] ` do S ) = { ` } Example: ﬁnal ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = { 2 } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 5

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

View Full Document
Labels labels ( S ) is the entire set of labels in the statement S : labels : Stmt → P ( Lab ) labels ([ x := a ] ` ) = { ` } labels ([ skip ] ` ) = { ` } labels ( S 1 ; S 2 ) = labels ( S 1 ) labels ( S 2 ) labels ( if [ b ] ` then S 1 else S 2 ) = { ` } ∪ labels ( S 1 ) labels ( S 2 ) labels ( while [ b ] ` do S ) = { ` } ∪ labels ( S ) Example labels ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = { 1 , 2 , 3 , 4 } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 6
Flows and reverse ﬂows ﬂow ( S ) and ﬂow R ( S ) are representations of how control ﬂows in S : ﬂow , ﬂow R : Stmt → P ( Lab × Lab ) ﬂow ([ x := a ] ` ) = ﬂow ([ skip ] ` ) = ﬂow ( S 1 ; S 2 ) = ﬂow ( S 1 ) ﬂow ( S 2 ) ∪ { ( `, init ( S 2 )) | ` ﬁnal ( S 1 ) } ﬂow ( if [ b ] ` then S 1 else S 2 ) = ﬂow ( S 1 ) ﬂow ( S 2 ) ∪ { ( `, init ( S 1 )) , ( `, init ( S 2 )) } ﬂow ( while [ b ] ` do S ) = ﬂow ( S ) ∪ { ( `, init ( S )) } ∪ { ( ` 0 ,` ) | ` 0 ﬁnal ( S ) } ﬂow R ( S ) = { ( `,` 0 ) | ( ` 0 ) ﬂow ( S ) } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 7

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

View Full Document
Elementary blocks A statement consists of a set of elementary blocks blocks : Stmt → P ( Blocks ) blocks ([ x := a ] ` ) = { [ x := a ] ` } blocks ([ skip ] ` ) = { [ skip ] ` } blocks ( S 1 ; S 2 ) = blocks ( S 1 ) blocks ( S 2 ) blocks ( if [ b ] ` then S 1 else S 2 ) = { [ b ] ` } ∪ blocks ( S 1 ) blocks ( S 2 ) blocks ( while [ b ] ` do S ) = { [ b ] ` } ∪ blocks ( S ) A statement S is label consistent if and only if any two elementary statements [ S 1 ] ` and [ S 2 ] ` with the same label in S are equal: S 1 = S 2 A statement where all labels are unique is automatically label consistent PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 8
Intraprocedural Analysis Classical analyses: Available Expressions Analysis Reaching Deﬁnitions Analysis

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.

{[ snackBarMessage ]}

### Page1 / 151

slides2 - Principles of Program Analysis Data Flow Analysis...

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

View Full Document
Ask a homework question - tutors are online