DATA FLOW GRAPH

5.4 DATA FLOW GRAPH

In this section, we explain the main ideas in a data flow graph and a method to draw it. In practice, programmers may not draw data flow graphs by hand. Instead, language translators are modified to produce data flow graphs from program units.

A data flow graph is drawn with the objective of identifying data definitions and their uses as motivated in the preceding section. Each occurrence of a data variable is classified as follows:

Definition : This occurs when a value is moved into the memory location of the variable. Referring to the C function VarTypes() in Figure 5.3, the assignment statement i = x; is an example of definition of the variable i .

Undefinition or Kill : This occurs when the value and the location become unbound. Referring to the C function VarTypes(), the first

(iptr = malloc(sizeof(int));

117 int VarTypes(int x, int y){

5.4 DATA FLOW GRAPH

int i; int *iptr; i = x; iptr = malloc(sizeof(int)); *iptr = i + x; if (*iptr > y)

return (x); else { iptr = malloc(sizeof(int)); *iptr = x + y; return(*iptr); }

} Figure 5.3 Definition and uses of variables.

statement initializes the integer pointer variable iptr and iptr = i + x; initializes the value of the location pointed to by iptr. The second iptr = malloc(sizeof(int)); statement redefines variable iptr, thereby undefining the location previ-

ously pointed to by iptr. Use : This occurs when the value is fetched from the memory location of the

variable. There are two forms of uses of a variable as explained below. • Computation use (c-use): This directly affects the computation being

performed. In a c-use, a potentially new value of another variable or of the same variable is produced. Referring to the C function VarTypes(), the statement

*iptr = i + x; gives examples of c-use of variables i and x .

• Predicate use (p-use): This refers to the use of a variable in a predicate controlling the flow of execution. Referring to the C function VarTypes(), the statement

if (*iptr > y) ... gives examples of p-use of variables y and iptr.

A data flow graph is a directed graph constructed as follows:

A sequence of definitions and c-uses is associated with each node of the graph.

A set of p-uses is associated with each edge of the graph.

118 CHAPTER 5 DATA FLOW TESTING

• The entry node has a definition of each parameter and each nonlocal vari- able which occurs in the subprogram.

• The exit node has an undefinition of each local variable.

Example: We show the data flow graph in Figure 5.4 for the ReturnAverage() example discussed in Chapter 4, The initial node, node 1, represents initialization of the input vector < value, AS, MIN, MAX > . Node 2 represents the initialization of the four local variables i , ti, tv, and sum in the routine. Next we introduce a NULL node, node 3, keeping in mind that control will come back to the beginning of the while loop. Node 3 also denotes the fact that program control exits from the while loop at the NULL node. The statement ti++ is represented by node 4. The predicate associated with edge (3, 4) is the condition part of the while loop, namely,

((ti < AS) && (value[i] != -999)) Statements tv++ and sum = sum + value[i] are represented by node 5.

Therefore, the condition part of the first if statement forms the predicate associated with edge (4, 5), namely,

1 Initialize: value[], AS, MIN, MAX

True 2 i = 0, ti = 0,

tv = 0, sum = 0 True

NULL

~((ti < AS) &&

((ti < AS) &&

(value[i] != −999)) (value[i] != −999))

NULL

7 4 ti++

~(tv > 0) (tv > 0)

((value[i] >= MIN) &&

5 ~((value[i] >= MIN) && (value[i] <= MAX)) av = (double)

8 9 (value[i] <= MAX))

− 999 av = (double)sum/tv

tv++

sum = sum + value[i]

True True

True

6 True 10 i++

return(av)

Figure 5.4 Data flow graph of ReturnAverage() example.

119 ((value[i] >= MIN) && (value[i] <= MAX))

5.5 DATA FLOW TERMS

The statement i++ is represented by node 6. The predicate associated with edge (4, 6) is the negation of the condition part of the if statement, namely,

((value[i] >= MIN) && (value[i] <= MAX)). The predicate associated with edge (5, 6) is true because there is an uncondi-

tional flow of control from node 5 to node 6. Execution of the while loop terminates when its condition evaluates to false. Therefore, the predicate associated with edge (3, 7) is the negation of the predicate associated with edge (3, 4), namely,

~ ((ti < AS) && (value[i] != -999)) It may be noted that there is no computation performed in a NULL node.

Referring to the second if statement, av = (double) − 999 is represented by node

8 , and av = (double) sum/tv is represented by node 9. Therefore, the predicate associated with edge (7, 9) is

(tv > 0), and the predicate associated with edge (7, 8) is ~ (tv > 0).

Finally, the return(av) statement is represented by node 10, and the predicate True is associated with both the edges (7, 8) and (7, 9).

Dokumen yang terkait

ANALISIS DANA PIHAK KETIGA PADA PERBANKAN SYARIAH DI INDONESIA PERIODE TRIWULAN I 2002 – TRIWULAN IV 2007

40 502 17

ANALISIS KEMAMPUAN SISWA SMP DALAM MENYELESAIKAN SOAL PISA KONTEN SHAPE AND SPACE BERDASARKAN MODEL RASCH

69 778 11

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

STUDI PENJADWALAN DAN RENCANA ANGGARAN BIAYA (RAB) PADA PROYEK PEMBANGUNAN PUSAT PERDAGANGAN CIREBON RAYA (PPCR) CIREBON – JAWA BARAT

34 235 1

PENGARUH PENGGUNAAN BLACKBERRY MESSENGER TERHADAP PERUBAHAN PERILAKU MAHASISWA DALAM INTERAKSI SOSIAL (Studi Pada Mahasiswa Jurusan Ilmu Komunikasi Angkatan 2008 Universitas Muhammadiyah Malang)

127 505 26

AN ANALYSIS OF DESCRIPTIVE TEXT WRITING COMPOSED BY THE HIGH AND THE LOW ACHIEVERS OF THE EIGHTH GRADE STUDENTS OF SMPN SUKORAMBI JEMBER

11 83 16

AN ANALYSIS OF LANGUAGE CONTENT IN THE SYLLABUS FOR ESP COURSE USING ESP APPROACH THE SECRETARY AND MANAGEMENT PROGRAM BUSINESS TRAINING CENTER (BTC) JEMBER IN ACADEMIC YEAR OF 2000 2001

3 95 76

A DISCOURSE ANALYSIS ON “SPA: REGAIN BALANCE OF YOUR INNER AND OUTER BEAUTY” IN THE JAKARTA POST ON 4 MARCH 2011

9 161 13

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

THE INTEGRATION BETWEEN INDONESIA AND WORLD RICE MARKET

1 88 12