Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiValue.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | bc8527f3071c |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.cri.ci; | |
24 | |
25 import java.io.*; | |
26 | |
27 | |
28 | |
29 /** | |
30 * Abstract base class for values manipulated by the compiler. All values have a {@linkplain CiKind kind} and are immutable. | |
31 */ | |
32 public abstract class CiValue implements Serializable { | |
33 | |
34 public static CiValue IllegalValue = new CiValue(CiKind.Illegal) { | |
35 @Override | |
36 public String name() { | |
37 return "<illegal>"; | |
38 } | |
39 @Override | |
40 public CiRegister asRegister() { | |
41 return CiRegister.None; | |
42 } | |
43 @Override | |
44 public int hashCode() { | |
45 return -1; | |
46 } | |
47 @Override | |
48 public boolean equals(Object obj) { | |
49 return obj == this; | |
50 } | |
51 @Override | |
52 public boolean equalsIgnoringKind(CiValue other) { | |
53 return other == this; | |
54 } | |
55 }; | |
56 | |
57 /** | |
58 * The kind of this value. | |
59 */ | |
60 public final CiKind kind; | |
61 | |
62 /** | |
63 * Initializes a new value of the specified kind. | |
64 * @param kind the kind | |
65 */ | |
66 protected CiValue(CiKind kind) { | |
67 this.kind = kind; | |
68 } | |
69 | |
70 public final boolean isVariableOrRegister() { | |
71 return this instanceof CiVariable || this instanceof CiRegisterValue; | |
72 } | |
73 | |
74 public CiRegister asRegister() { | |
75 throw new InternalError("Not a register: " + this); | |
76 } | |
77 | |
78 public final boolean isIllegal() { | |
79 return this == IllegalValue; | |
80 } | |
81 | |
82 public final boolean isLegal() { | |
83 return this != IllegalValue; | |
84 } | |
85 | |
86 /** | |
87 * Determines if this value represents a slot on a stack. These values are created | |
88 * by the register allocator for spill slots. They are also used to model method | |
89 * parameters passed on the stack according to a specific calling convention. | |
90 */ | |
91 public final boolean isStackSlot() { | |
92 return this instanceof CiStackSlot; | |
93 } | |
94 | |
95 public final boolean isRegister() { | |
96 return this instanceof CiRegisterValue; | |
97 } | |
98 | |
99 public final boolean isVariable() { | |
100 return this instanceof CiVariable; | |
101 } | |
102 | |
103 public final boolean isAddress() { | |
104 return this instanceof CiAddress; | |
105 } | |
106 | |
107 public final boolean isConstant() { | |
108 return this instanceof CiConstant; | |
109 } | |
110 | |
111 /** | |
112 * Gets a string name for this value without indicating its {@linkplain #kind kind}. | |
113 */ | |
114 public abstract String name(); | |
115 | |
116 @Override | |
117 public abstract boolean equals(Object obj); | |
118 | |
119 public abstract boolean equalsIgnoringKind(CiValue other); | |
120 | |
121 @Override | |
122 public abstract int hashCode(); | |
123 | |
124 @Override | |
125 public final String toString() { | |
126 return name() + kindSuffix(); | |
127 } | |
128 | |
129 public final String kindSuffix() { | |
130 if (kind == CiKind.Illegal) { | |
131 return ""; | |
132 } | |
133 return ":" + kind.typeChar; | |
134 } | |
135 | |
136 public final boolean isConstant0() { | |
137 return isConstant() && ((CiConstant) this).asInt() == 0; | |
138 } | |
139 | |
140 /** | |
141 * Utility for specializing how a {@linkplain CiValue LIR operand} is formatted to a string. | |
142 * The {@linkplain Formatter#DEFAULT default formatter} returns the value of | |
143 * {@link CiValue#toString()}. | |
144 */ | |
145 public static class Formatter { | |
146 public static final Formatter DEFAULT = new Formatter(); | |
147 | |
148 /** | |
149 * Formats a given operand as a string. | |
150 * | |
151 * @param operand the operand to format | |
152 * @return {@code operand} as a string | |
153 */ | |
154 public String format(CiValue operand) { | |
155 return operand.toString(); | |
156 } | |
157 } | |
158 | |
159 } |