Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/ir/Constant.java @ 2872:0341b6424579
Project renaming.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:42:25 +0200 |
parents | graal/GraalCompiler/src/com/sun/c1x/ir/Constant.java@14708c03abba |
children |
comparison
equal
deleted
inserted
replaced
2871:d704eb526603 | 2872:0341b6424579 |
---|---|
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.c1x.ir; | |
24 | |
25 import static com.sun.c1x.C1XCompilation.*; | |
26 | |
27 import com.oracle.graal.graph.*; | |
28 import com.sun.c1x.debug.*; | |
29 import com.sun.cri.ci.*; | |
30 import com.sun.cri.ri.*; | |
31 | |
32 /** | |
33 * The {@code Constant} instruction represents a constant such as an integer value, | |
34 * long, float, object reference, address, etc. | |
35 */ | |
36 public final class Constant extends FloatingNode { | |
37 | |
38 private static final int INPUT_COUNT = 0; | |
39 private static final int SUCCESSOR_COUNT = 0; | |
40 | |
41 public final CiConstant value; | |
42 | |
43 /** | |
44 * Constructs a new instruction representing the specified constant. | |
45 * @param value the constant | |
46 * @param graph | |
47 */ | |
48 public Constant(CiConstant value, Graph graph) { | |
49 super(value.kind.stackKind(), INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
50 this.value = value; | |
51 } | |
52 | |
53 @Override | |
54 public void accept(ValueVisitor v) { | |
55 v.visitConstant(this); | |
56 } | |
57 | |
58 /** | |
59 * Creates an instruction for a double constant. | |
60 * @param d the double value for which to create the instruction | |
61 * @param graph | |
62 * @return an instruction representing the double | |
63 */ | |
64 public static Constant forDouble(double d, Graph graph) { | |
65 return new Constant(CiConstant.forDouble(d), graph); | |
66 } | |
67 | |
68 /** | |
69 * Creates an instruction for a float constant. | |
70 * @param f the float value for which to create the instruction | |
71 * @return an instruction representing the float | |
72 */ | |
73 public static Constant forFloat(float f, Graph graph) { | |
74 return new Constant(CiConstant.forFloat(f), graph); | |
75 } | |
76 | |
77 /** | |
78 * Creates an instruction for an long constant. | |
79 * @param i the long value for which to create the instruction | |
80 * @return an instruction representing the long | |
81 */ | |
82 public static Constant forLong(long i, Graph graph) { | |
83 return new Constant(CiConstant.forLong(i), graph); | |
84 } | |
85 | |
86 /** | |
87 * Creates an instruction for an integer constant. | |
88 * @param i the integer value for which to create the instruction | |
89 * @return an instruction representing the integer | |
90 */ | |
91 public static Constant forInt(int i, Graph graph) { | |
92 return new Constant(CiConstant.forInt(i), graph); | |
93 } | |
94 | |
95 /** | |
96 * Creates an instruction for a boolean constant. | |
97 * @param i the boolean value for which to create the instruction | |
98 * @return an instruction representing the boolean | |
99 */ | |
100 public static Constant forBoolean(boolean i, Graph graph) { | |
101 return new Constant(CiConstant.forBoolean(i), graph); | |
102 } | |
103 | |
104 /** | |
105 * Creates an instruction for an address (jsr/ret address) constant. | |
106 * @param i the address value for which to create the instruction | |
107 * @return an instruction representing the address | |
108 */ | |
109 public static Constant forJsr(int i, Graph graph) { | |
110 return new Constant(CiConstant.forJsr(i), graph); | |
111 } | |
112 | |
113 /** | |
114 * Creates an instruction for an object constant. | |
115 * @param o the object value for which to create the instruction | |
116 * @return an instruction representing the object | |
117 */ | |
118 public static Constant forObject(Object o, Graph graph) { | |
119 return new Constant(CiConstant.forObject(o), graph); | |
120 } | |
121 | |
122 /** | |
123 * Creates an instruction for a word constant. | |
124 * @param val the word value for which to create the instruction | |
125 * @return an instruction representing the word | |
126 */ | |
127 public static Constant forWord(long val, Graph graph) { | |
128 return new Constant(CiConstant.forWord(val), graph); | |
129 } | |
130 | |
131 public static Constant defaultForKind(CiKind kind, Graph graph) { | |
132 switch(kind) { | |
133 case Boolean: | |
134 return Constant.forBoolean(false, graph); | |
135 case Byte: | |
136 case Char: | |
137 case Short: | |
138 case Int: | |
139 return Constant.forInt(0, graph); | |
140 case Double: | |
141 return Constant.forDouble(0.0, graph); | |
142 case Float: | |
143 return Constant.forFloat(0.0f, graph); | |
144 case Long: | |
145 return Constant.forLong(0L, graph); | |
146 case Object: | |
147 return Constant.forObject(null, graph); | |
148 case Word: | |
149 return Constant.forWord(0L, graph); | |
150 default: | |
151 return null; | |
152 } | |
153 } | |
154 | |
155 @Override | |
156 public String toString() { | |
157 return super.toString() + "(" + value + ")"; | |
158 } | |
159 | |
160 @Override | |
161 public int valueNumber() { | |
162 return 0x50000000 | value.hashCode(); | |
163 } | |
164 | |
165 @Override | |
166 public boolean valueEqual(Node i) { | |
167 return i instanceof Constant && ((Constant) i).value.equivalent(this.value); | |
168 } | |
169 | |
170 @Override | |
171 public RiType declaredType() { | |
172 RiRuntime runtime = compilation().runtime; | |
173 if (kind.isPrimitive()) { | |
174 runtime.asRiType(kind); | |
175 } | |
176 return runtime.getTypeOf(asConstant()); | |
177 } | |
178 | |
179 @Override | |
180 public RiType exactType() { | |
181 return declaredType(); | |
182 } | |
183 | |
184 @Override | |
185 public void print(LogStream out) { | |
186 out.print(value.valueString()); | |
187 } | |
188 | |
189 @Override | |
190 public String shortName() { | |
191 return value.name(); | |
192 } | |
193 | |
194 @Override | |
195 public Node copy(Graph into) { | |
196 Constant x = new Constant(value, into); | |
197 return x; | |
198 } | |
199 } |