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;
26 public FlatFlagActionNode(int taskexit) {
27 tempflagpairs=new Hashtable<TempFlagPair, Boolean>();
28 temptagpairs=new Hashtable<TempTagPair, Boolean>();
29 this.taskexit=taskexit;
31 this.cd2initfs = null;
32 this.cd2fs4new = null;
34 this.m_taskexitindex = 0;
37 public int getTaskExitIndex() {
38 return m_taskexitindex;
41 public void setTaskExitIndex(int taskexitindex) {
42 this.m_taskexitindex = taskexitindex;
45 public int getTaskType() {
49 public Vector<FlagState> getInitFStates(ClassDescriptor cd) {
50 if(this.cd2initfs == null) {
51 this.cd2initfs = new Hashtable<ClassDescriptor, Vector<FlagState>>();
53 if(this.cd2initfs.get(cd) == null) {
54 this.cd2initfs.put(cd, new Vector<FlagState>());
56 return this.cd2initfs.get(cd);
59 public Vector<FlagState> getTargetFStates4NewObj(ClassDescriptor cd) {
60 if(this.cd2fs4new == null) {
61 this.cd2fs4new = new Hashtable<ClassDescriptor, Vector<FlagState>>();
63 if(this.cd2fs4new.get(cd) == null) {
64 this.cd2fs4new.put(cd, new Vector<FlagState>());
66 return this.cd2fs4new.get(cd);
69 public Vector<FlagState> getTargetFStates(FlagState fs) {
70 if(this.fs2fs == null) {
71 this.fs2fs = new Hashtable<FlagState, Vector<FlagState>>();
73 if(this.fs2fs.get(fs) == null) {
74 this.fs2fs.put(fs, new Vector<FlagState>());
76 return this.fs2fs.get(fs);
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);
84 tempflagpairs.put(tfp, new Boolean(status));
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);
92 temptagpairs.put(ttp, new Boolean(status));
96 return FKind.FlatFlagActionNode;
99 /** This method returns an iterator over the Temp/Flag pairs. */
101 public Iterator<TempFlagPair> getTempFlagPairs() {
102 return tempflagpairs.keySet().iterator();
105 public Iterator<TempTagPair> getTempTagPairs() {
106 return temptagpairs.keySet().iterator();
109 public boolean getFlagChange(TempFlagPair tfp) {
110 return ((Boolean)tempflagpairs.get(tfp)).booleanValue();
113 public boolean getTagChange(TempTagPair ttp) {
114 return ((Boolean)temptagpairs.get(ttp)).booleanValue();
117 public TempDescriptor [] readsTemps() {
118 if (tempflagpairs.size()==0)
119 return new TempDescriptor [0];
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());
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());
131 return (TempDescriptor[])temps.toArray(new TempDescriptor [temps.size()]);
135 public int getFFANType() {
136 throw new Error("Use getTaskType() instead and remove this method");
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()+",";
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()+"),";