more changes
[IRC.git] / Robust / src / Analysis / Pointer / Delta.java
1 package Analysis.Pointer;
2 import java.util.*;
3 import Analysis.Pointer.AllocFactory.AllocNode;
4 import Analysis.Pointer.BasicBlock.BBlock;
5 import IR.Flat.*;
6
7 public class Delta {
8   HashMap<AllocNode, MySet<Edge>> heapedgeremove;
9   HashMap<AllocNode, MySet<Edge>> heapedgeadd;
10   HashMap<TempDescriptor, MySet<Edge>> varedgeadd;
11   HashMap<TempDescriptor, MySet<Edge>> varedgeremove;
12   HashMap<AllocNode, MySet<Edge>> baseheapedge;
13   HashMap<TempDescriptor, MySet<Edge>> basevaredge;
14   HashSet<AllocNode> baseNodeAges;
15   HashSet<AllocNode> addNodeAges;
16   HashMap<AllocNode, Boolean> baseOldNodes;
17   HashMap<AllocNode, Boolean> addOldNodes;
18
19
20   boolean init;
21   PPoint block;
22   boolean callStart;
23
24   /* Init is set for false for delta propagations inside of one basic block.
25    */
26   
27   public Delta(PPoint block, boolean init) {
28     this.init=init;
29     this.baseheapedge=new HashMap<AllocNode, MySet<Edge>>();
30     this.basevaredge=new HashMap<TempDescriptor, MySet<Edge>>();
31     this.heapedgeadd=new HashMap<AllocNode, MySet<Edge>>();
32     this.heapedgeremove=new HashMap<AllocNode, MySet<Edge>>();
33     this.varedgeadd=new HashMap<TempDescriptor, MySet<Edge>>();
34     this.varedgeremove=new HashMap<TempDescriptor, MySet<Edge>>();
35     this.baseNodeAges=new HashSet<AllocNode>();
36     this.addNodeAges=new HashSet<AllocNode>();
37     this.baseOldNodes=new HashMap<AllocNode, Boolean>();
38     this.addOldNodes=new HashMap<AllocNode, Boolean>();
39     this.block=block;
40   }
41
42   private Delta() {
43   }
44
45   public PPoint getBlock() {
46     return block;
47   }
48
49   public void setBlock(PPoint block) {
50     this.block=block;
51   }
52
53   public Delta changeParams(HashMap<TempDescriptor, TempDescriptor> tmpMap, PPoint bblock) {
54     Delta newdelta=new Delta();
55     newdelta.baseheapedge=baseheapedge;
56     newdelta.basevaredge=basevaredge;
57     newdelta.heapedgeadd=heapedgeadd;
58     newdelta.heapedgeremove=heapedgeremove;
59     //Update variable edge mappings
60     newdelta.varedgeadd=new HashMap<TempDescriptor, MySet<Edge>>();
61     for(Map.Entry<TempDescriptor, MySet<Edge>> entry:varedgeadd.entrySet()) {
62       varedgeadd.put(tmpMap.get(entry.getKey()), entry.getValue());
63     }
64     newdelta.varedgeremove=varedgeremove;
65     newdelta.block=bblock;
66     return newdelta;
67   }
68
69   public Delta buildBase(MySet<Edge> edges) {
70     Delta newdelta=new Delta();
71     newdelta.baseheapedge=baseheapedge;
72     newdelta.basevaredge=basevaredge;
73     newdelta.heapedgeadd=heapedgeadd;
74     newdelta.heapedgeremove=heapedgeremove;
75     newdelta.varedgeadd=varedgeadd;
76     for(Edge e:edges) {
77       if (e.srcvar!=null) {
78         if (!newdelta.varedgeadd.containsKey(e.srcvar)) {
79           newdelta.varedgeadd.put(e.srcvar, new MySet<Edge>());
80         }
81         newdelta.varedgeadd.get(e.srcvar).add(e);
82       } else {
83         if (!newdelta.heapedgeadd.containsKey(e.src)) {
84           newdelta.heapedgeadd.put(e.src, new MySet<Edge>());
85         }
86         newdelta.heapedgeadd.get(e.src).add(e);
87       }
88     }
89     return newdelta;
90   }
91
92   public Delta diffBlock(PPoint bblock) {
93     Delta newdelta=new Delta();
94     newdelta.baseheapedge=baseheapedge;
95     newdelta.basevaredge=basevaredge;
96     newdelta.heapedgeadd=heapedgeadd;
97     newdelta.heapedgeremove=heapedgeremove;
98     newdelta.varedgeadd=varedgeadd;
99     newdelta.varedgeremove=varedgeremove;
100     newdelta.block=bblock;
101     return newdelta;
102   }
103
104   public boolean getInit() {
105     return init;
106   }
107
108   public void setInit(boolean init) {
109     this.init=init;
110   }
111 }