Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Constant.java @ 2509:16b9a8b5ad39
Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:50:44 +0200 |
parents | graal/Compiler/src/com/sun/c1x/ir/Constant.java@9ec15d6914ca |
children | 092e628ddd5d |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
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.sun.c1x.debug.*; | |
28 import com.sun.cri.ci.*; | |
29 import com.sun.cri.ri.*; | |
30 | |
31 /** | |
32 * The {@code Constant} instruction represents a constant such as an integer value, | |
33 * long, float, object reference, address, etc. | |
34 * | |
35 * @author Ben L. Titzer | |
36 */ | |
37 public final class Constant extends Instruction { | |
38 | |
39 public final CiConstant value; | |
40 | |
41 /** | |
42 * Constructs a new instruction representing the specified constant. | |
43 * @param value the constant | |
44 */ | |
45 public Constant(CiConstant value) { | |
46 super(value.kind.stackKind()); | |
47 this.value = value; | |
48 initFlag(Value.Flag.NonNull, value.isNonNull()); | |
49 } | |
50 | |
51 @Override | |
52 public void accept(ValueVisitor v) { | |
53 v.visitConstant(this); | |
54 } | |
55 | |
56 /** | |
57 * Creates an instruction for a double constant. | |
58 * @param d the double value for which to create the instruction | |
59 * @return an instruction representing the double | |
60 */ | |
61 public static Constant forDouble(double d) { | |
62 return new Constant(CiConstant.forDouble(d)); | |
63 } | |
64 | |
65 /** | |
66 * Creates an instruction for a float constant. | |
67 * @param f the float value for which to create the instruction | |
68 * @return an instruction representing the float | |
69 */ | |
70 public static Constant forFloat(float f) { | |
71 return new Constant(CiConstant.forFloat(f)); | |
72 } | |
73 | |
74 /** | |
75 * Creates an instruction for an long constant. | |
76 * @param i the long value for which to create the instruction | |
77 * @return an instruction representing the long | |
78 */ | |
79 public static Constant forLong(long i) { | |
80 return new Constant(CiConstant.forLong(i)); | |
81 } | |
82 | |
83 /** | |
84 * Creates an instruction for an integer constant. | |
85 * @param i the integer value for which to create the instruction | |
86 * @return an instruction representing the integer | |
87 */ | |
88 public static Constant forInt(int i) { | |
89 return new Constant(CiConstant.forInt(i)); | |
90 } | |
91 | |
92 /** | |
93 * Creates an instruction for a boolean constant. | |
94 * @param i the boolean value for which to create the instruction | |
95 * @return an instruction representing the boolean | |
96 */ | |
97 public static Constant forBoolean(boolean i) { | |
98 return new Constant(CiConstant.forBoolean(i)); | |
99 } | |
100 | |
101 /** | |
102 * Creates an instruction for an address (jsr/ret address) constant. | |
103 * @param i the address value for which to create the instruction | |
104 * @return an instruction representing the address | |
105 */ | |
106 public static Constant forJsr(int i) { | |
107 return new Constant(CiConstant.forJsr(i)); | |
108 } | |
109 | |
110 /** | |
111 * Creates an instruction for an object constant. | |
112 * @param o the object value for which to create the instruction | |
113 * @return an instruction representing the object | |
114 */ | |
115 public static Constant forObject(Object o) { | |
116 return new Constant(CiConstant.forObject(o)); | |
117 } | |
118 | |
119 /** | |
120 * Creates an instruction for a word constant. | |
121 * @param val the word value for which to create the instruction | |
122 * @return an instruction representing the word | |
123 */ | |
124 public static Constant forWord(long val) { | |
125 return new Constant(CiConstant.forWord(val)); | |
126 } | |
127 | |
128 @Override | |
129 public String toString() { | |
130 return super.toString() + "(" + value + ")"; | |
131 } | |
132 | |
133 @Override | |
134 public int valueNumber() { | |
135 return 0x50000000 | value.hashCode(); | |
136 } | |
137 | |
138 @Override | |
139 public boolean valueEqual(Instruction i) { | |
140 return i instanceof Constant && ((Constant) i).value.equivalent(this.value); | |
141 } | |
142 | |
143 @Override | |
144 public RiType declaredType() { | |
145 RiRuntime runtime = compilation().runtime; | |
146 if (kind.isPrimitive()) { | |
147 runtime.asRiType(kind); | |
148 } | |
149 return runtime.getTypeOf(asConstant()); | |
150 } | |
151 | |
152 @Override | |
153 public RiType exactType() { | |
154 return declaredType(); | |
155 } | |
156 | |
157 @Override | |
158 public void print(LogStream out) { | |
159 out.print(value.valueString()); | |
160 } | |
161 } |