Still haven't worked all the bugs out of MLP's support for method calls, but stable...
[IRC.git] / Robust / src / Analysis / MLP / CodePlan.java
1 package Analysis.MLP;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8
9 // a code plan contains information based on analysis results
10 // for injecting code before and/or after a flat node
11 public class CodePlan {
12     
13   private Hashtable< VariableSourceToken, Set<TempDescriptor> > stall2copySet;
14   private Set<TempDescriptor>                                   dynamicStallSet;
15   private Hashtable<TempDescriptor, TempDescriptor>             dynAssign_lhs2rhs;
16   private FlatSESEEnterNode                                     currentSESE;
17   
18   public CodePlan( FlatSESEEnterNode fsen ) {
19     stall2copySet     = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
20     dynamicStallSet   = new HashSet<TempDescriptor>();
21     dynAssign_lhs2rhs = new Hashtable<TempDescriptor, TempDescriptor>();
22     currentSESE       = fsen;
23   }
24
25   public FlatSESEEnterNode getCurrentSESE() {
26     return currentSESE;
27   }
28   
29   public void addStall2CopySet( VariableSourceToken stallToken,
30                                 Set<TempDescriptor> copySet ) {
31
32     if( stall2copySet.containsKey( stallToken ) ) {
33       Set<TempDescriptor> priorCopySet = stall2copySet.get( stallToken );
34       priorCopySet.addAll( copySet );
35     } else {
36       stall2copySet.put( stallToken, copySet );
37     }
38   }
39
40   public Set<VariableSourceToken> getStallTokens() {
41     return stall2copySet.keySet();
42   }
43
44   public Set<TempDescriptor> getCopySet( VariableSourceToken stallToken ) {
45     return stall2copySet.get( stallToken );
46   }
47
48
49   public void addDynamicStall( TempDescriptor var ) {
50     dynamicStallSet.add( var );
51   }
52
53   public Set<TempDescriptor> getDynamicStallSet() {
54     return dynamicStallSet;
55   }
56
57   public void addDynAssign( TempDescriptor lhs,
58                             TempDescriptor rhs ) {
59     dynAssign_lhs2rhs.put( lhs, rhs );
60   }
61
62   public Hashtable<TempDescriptor, TempDescriptor> getDynAssigns() {
63     return dynAssign_lhs2rhs;
64   }
65
66   public boolean equals( Object o ) {
67     if( o == null ) {
68       return false;
69     }
70
71     if( !(o instanceof CodePlan) ) {
72       return false;
73     }
74
75     CodePlan cp = (CodePlan) o;
76
77     boolean copySetsEq = (stall2copySet.equals( cp.stall2copySet ));
78
79     boolean dynStallSetEq = (dynamicStallSet.equals( cp.dynamicStallSet ));
80
81     boolean dynAssignEq = (dynAssign_lhs2rhs.equals( cp.dynAssign_lhs2rhs ));
82         
83     return copySetsEq && dynStallSetEq && dynAssignEq;
84   }
85
86   public int hashCode() {
87
88     int copySetsHC = stall2copySet.hashCode();
89
90     int dynStallSetHC = dynamicStallSet.hashCode();
91
92     int dynAssignHC = dynAssign_lhs2rhs.hashCode();
93
94     int hash = 7;
95     hash = 31*hash + copySetsHC;
96     hash = 31*hash + dynStallSetHC;
97     hash = 31*hash + dynAssignHC;
98     return hash;
99   }
100
101   public String toString() {
102     String s = " PLAN: ";
103
104     if( !stall2copySet.entrySet().isEmpty() ) {
105       s += "[STATIC STALLS:";
106     }
107     Iterator cpsItr = stall2copySet.entrySet().iterator();
108     while( cpsItr.hasNext() ) {
109       Map.Entry           me         = (Map.Entry)           cpsItr.next();
110       VariableSourceToken stallToken = (VariableSourceToken) me.getKey();
111       Set<TempDescriptor> copySet    = (Set<TempDescriptor>) me.getValue();
112
113       s += "("+stallToken+"->"+copySet+")";
114     }
115     if( !stall2copySet.entrySet().isEmpty() ) {
116       s += "]";
117     }
118
119     if( !dynamicStallSet.isEmpty() ) {
120       s += "[DYN STALLS:"+dynamicStallSet+"]";
121     }
122
123     if( !dynAssign_lhs2rhs.isEmpty() ) {
124       s += "[DYN ASSIGNS:"+dynAssign_lhs2rhs+"]";
125     }
126
127     return s;
128   }
129 }