annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaConstant.java @ 18490:ca81508f2a19

Generalize NULL handling to work on arbitrary pointers.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 24 Nov 2014 13:53:14 +0100
parents 75e72d395820
children 5aeab26703cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
16094
c0b8d395368b Introduce LIRKind to accurately track oop references in backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 16036
diff changeset
2 * Copyright (c) 2009, 2014, 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 */
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5506
diff changeset
23 package com.oracle.graal.api.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 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
31 public interface JavaConstant extends Constant, JavaValue, Value {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
16036
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
33 /*
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
34 * 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
35 * not enough to justify the impact on startup time.
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
36 */
18490
ca81508f2a19 Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 18329
diff changeset
37 JavaConstant NULL_POINTER = new NullConstant();
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
38 PrimitiveConstant INT_MINUS_1 = new PrimitiveConstant(Kind.Int, -1);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
39 PrimitiveConstant INT_0 = new PrimitiveConstant(Kind.Int, 0);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
40 PrimitiveConstant INT_1 = new PrimitiveConstant(Kind.Int, 1);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
41 PrimitiveConstant INT_2 = new PrimitiveConstant(Kind.Int, 2);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
42 PrimitiveConstant LONG_0 = new PrimitiveConstant(Kind.Long, 0L);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
43 PrimitiveConstant LONG_1 = new PrimitiveConstant(Kind.Long, 1L);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
44 PrimitiveConstant FLOAT_0 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(0.0F));
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
45 PrimitiveConstant FLOAT_1 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(1.0F));
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
46 PrimitiveConstant DOUBLE_0 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(0.0D));
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
47 PrimitiveConstant DOUBLE_1 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(1.0D));
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
48 PrimitiveConstant TRUE = new PrimitiveConstant(Kind.Boolean, 1L);
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
49 PrimitiveConstant FALSE = new PrimitiveConstant(Kind.Boolean, 0L);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 * 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
53 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 * @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
55 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
56 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
57
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
58 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
59 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
60 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
61 } else {
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
62 return false;
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
63 }
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
64 }
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
65
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
66 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
67 * 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
68 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
69 * @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
70 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
71 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
72 return !isNull();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
75 /**
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
76 * 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
77 *
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
78 * @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
79 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
80 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
81
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
82 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
83 * 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
84 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
85 * @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
86 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
87 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
88
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
89 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
90 * Returns the primitive int value this constant represents. The constant must have a
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
91 * {@link Kind#getStackKind()} of {@link Kind#Int}.
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 * @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
94 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
95 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
96
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
97 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
98 * Returns the primitive boolean value this constant represents. The constant must have kind
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
99 * {@link Kind#Boolean}.
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 * @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
102 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
103 boolean asBoolean();
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
104
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
105 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
106 * Returns the primitive long value this constant represents. The constant must have kind
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
107 * {@link Kind#Long}, a {@link Kind#getStackKind()} of {@link Kind#Int}.
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
108 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
109 * @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
110 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
111 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
112
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
113 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
114 * Returns the primitive float value this constant represents. The constant must have kind
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
115 * {@link Kind#Float}.
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 * @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
118 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
119 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
120
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
121 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
122 * Returns the primitive double value this constant represents. The constant must have kind
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
123 * {@link Kind#Double}.
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 * @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
126 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
127 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
128
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
129 default String toValueString() {
15183
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
130 if (getKind() == Kind.Illegal) {
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
131 return "illegal";
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
132 } else {
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
133 return getKind().format(asBoxedPrimitive());
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
134 }
13576
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
135 }
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
136
18329
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
137 static String toString(JavaConstant constant) {
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
138 if (constant.getKind() == Kind.Illegal) {
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
139 return "illegal";
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
140 } else {
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
141 return constant.getKind().getJavaName() + "[" + constant.toValueString() + "]";
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
142 }
75e72d395820 fixed toString() for JavaConstants
Doug Simon <doug.simon@oracle.com>
parents: 18320
diff changeset
143 }
18186
ef357effbda7 Backout of changeset 9a804ec7f707 (converted Constant and Value to be interfaces).
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
144
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 * 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
147 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 * @param d the double value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
151 static PrimitiveConstant forDouble(double d) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 if (Double.compare(0.0D, d) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 return DOUBLE_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 if (Double.compare(d, 1.0D) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 return DOUBLE_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
158 return new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(d));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 * 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
163 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 * @param f the float value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
167 static PrimitiveConstant forFloat(float f) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 if (Float.compare(f, 0.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 return FLOAT_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 if (Float.compare(f, 1.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 return FLOAT_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
174 return new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(f));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 * 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
179 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 * @param i the long value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
183 static PrimitiveConstant forLong(long i) {
16036
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
184 if (i == 0) {
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
185 return LONG_0;
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
186 } else if (i == 1) {
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
187 return LONG_1;
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
188 } else {
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
189 return new PrimitiveConstant(Kind.Long, i);
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
190 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 * 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
195 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 * @param i the integer value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
199 static PrimitiveConstant forInt(int i) {
16036
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
200 switch (i) {
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
201 case -1:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
202 return INT_MINUS_1;
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
203 case 0:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
204 return INT_0;
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_1;
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
207 case 2:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
208 return INT_2;
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
209 default:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
210 return new PrimitiveConstant(Kind.Int, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 * 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
216 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 * @param i the byte value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
220 static PrimitiveConstant forByte(byte i) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
221 return new PrimitiveConstant(Kind.Byte, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225 * 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
226 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227 * @param i the boolean value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
228 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
230 static PrimitiveConstant forBoolean(boolean i) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 return i ? TRUE : FALSE;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 * 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
236 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 * @param i the char value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
240 static PrimitiveConstant forChar(char i) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
241 return new PrimitiveConstant(Kind.Char, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 * 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
246 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 * @param i the short value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
250 static PrimitiveConstant forShort(short i) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
251 return new PrimitiveConstant(Kind.Short, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254 /**
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18186
diff changeset
255 * 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
256 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
257 static PrimitiveConstant forIntegerKind(Kind 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
258 switch (kind) {
17197
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
259 case Byte:
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
260 return new PrimitiveConstant(kind, (byte) i);
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
261 case Short:
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
262 return new PrimitiveConstant(kind, (short) i);
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
263 case Char:
ec35bb4eccb8 Add support for other data types to integer arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 16094
diff changeset
264 return new PrimitiveConstant(kind, (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
265 case Int:
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
266 return new PrimitiveConstant(kind, (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
267 case Long:
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
268 return new PrimitiveConstant(kind, 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
269 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
270 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
271 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274 /**
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18186
diff changeset
275 * 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
276 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
277 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
278 assert bits <= 64;
17606
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
279 switch (bits) {
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
280 case 1:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
281 return forBoolean(i != 0);
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
282 case 8:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
283 return forByte((byte) i);
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
284 case 16:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
285 return forShort((short) i);
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
286 case 32:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
287 return forInt((int) i);
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
288 case 64:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
289 return forLong(i);
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
290 default:
45d7b2c7029d Use correct kind for narrow int constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 17446
diff changeset
291 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
292 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
293 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
294
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
295 /**
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
296 * 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
297 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
298 * @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
299 * @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
300 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
301 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
302 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
303 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
304 } 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
305 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
306 } 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
307 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
308 } 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
309 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
310 } 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
311 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
312 } 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
313 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
314 } 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
315 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
316 } 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
317 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
318 } else {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
319 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
320 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
321 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
322
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
323 static PrimitiveConstant forIllegal() {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
324 return new PrimitiveConstant(Kind.Illegal, 0);
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
325 }
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
326
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
327 /**
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
328 * 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
329 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
330 static JavaConstant defaultForKind(Kind kind) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
331 switch (kind) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
332 case Boolean:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
333 return FALSE;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
334 case Byte:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
335 return forByte((byte) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
336 case Char:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
337 return forChar((char) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
338 case Short:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
339 return forShort((short) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
340 case Int:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
341 return INT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
342 case Double:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
343 return DOUBLE_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
344 case Float:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
345 return FLOAT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
346 case Long:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
347 return LONG_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
348 case Object:
18490
ca81508f2a19 Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 18329
diff changeset
349 return NULL_POINTER;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
350 default:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
351 throw new IllegalArgumentException(kind.toString());
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
352 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
353 }
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
354
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
355 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
356 * 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
357 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
358 static JavaConstant zero(Kind kind) {
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
359 switch (kind) {
16036
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
360 case Boolean:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
361 return FALSE;
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
362 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
363 return forByte((byte) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
364 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
365 return forChar((char) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
366 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
367 return DOUBLE_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
368 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
369 return FLOAT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
370 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
371 return INT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
372 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
373 return LONG_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
374 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
375 return forShort((short) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
376 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
377 throw new IllegalArgumentException(kind.toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
378 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
379 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
380
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
381 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
382 * 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
383 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
384 static JavaConstant one(Kind kind) {
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
385 switch (kind) {
16036
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
386 case Boolean:
4161a58e48cb refactor/simplify Constant
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15909
diff changeset
387 return TRUE;
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
388 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
389 return forByte((byte) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
390 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
391 return forChar((char) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
392 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
393 return DOUBLE_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
394 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
395 return FLOAT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
396 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
397 return INT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
398 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
399 return LONG_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
400 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
401 return forShort((short) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
402 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
403 throw new IllegalArgumentException(kind.toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
404 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
405 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
406
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
407 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
408 * Adds two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
409 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
410 static JavaConstant add(JavaConstant x, JavaConstant y) {
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
411 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
412 switch (x.getKind()) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
413 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
414 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
415 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
416 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
417 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
418 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
419 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
420 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
421 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
422 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
423 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
424 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
425 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
426 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
427 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
428 throw new IllegalArgumentException(x.getKind().toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
429 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
430 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
431
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
432 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
433 * Multiplies two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
434 */
18320
0093dcea7092 converted JavaConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18319
diff changeset
435 static PrimitiveConstant mul(JavaConstant x, JavaConstant y) {
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
436 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
437 switch (x.getKind()) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
438 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
439 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
440 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
441 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
442 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
443 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
444 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
445 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
446 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
447 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
448 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
449 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
450 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
451 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
452 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
453 throw new IllegalArgumentException(x.getKind().toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
454 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
455 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456 }