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;
11 public class FlatFlagActionNode extends FlatNode {
12 Hashtable<TempFlagPair, Boolean> tempflagpairs;
13 Hashtable<TempTagPair, Boolean> temptagpairs;
16 public static final int NEWOBJECT=0;
17 public static final int PRE=1;
18 public static final int TASKEXIT=2;
20 Hashtable<ClassDescriptor, Vector<FlagState>> cd2initfs;
21 Hashtable<ClassDescriptor, Vector<FlagState>> cd2fs4new;
22 Hashtable<FlagState, Vector<FlagState>> fs2fs;
25 public FlatFlagActionNode(int taskexit) {
26 tempflagpairs=new Hashtable<TempFlagPair, Boolean>();
27 temptagpairs=new Hashtable<TempTagPair, Boolean>();
28 this.taskexit=taskexit;
30 this.cd2initfs = null;
31 this.cd2fs4new = null;
35 public int getTaskType() {
39 public Vector<FlagState> getInitFStates(ClassDescriptor cd) {
40 if(this.cd2initfs == null) {
41 this.cd2initfs = new Hashtable<ClassDescriptor, Vector<FlagState>>();
43 if(this.cd2initfs.get(cd) == null) {
44 this.cd2initfs.put(cd, new Vector<FlagState>());
46 return this.cd2initfs.get(cd);
49 public Vector<FlagState> getTargetFStates4NewObj(ClassDescriptor cd) {
50 if(this.cd2fs4new == null) {
51 this.cd2fs4new = new Hashtable<ClassDescriptor, Vector<FlagState>>();
53 if(this.cd2fs4new.get(cd) == null) {
54 this.cd2fs4new.put(cd, new Vector<FlagState>());
56 return this.cd2fs4new.get(cd);
59 public Vector<FlagState> getTargetFStates(FlagState fs) {
60 if(this.fs2fs == null) {
61 this.fs2fs = new Hashtable<FlagState, Vector<FlagState>>();
63 if(this.fs2fs.get(fs) == null) {
64 this.fs2fs.put(fs, new Vector<FlagState>());
66 return this.fs2fs.get(fs);
69 public void addFlagAction(TempDescriptor td, FlagDescriptor fd, boolean status) {
70 TempFlagPair tfp=new TempFlagPair(td,fd);
71 if (tempflagpairs.containsKey(tfp)) {
72 throw new Error("Temp/Flag combination used twice: "+tfp);
74 tempflagpairs.put(tfp, new Boolean(status));
77 public void addTagAction(TempDescriptor td, TagDescriptor tagd, TempDescriptor tagt, boolean status) {
78 TempTagPair ttp=new TempTagPair(td,tagd, tagt);
79 if (temptagpairs.containsKey(ttp)) {
80 throw new Error("Temp/Tag combination used twice: "+ttp);
82 temptagpairs.put(ttp, new Boolean(status));
86 return FKind.FlatFlagActionNode;
89 /** This method returns an iterator over the Temp/Flag pairs. */
91 public Iterator<TempFlagPair> getTempFlagPairs() {
92 return tempflagpairs.keySet().iterator();
95 public Iterator<TempTagPair> getTempTagPairs() {
96 return temptagpairs.keySet().iterator();
99 public boolean getFlagChange(TempFlagPair tfp) {
100 return ((Boolean)tempflagpairs.get(tfp)).booleanValue();
103 public boolean getTagChange(TempTagPair ttp) {
104 return ((Boolean)temptagpairs.get(ttp)).booleanValue();
107 public TempDescriptor [] readsTemps() {
108 if (tempflagpairs.size()==0)
109 return new TempDescriptor [0];
111 HashSet temps=new HashSet();
112 for(Iterator it=tempflagpairs.keySet().iterator(); it.hasNext();) {
113 TempFlagPair tfp=(TempFlagPair)it.next();
114 temps.add(tfp.getTemp());
116 for(Iterator it=temptagpairs.keySet().iterator(); it.hasNext();) {
117 TempTagPair ttp=(TempTagPair)it.next();
118 temps.add(ttp.getTemp());
119 temps.add(ttp.getTagTemp());
121 return (TempDescriptor[])temps.toArray(new TempDescriptor [temps.size()]);
125 public int getFFANType() {
126 throw new Error("Use getTaskType() instead and remove this method");
129 public String toString() {
130 String st="FlatFlagActionNode_";
131 for(Iterator it=tempflagpairs.keySet().iterator(); it.hasNext();) {
132 TempFlagPair tfp=(TempFlagPair)it.next();
133 st+=getFlagChange(tfp) ? "" : "!";
134 st+=tfp.getTemp()+" "+tfp.getFlag()+",";
136 for(Iterator it=temptagpairs.keySet().iterator(); it.hasNext();) {
137 TempTagPair ttp=(TempTagPair)it.next();
138 st+=getTagChange(ttp) ? "" : "!";
139 st+=ttp.getTemp()+" "+ttp.getTag()+"("+ttp.getTagTemp()+"),";