Saturday, 13 January 2018

data flow analysis in c program


Ex. No: 7 B
Date:
7B.  Implement Data flow analysis 

AIM:

  To write a C program to implement Data Flow Analysis.


INTRODUCTION:

Data flow analysis is a technique for gathering information about the possible set of value calculated at various points in a computer program.

ALGORITHM:

Step-1: Start the Program Execution.
Step-2: Read the total Numbers of Expression 
Step-3: Read the Left and Right side of Each Expressions 
Step-4: Display the Expressions with Line No
Step-5: Display the Data flow movement with Particular Expressions 
Step-6: Stop the Program Execution.


PROGRAM

#include <stdio.h>
#include <conio.h>
#include <string.h >
struct op
{
char l[20];
char r[20];
}
op[10], pr[10];

void main()
{
int a, i, k, j, n, z = 0, m, q,lineno=1;
char * p, * l;
char temp, t;
char * tem;char *match;
clrscr();
printf("enter no of values");
scanf("%d", & n);
for (i = 0; i < n; i++)
{
printf("\tleft\t");
scanf("%s",op[i].l);
printf("\tright:\t");
scanf("%s", op[i].r);
}
printf("intermediate Code\n");
for (i = 0; i < n; i++)
{   printf("Line No=%d\n",lineno);
printf("\t\t\t%s=", op[i].l);
printf("%s\n", op[i].r);lineno++;
}
printf("***Data Flow Analysis for the Above Code ***\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
match=strstr(op[j].r,op[i].l);
if(match)
{
printf("\n %s is live at  %s \n ", op[i].l,op[j].r);
}
}
}}
OUTPUT:

Enter no of values
4
        left    a
        right:  a+b
        left    b
        right:  a+c
        left    c
        right:  a+b
        left    d
        right:  b+c+d
 Line No=1
 a=a+b
 Line No=2
 b=a+c
Line No=3
                        c=a+b
Line No=4
                        d=b+c+d
***Data Flow Analysis for the Above Code ***

 a is live at  a+b

 a is live at  a+c

 a is live at  a+b

 b is live at  a+b

 b is live at  a+b

 b is live at  b+c+d

 c is live at  a+c

 c is live at  b+c+d

 d is live at  b+c+d



RESULT:

Thus the above program is compiled and executed successfully and output is verified.

No comments:

Post a Comment

11. Implementation of Simple Code Optimization Techniques (Constant Folding.,etc.)

Ex. No: 11 Date:                   11. Implementation of Simple Code Optimization Techniques (Constant Folding.,etc.) ...