Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiValue.java @ 4169:f5328dda9714
Initial commit of SSA-based spill-all register assignment
author | Christian Wimmer <Christian.Wimmer@Oracle.com> |
---|---|
date | Wed, 28 Dec 2011 18:13:25 -0800 |
parents | bc8527f3071c |
children | de7b3e7ae528 |
comparison
equal
deleted
inserted
replaced
4168:0bc4815d2069 | 4169:f5328dda9714 |
---|---|
22 */ | 22 */ |
23 package com.sun.cri.ci; | 23 package com.sun.cri.ci; |
24 | 24 |
25 import java.io.*; | 25 import java.io.*; |
26 | 26 |
27 | |
28 | |
29 /** | 27 /** |
30 * Abstract base class for values manipulated by the compiler. All values have a {@linkplain CiKind kind} and are immutable. | 28 * Abstract base class for values manipulated by the compiler. All values have a {@linkplain CiKind kind} and are immutable. |
31 */ | 29 */ |
32 public abstract class CiValue implements Serializable { | 30 public abstract class CiValue implements Serializable { |
33 private static final long serialVersionUID = -6909397188697766469L; | 31 private static final long serialVersionUID = -6909397188697766469L; |
34 | 32 |
35 @SuppressWarnings("serial") | 33 @SuppressWarnings("serial") |
36 public static CiValue IllegalValue = new CiValue(CiKind.Illegal) { | 34 public static CiValue IllegalValue = new CiValue(CiKind.Illegal) { |
37 @Override | 35 @Override |
38 public String name() { | 36 public String toString() { |
39 return "<illegal>"; | 37 return "-"; |
40 } | 38 } |
41 @Override | 39 @Override |
42 public CiRegister asRegister() { | 40 public CiRegister asRegister() { |
43 return CiRegister.None; | 41 return CiRegister.None; |
44 } | |
45 @Override | |
46 public int hashCode() { | |
47 return -1; | |
48 } | |
49 @Override | |
50 public boolean equals(Object obj) { | |
51 return obj == this; | |
52 } | |
53 @Override | |
54 public boolean equalsIgnoringKind(CiValue other) { | |
55 return other == this; | |
56 } | 42 } |
57 }; | 43 }; |
58 | 44 |
59 /** | 45 /** |
60 * The kind of this value. | 46 * The kind of this value. |
108 | 94 |
109 public final boolean isConstant() { | 95 public final boolean isConstant() { |
110 return this instanceof CiConstant; | 96 return this instanceof CiConstant; |
111 } | 97 } |
112 | 98 |
113 /** | 99 public boolean equalsIgnoringKind(CiValue other) { |
114 * Gets a string name for this value without indicating its {@linkplain #kind kind}. | 100 // This is a suitable default implementation for several subclasses |
115 */ | 101 return equals(other); |
116 public abstract String name(); | 102 } |
117 | 103 |
118 @Override | 104 @Override |
119 public abstract boolean equals(Object obj); | 105 public abstract String toString(); |
120 | 106 |
121 public abstract boolean equalsIgnoringKind(CiValue other); | 107 protected final String kindSuffix() { |
122 | 108 return "|" + kind.typeChar; |
123 @Override | |
124 public abstract int hashCode(); | |
125 | |
126 @Override | |
127 public final String toString() { | |
128 return name() + kindSuffix(); | |
129 } | |
130 | |
131 public final String kindSuffix() { | |
132 if (kind == CiKind.Illegal) { | |
133 return ""; | |
134 } | |
135 return ":" + kind.typeChar; | |
136 } | 109 } |
137 | 110 |
138 public final boolean isConstant0() { | 111 public final boolean isConstant0() { |
139 return isConstant() && ((CiConstant) this).asInt() == 0; | 112 return isConstant() && ((CiConstant) this).asInt() == 0; |
140 } | 113 } |
141 | |
142 /** | |
143 * Utility for specializing how a {@linkplain CiValue LIR operand} is formatted to a string. | |
144 * The {@linkplain Formatter#DEFAULT default formatter} returns the value of | |
145 * {@link CiValue#toString()}. | |
146 */ | |
147 public static class Formatter { | |
148 public static final Formatter DEFAULT = new Formatter(); | |
149 | |
150 /** | |
151 * Formats a given operand as a string. | |
152 * | |
153 * @param operand the operand to format | |
154 * @return {@code operand} as a string | |
155 */ | |
156 public String format(CiValue operand) { | |
157 return operand.toString(); | |
158 } | |
159 } | |
160 | |
161 } | 114 } |