This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 package IR.Flat;
2 import Analysis.TaskStateAnalysis.FlagState;
3 import IR.ClassDescriptor;
4 import IR.FlagDescriptor;
5 import IR.TagDescriptor;
6 import java.util.Hashtable;
7 import java.util.HashSet;
8 import java.util.Iterator;
9 import java.util.Vector;
10
11 public class FlatFlagActionNode extends FlatNode {
12   Hashtable<TempFlagPair, Boolean> tempflagpairs;
13   Hashtable<TempTagPair, Boolean> temptagpairs;
14
15   int taskexit;
16   public static final int NEWOBJECT=0;
17   public static final int PRE=1;
18   public static final int TASKEXIT=2;
19
20   Hashtable<ClassDescriptor, Vector<FlagState>> cd2initfs;
21   Hashtable<ClassDescriptor, Vector<FlagState>> cd2fs4new;
22   Hashtable<FlagState, Vector<FlagState>> fs2fs;
23
24   int m_taskexitindex;
25
26   public FlatFlagActionNode(int taskexit) {
27     tempflagpairs=new Hashtable<TempFlagPair, Boolean>();
28     temptagpairs=new Hashtable<TempTagPair, Boolean>();
29     this.taskexit=taskexit;
30
31     this.cd2initfs = null;
32     this.cd2fs4new = null;
33     this.fs2fs = null;
34     this.m_taskexitindex = 0;
35   }
36
37   public int getTaskExitIndex() {
38       return m_taskexitindex;
39   }
40
41   public void setTaskExitIndex(int taskexitindex) {
42       this.m_taskexitindex = taskexitindex;
43   }
44
45   public int getTaskType() {
46     return taskexit;
47   }
48
49   public Vector<FlagState> getInitFStates(ClassDescriptor cd) {
50     if(this.cd2initfs == null) {
51       this.cd2initfs = new Hashtable<ClassDescriptor, Vector<FlagState>>();
52     }
53     if(this.cd2initfs.get(cd) == null) {
54       this.cd2initfs.put(cd, new Vector<FlagState>());
55     }
56     return this.cd2initfs.get(cd);
57   }
58
59   public Vector<FlagState> getTargetFStates4NewObj(ClassDescriptor cd) {
60     if(this.cd2fs4new == null) {
61       this.cd2fs4new = new Hashtable<ClassDescriptor, Vector<FlagState>>();
62     }
63     if(this.cd2fs4new.get(cd) == null) {
64       this.cd2fs4new.put(cd, new Vector<FlagState>());
65     }
66     return this.cd2fs4new.get(cd);
67   }
68
69   public Vector<FlagState> getTargetFStates(FlagState fs) {
70     if(this.fs2fs == null) {
71       this.fs2fs = new Hashtable<FlagState, Vector<FlagState>>();
72     }
73     if(this.fs2fs.get(fs) == null) {
74       this.fs2fs.put(fs, new Vector<FlagState>());
75     }
76     return this.fs2fs.get(fs);
77   }
78
79   public void addFlagAction(TempDescriptor td, FlagDescriptor fd, boolean status) {
80     TempFlagPair tfp=new TempFlagPair(td,fd);
81     if (tempflagpairs.containsKey(tfp)) {
82       throw new Error("Temp/Flag combination used twice: "+tfp);
83     }
84     tempflagpairs.put(tfp, new Boolean(status));
85   }
86
87   public void addTagAction(TempDescriptor td, TagDescriptor tagd, TempDescriptor tagt, boolean status) {
88     TempTagPair ttp=new TempTagPair(td,tagd, tagt);
89     if (temptagpairs.containsKey(ttp)) {
90       throw new Error("Temp/Tag combination used twice: "+ttp);
91     }
92     temptagpairs.put(ttp, new Boolean(status));
93   }
94
95   public int kind() {
96     return FKind.FlatFlagActionNode;
97   }
98
99   /** This method returns an iterator over the Temp/Flag pairs. */
100
101   public Iterator<TempFlagPair> getTempFlagPairs() {
102     return tempflagpairs.keySet().iterator();
103   }
104
105   public Iterator<TempTagPair> getTempTagPairs() {
106     return temptagpairs.keySet().iterator();
107   }
108
109   public boolean getFlagChange(TempFlagPair tfp) {
110     return ((Boolean)tempflagpairs.get(tfp)).booleanValue();
111   }
112
113   public boolean getTagChange(TempTagPair ttp) {
114     return ((Boolean)temptagpairs.get(ttp)).booleanValue();
115   }
116
117   public TempDescriptor [] readsTemps() {
118     if (tempflagpairs.size()==0)
119       return new TempDescriptor [0];
120     else {
121       HashSet temps=new HashSet();
122       for(Iterator it=tempflagpairs.keySet().iterator(); it.hasNext();) {
123         TempFlagPair tfp=(TempFlagPair)it.next();
124         temps.add(tfp.getTemp());
125       }
126       for(Iterator it=temptagpairs.keySet().iterator(); it.hasNext();) {
127         TempTagPair ttp=(TempTagPair)it.next();
128         temps.add(ttp.getTemp());
129         temps.add(ttp.getTagTemp());
130       }
131       return (TempDescriptor[])temps.toArray(new TempDescriptor [temps.size()]);
132     }
133   }
134
135   public int getFFANType() {
136     throw new Error("Use getTaskType() instead and remove this method");
137   }
138
139   public String toString() {
140     String st="FlatFlagActionNode_";
141     for(Iterator it=tempflagpairs.keySet().iterator(); it.hasNext();) {
142       TempFlagPair tfp=(TempFlagPair)it.next();
143       st+=getFlagChange(tfp) ? "" : "!";
144       st+=tfp.getTemp()+" "+tfp.getFlag()+",";
145     }
146     for(Iterator it=temptagpairs.keySet().iterator(); it.hasNext();) {
147       TempTagPair ttp=(TempTagPair)it.next();
148       st+=getTagChange(ttp) ? "" : "!";
149       st+=ttp.getTemp()+" "+ttp.getTag()+"("+ttp.getTagTemp()+"),";
150     }
151
152     return st;
153   }
154 }