1 package joeq.Compiler.Analysis.IPSSA;
2
3 import java.util.HashMap;
4 import joeq.Class.jq_LocalVarTableEntry;
5 import joeq.Class.jq_Method;
6 import joeq.Class.jq_NameAndDesc;
7 import joeq.Compiler.Analysis.IPA.PA;
8 import joeq.Compiler.Quad.CodeCache;
9 import joeq.Compiler.Quad.Quad;
10 import joeq.Compiler.Quad.RegisterFactory;
11 import jwutil.util.Assert;
12
13 /***
14 * @author V.Benjamin Livshits
15 * @see joeq.Compiler.Analysis.IPSSA.SSADefinition
16 * @see joeq.Compiler.Analysis.IPSSA.SSABinding
17 * @version $Id: SSALocation.java 1931 2004-09-22 22:17:47Z joewhaley $
18 */
19 public interface SSALocation {
20
21 /***
22 * We need to have "abstract" temporary locations for IPSSA construction purposes
23 * that do not necessarily correspond to anything tangible.
24 * */
25 public static class Temporary implements SSALocation {
26 private Temporary() {
27
28 }
29
30
31 public static class FACTORY {
32 private static Temporary INSTANCE = new Temporary();
33
34 public static Temporary get() {
35 return INSTANCE;
36 }
37 }
38
39 public String toString(PA pa) {
40 return null;
41 }
42
43 public String toString() {
44 return "temp";
45 }
46 }
47
48 public static class Unique implements SSALocation {
49 private static long _count = 0;
50 private long _id;
51
52 private Unique(long id) {
53 this._id = id;
54 }
55
56
57 public static class FACTORY {
58 public static Unique get() {
59 return new Unique(_count++);
60 }
61 }
62
63 public String toString(PA pa) {
64 return null;
65 }
66
67 public String toString() {
68 return "uniq" + _id;
69 }
70 }
71
72 String toString(PA pa);
73
74 /***
75 * These locations represent local variables.
76 * */
77 class LocalLocation implements SSALocation {
78 private RegisterFactory.Register _reg;
79 private String _name = null;
80
81 public static class FACTORY {
82 static HashMap _locationMap = new HashMap();
83 public static LocalLocation createLocalLocation(RegisterFactory.Register reg){
84 LocalLocation loc = (LocalLocation) _locationMap.get(reg);
85 if(loc == null){
86 loc = new LocalLocation(reg);
87 _locationMap.put(reg, loc);
88 }
89 return loc;
90 }
91 }
92 public RegisterFactory.Register getRegister(){
93 return this._reg;
94 }
95 private LocalLocation(RegisterFactory.Register reg){
96 Assert._assert(reg != null);
97 this._reg = reg;
98 }
99 public String toString(PA pa) {
100 return toString();
101 }
102
103
104 public String toString() {
105 return _reg.toString();
106 }
107 public String getName(jq_Method method, Quad quad) {
108 if(_reg.isTemp()) {
109 return null;
110 }
111 if(_name != null) {
112 return _name;
113 }
114 Integer i = ((Integer)CodeCache.getBCMap(method).get(quad));
115 if(i == null) {
116 return null;
117 }
118 int bci = i.intValue();
119 jq_LocalVarTableEntry entry = method.getLocalVarTableEntry(bci, _reg.getNumber());
120 if(entry == null) {
121 return null;
122 }
123 jq_NameAndDesc nd = entry.getNameAndDesc();
124 if(nd == null) {
125 return null;
126 }
127
128 _name = nd.getName().toString();
129 return _name;
130 }
131 }
132 }
133