getting definite reach analysis set up as a fixed point piggy-back to disjoint
[IRC.git] / Robust / src / Analysis / Disjoint / DefiniteReachAnalysis.java
1 package Analysis.Disjoint;
2
3 import java.util.*;
4
5 import IR.*;
6 import IR.Flat.*;
7 import Util.*;
8
9
10 public class DefiniteReachAnalysis {
11   
12   // keep a state of definite reachability analysis for
13   // every program point
14   private Map<FlatNode, DefiniteReachState> fn2state;
15   
16   public DefiniteReachAnalysis() {
17     fn2state = new HashMap<FlatNode, DefiniteReachState>();
18   }
19
20
21   public void methodEntry( FlatNode fn, 
22                            Set<TempDescriptor> parameters ) {
23     DefiniteReachState state = get( fn );
24     state.methodEntry( parameters );
25     fn2state.put( fn, state );
26   }
27
28   public void copy( FlatNode fn, 
29                     TempDescriptor x,
30                     TempDescriptor y ) {
31     DefiniteReachState state = makeIn( fn );
32     state.copy( x, y );
33     fn2state.put( fn, state ); 
34   }
35
36   public void load( FlatNode fn, 
37                     TempDescriptor  x,
38                     TempDescriptor  y,
39                     FieldDescriptor f ) {
40     DefiniteReachState state = makeIn( fn );
41     state.load( x, y, f );
42     fn2state.put( fn, state ); 
43   }
44
45   public void store( FlatNode fn, 
46                      TempDescriptor  x,
47                      FieldDescriptor f,
48                      TempDescriptor  y ) {
49     DefiniteReachState state = makeIn( fn );
50     state.store( x, f, y );
51     fn2state.put( fn, state ); 
52   }
53
54   public void newObject( FlatNode fn, 
55                          TempDescriptor x ) {
56     DefiniteReachState state = makeIn( fn );
57     state.newObject( x );
58     fn2state.put( fn, state ); 
59   }
60
61   // x is the return value, x = foo(...);
62   public void methodCall( FlatNode fn, 
63                           TempDescriptor x ) {
64     DefiniteReachState state = makeIn( fn );
65     state.methodCall( x );
66     fn2state.put( fn, state ); 
67   }
68
69
70   // get the current state for just after the given
71   // program point
72   private DefiniteReachState get( FlatNode fn ) {
73     DefiniteReachState state = fn2state.get( fn );
74     if( state == null ) {
75       state = new DefiniteReachState();
76       fn2state.put( fn, state );
77     }
78     return state;
79   }
80
81   // get the current state for the program point just
82   // before the given program point by merging the out
83   // states of the predecessor statements
84   private DefiniteReachState makeIn( FlatNode fn ) {
85     DefiniteReachState stateIn = new DefiniteReachState();
86     for( int i = 0; i < fn.numPrev(); ++i ) {
87       stateIn.merge( get( fn.getPrev( i ) ) );
88     }
89     return stateIn;
90   }
91 }