Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/JavaConstant.java @ 22672:1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 17:28:41 -0700 |
parents | jvmci/jdk.internal.jvmci.meta/src/jdk/internal/jvmci/meta/JavaConstant.java@dc1aeef79e7e |
children | 1d4ce2d19e52 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
22478
822922922f3c
Explicitly store slot kinds in DebugInfo.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22536
diff
changeset
|
23 package jdk.vm.ci.meta; |
5502
13aee5aba8cc
Moved RiConstant to cri.ri package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5501
diff
changeset
|
24 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
26 * Represents a constant (boxed) value, such as an integer, floating point number, or object |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
27 * reference, within the compiler and across the compiler/runtime interface. Exports a set of |
18188
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
28 * {@code JavaConstant} instances that represent frequently used constant values, such as |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18329
diff
changeset
|
29 * {@link #NULL_POINTER}. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 */ |
22489
24b4e5e1431c
Remove JavaConstant from Value hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
22478
diff
changeset
|
31 public interface JavaConstant extends Constant, JavaValue { |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
32 /* |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
33 * Using a larger cache for integers leads to only a slight increase in cache hit ratio which is |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
34 * not enough to justify the impact on startup time. |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
35 */ |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18329
diff
changeset
|
36 JavaConstant NULL_POINTER = new NullConstant(); |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
37 PrimitiveConstant INT_MINUS_1 = new PrimitiveConstant(JavaKind.Int, -1); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
38 PrimitiveConstant INT_0 = new PrimitiveConstant(JavaKind.Int, 0); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
39 PrimitiveConstant INT_1 = new PrimitiveConstant(JavaKind.Int, 1); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
40 PrimitiveConstant INT_2 = new PrimitiveConstant(JavaKind.Int, 2); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
41 PrimitiveConstant LONG_0 = new PrimitiveConstant(JavaKind.Long, 0L); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
42 PrimitiveConstant LONG_1 = new PrimitiveConstant(JavaKind.Long, 1L); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
43 PrimitiveConstant FLOAT_0 = new PrimitiveConstant(JavaKind.Float, Float.floatToRawIntBits(0.0F)); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
44 PrimitiveConstant FLOAT_1 = new PrimitiveConstant(JavaKind.Float, Float.floatToRawIntBits(1.0F)); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
45 PrimitiveConstant DOUBLE_0 = new PrimitiveConstant(JavaKind.Double, Double.doubleToRawLongBits(0.0D)); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
46 PrimitiveConstant DOUBLE_1 = new PrimitiveConstant(JavaKind.Double, Double.doubleToRawLongBits(1.0D)); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
47 PrimitiveConstant TRUE = new PrimitiveConstant(JavaKind.Boolean, 1L); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
48 PrimitiveConstant FALSE = new PrimitiveConstant(JavaKind.Boolean, 0L); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 /** |
22478
822922922f3c
Explicitly store slot kinds in DebugInfo.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
51 * Returns the Java kind of this constant. |
822922922f3c
Explicitly store slot kinds in DebugInfo.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
52 */ |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
53 JavaKind getJavaKind(); |
22478
822922922f3c
Explicitly store slot kinds in DebugInfo.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
54 |
822922922f3c
Explicitly store slot kinds in DebugInfo.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
55 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 * Checks whether this constant is null. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
57 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 * @return {@code true} if this constant is the null constant |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
60 boolean isNull(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
61 |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
62 static boolean isNull(Constant c) { |
18188
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
63 if (c instanceof JavaConstant) { |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
64 return ((JavaConstant) c).isNull(); |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
65 } else { |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
66 return false; |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
67 } |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
68 } |
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
69 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
70 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
71 * Checks whether this constant is non-null. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
72 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
73 * @return {@code true} if this constant is a primitive, or an object constant that is not null |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
74 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
75 default boolean isNonNull() { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
76 return !isNull(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 |
6708
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
79 /** |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
80 * Checks whether this constant is the default value for its kind (null, 0, 0.0, false). |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
81 * |
6708
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
82 * @return {@code true} if this constant is the default value for its kind |
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
83 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
84 boolean isDefaultForKind(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
85 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
86 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
87 * Returns the value of this constant as a boxed Java value. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
88 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
89 * @return the value of this constant |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
90 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
91 Object asBoxedPrimitive(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
92 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
93 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
94 * Returns the primitive int value this constant represents. The constant must have a |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
95 * {@link JavaKind#getStackKind()} of {@link JavaKind#Int}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
96 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
97 * @return the constant value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
98 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
99 int asInt(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
100 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
101 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
102 * Returns the primitive boolean value this constant represents. The constant must have kind |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
103 * {@link JavaKind#Boolean}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
104 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
105 * @return the constant value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
106 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
107 boolean asBoolean(); |
6708
a5156d39b622
add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
108 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
109 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
110 * Returns the primitive long value this constant represents. The constant must have kind |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
111 * {@link JavaKind#Long}, a {@link JavaKind#getStackKind()} of {@link JavaKind#Int}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
112 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
113 * @return the constant value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
114 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
115 long asLong(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
116 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
117 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
118 * Returns the primitive float value this constant represents. The constant must have kind |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
119 * {@link JavaKind#Float}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
120 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
121 * @return the constant value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
122 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
123 float asFloat(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
124 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
125 /** |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
126 * Returns the primitive double value this constant represents. The constant must have kind |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
127 * {@link JavaKind#Double}. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
128 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
129 * @return the constant value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
130 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
131 double asDouble(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
132 |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
133 default String toValueString() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
134 if (getJavaKind() == JavaKind.Illegal) { |
15183
b862cf4381ef
don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
135 return "illegal"; |
b862cf4381ef
don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
136 } else { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
137 return getJavaKind().format(asBoxedPrimitive()); |
15183
b862cf4381ef
don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
138 } |
13576
4e679d50ba9a
Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents:
13140
diff
changeset
|
139 } |
4e679d50ba9a
Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents:
13140
diff
changeset
|
140 |
18329
75e72d395820
fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents:
18320
diff
changeset
|
141 static String toString(JavaConstant constant) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
142 if (constant.getJavaKind() == JavaKind.Illegal) { |
18329
75e72d395820
fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents:
18320
diff
changeset
|
143 return "illegal"; |
75e72d395820
fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents:
18320
diff
changeset
|
144 } else { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
145 return constant.getJavaKind().getJavaName() + "[" + constant.toValueString() + "]"; |
18329
75e72d395820
fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents:
18320
diff
changeset
|
146 } |
75e72d395820
fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents:
18320
diff
changeset
|
147 } |
18186
ef357effbda7
Backout of changeset 9a804ec7f707 (converted Constant and Value to be interfaces).
Roland Schatz <roland.schatz@oracle.com>
parents:
18163
diff
changeset
|
148 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
149 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
150 * Creates a boxed double constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
151 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
152 * @param d the double value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
153 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
154 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
155 static PrimitiveConstant forDouble(double d) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
156 if (Double.compare(0.0D, d) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
157 return DOUBLE_0; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
158 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
159 if (Double.compare(d, 1.0D) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
160 return DOUBLE_1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
161 } |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
162 return new PrimitiveConstant(JavaKind.Double, Double.doubleToRawLongBits(d)); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
163 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
164 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
165 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
166 * Creates a boxed float constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
167 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
168 * @param f the float value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
169 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
170 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
171 static PrimitiveConstant forFloat(float f) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
172 if (Float.compare(f, 0.0F) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
173 return FLOAT_0; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
174 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
175 if (Float.compare(f, 1.0F) == 0) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
176 return FLOAT_1; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
177 } |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
178 return new PrimitiveConstant(JavaKind.Float, Float.floatToRawIntBits(f)); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
179 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
180 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
181 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
182 * Creates a boxed long constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
183 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
184 * @param i the long value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
185 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
186 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
187 static PrimitiveConstant forLong(long i) { |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
188 if (i == 0) { |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
189 return LONG_0; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
190 } else if (i == 1) { |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
191 return LONG_1; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
192 } else { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
193 return new PrimitiveConstant(JavaKind.Long, i); |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
194 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
197 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 * Creates a boxed integer constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
199 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 * @param i the integer value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
203 static PrimitiveConstant forInt(int i) { |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
204 switch (i) { |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
205 case -1: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
206 return INT_MINUS_1; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
207 case 0: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
208 return INT_0; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
209 case 1: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
210 return INT_1; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
211 case 2: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
212 return INT_2; |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
213 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
214 return new PrimitiveConstant(JavaKind.Int, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
217 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
219 * Creates a boxed byte constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
220 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
221 * @param i the byte value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
224 static PrimitiveConstant forByte(byte i) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
225 return new PrimitiveConstant(JavaKind.Byte, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
226 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 * Creates a boxed boolean constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
230 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 * @param i the boolean value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
232 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
234 static PrimitiveConstant forBoolean(boolean i) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 return i ? TRUE : FALSE; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
236 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
238 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
239 * Creates a boxed char constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
240 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
241 * @param i the char value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
242 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
244 static PrimitiveConstant forChar(char i) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
245 return new PrimitiveConstant(JavaKind.Char, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
247 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
248 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 * Creates a boxed short constant. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
250 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
251 * @param i the short value to box |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 * @return a boxed copy of {@code value} |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
254 static PrimitiveConstant forShort(short i) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
255 return new PrimitiveConstant(JavaKind.Short, i); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
256 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
257 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 /** |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18186
diff
changeset
|
259 * Creates a {@link JavaConstant} from a primitive integer of a certain kind. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 */ |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
261 static PrimitiveConstant forIntegerKind(JavaKind kind, long i) { |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
262 switch (kind) { |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
263 case Boolean: |
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
264 return forBoolean(i != 0); |
17197
ec35bb4eccb8
Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
16094
diff
changeset
|
265 case Byte: |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
266 return forByte((byte) i); |
17197
ec35bb4eccb8
Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
16094
diff
changeset
|
267 case Short: |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
268 return forShort((short) i); |
17197
ec35bb4eccb8
Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
16094
diff
changeset
|
269 case Char: |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
270 return forChar((char) i); |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
271 case Int: |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
272 return forInt((int) i); |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
273 case Long: |
21369
5aeab26703cb
Use factory methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18490
diff
changeset
|
274 return forLong(i); |
7105
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
275 default: |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
276 throw new IllegalArgumentException("not an integer kind: " + kind); |
f1f32b695d1e
Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7103
diff
changeset
|
277 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
278 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
279 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
280 /** |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18186
diff
changeset
|
281 * Creates a {@link JavaConstant} from a primitive integer of a certain width. |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
282 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
283 static PrimitiveConstant forPrimitiveInt(int bits, long i) { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
284 assert bits <= 64; |
17606
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
285 switch (bits) { |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
286 case 1: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
287 return forBoolean(i != 0); |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
288 case 8: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
289 return forByte((byte) i); |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
290 case 16: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
291 return forShort((short) i); |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
292 case 32: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
293 return forInt((int) i); |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
294 case 64: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
295 return forLong(i); |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
296 default: |
45d7b2c7029d
Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
17446
diff
changeset
|
297 throw new IllegalArgumentException("unsupported integer width: " + bits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
298 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
299 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
300 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13726
diff
changeset
|
301 /** |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
302 * Creates a boxed constant for the given boxed primitive value. |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
303 * |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
304 * @param value the Java boxed value |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
305 * @return the primitive constant holding the {@code value} |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
306 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
307 static PrimitiveConstant forBoxedPrimitive(Object value) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
308 if (value instanceof Boolean) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
309 return forBoolean((Boolean) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
310 } else if (value instanceof Byte) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
311 return forByte((Byte) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
312 } else if (value instanceof Character) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
313 return forChar((Character) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
314 } else if (value instanceof Short) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
315 return forShort((Short) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
316 } else if (value instanceof Integer) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
317 return forInt((Integer) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
318 } else if (value instanceof Long) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
319 return forLong((Long) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
320 } else if (value instanceof Float) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
321 return forFloat((Float) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
322 } else if (value instanceof Double) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
323 return forDouble((Double) value); |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
324 } else { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14563
diff
changeset
|
325 return null; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
326 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
327 } |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
328 |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
329 static PrimitiveConstant forIllegal() { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
330 return new PrimitiveConstant(JavaKind.Illegal, 0); |
12617
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
331 } |
bca33c3135de
PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents:
11477
diff
changeset
|
332 |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
333 /** |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
334 * Returns a constant with the default value for the given kind. |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
335 */ |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
336 static JavaConstant defaultForKind(JavaKind kind) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7300
diff
changeset
|
337 switch (kind) { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
338 case Boolean: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
339 return FALSE; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
340 case Byte: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
341 return forByte((byte) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
342 case Char: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
343 return forChar((char) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
344 case Short: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
345 return forShort((short) 0); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
346 case Int: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
347 return INT_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
348 case Double: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
349 return DOUBLE_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
350 case Float: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
351 return FLOAT_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
352 case Long: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
353 return LONG_0; |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
354 case Object: |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18329
diff
changeset
|
355 return NULL_POINTER; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
356 default: |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
357 throw new IllegalArgumentException(kind.toString()); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
358 } |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7105
diff
changeset
|
359 } |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
360 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
361 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
362 * Returns the zero value for a given numeric kind. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
363 */ |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
364 static JavaConstant zero(JavaKind kind) { |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
365 switch (kind) { |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
366 case Boolean: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
367 return FALSE; |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
368 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
369 return forByte((byte) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
370 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
371 return forChar((char) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
372 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
373 return DOUBLE_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
374 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
375 return FLOAT_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
376 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
377 return INT_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
378 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
379 return LONG_0; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
380 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
381 return forShort((short) 0); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
382 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
383 throw new IllegalArgumentException(kind.toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
384 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
385 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
386 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
387 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
388 * Returns the one value for a given numeric kind. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
389 */ |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
390 static JavaConstant one(JavaKind kind) { |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
391 switch (kind) { |
16036
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
392 case Boolean: |
4161a58e48cb
refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15909
diff
changeset
|
393 return TRUE; |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
394 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
395 return forByte((byte) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
396 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
397 return forChar((char) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
398 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
399 return DOUBLE_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
400 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
401 return FLOAT_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
402 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
403 return INT_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
404 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
405 return LONG_1; |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
406 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
407 return forShort((short) 1); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
408 default: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
409 throw new IllegalArgumentException(kind.toString()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
410 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
411 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
412 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
413 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
414 * Adds two numeric constants. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
415 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
416 static JavaConstant add(JavaConstant x, JavaConstant y) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
417 assert x.getJavaKind() == y.getJavaKind(); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
418 switch (x.getJavaKind()) { |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
419 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
420 return forByte((byte) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
421 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
422 return forChar((char) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
423 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
424 return forDouble(x.asDouble() + y.asDouble()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
425 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
426 return forFloat(x.asFloat() + y.asFloat()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
427 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
428 return forInt(x.asInt() + y.asInt()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
429 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
430 return forLong(x.asLong() + y.asLong()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
431 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
432 return forShort((short) (x.asInt() + y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
433 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
434 throw new IllegalArgumentException(x.getJavaKind().toString()); |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
435 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
436 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
437 |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
438 /** |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
439 * Multiplies two numeric constants. |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
440 */ |
18320
0093dcea7092
converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18319
diff
changeset
|
441 static PrimitiveConstant mul(JavaConstant x, JavaConstant y) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
442 assert x.getJavaKind() == y.getJavaKind(); |
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
443 switch (x.getJavaKind()) { |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
444 case Byte: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
445 return forByte((byte) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
446 case Char: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
447 return forChar((char) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
448 case Double: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
449 return forDouble(x.asDouble() * y.asDouble()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
450 case Float: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
451 return forFloat(x.asFloat() * y.asFloat()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
452 case Int: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
453 return forInt(x.asInt() * y.asInt()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
454 case Long: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
455 return forLong(x.asLong() * y.asLong()); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
456 case Short: |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
457 return forShort((short) (x.asInt() * y.asInt())); |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
458 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22516
diff
changeset
|
459 throw new IllegalArgumentException(x.getJavaKind().toString()); |
11477
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
460 } |
4b41416685e9
New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents:
7816
diff
changeset
|
461 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
462 } |