annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java @ 15018:db4254246f9a

Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 07 Apr 2014 16:09:17 -0700
parents 82e4fe6fa525
children b862cf4381ef
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 /*
4182
de7b3e7ae528 Simplify CiValue
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4169
diff changeset
2 * Copyright (c) 2009, 2012, 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
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
28 * {@code Constant} instances that represent frequently used constant values, such as
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
29 * {@link #NULL_OBJECT}.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
31 public abstract class Constant extends Value {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6329
diff changeset
32
4182
de7b3e7ae528 Simplify CiValue
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4169
diff changeset
33 private static final long serialVersionUID = -6355452536852663986L;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
35 private static final Constant[] INT_CONSTANT_CACHE = new Constant[100];
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 static {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 for (int i = 0; i < INT_CONSTANT_CACHE.length; ++i) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
38 INT_CONSTANT_CACHE[i] = new PrimitiveConstant(Kind.Int, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
42 public static final Constant NULL_OBJECT = new NullConstant();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
43 public static final Constant INT_MINUS_1 = new PrimitiveConstant(Kind.Int, -1);
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
44 public static final Constant INT_0 = forInt(0);
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
45 public static final Constant INT_1 = forInt(1);
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
46 public static final Constant INT_2 = forInt(2);
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
47 public static final Constant INT_3 = forInt(3);
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
48 public static final Constant INT_4 = forInt(4);
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
49 public static final Constant INT_5 = forInt(5);
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
50 public static final Constant LONG_0 = new PrimitiveConstant(Kind.Long, 0L);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
51 public static final Constant LONG_1 = new PrimitiveConstant(Kind.Long, 1L);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
52 public static final Constant FLOAT_0 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(0.0F));
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
53 public static final Constant FLOAT_1 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(1.0F));
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
54 public static final Constant FLOAT_2 = new PrimitiveConstant(Kind.Float, Float.floatToRawIntBits(2.0F));
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
55 public static final Constant DOUBLE_0 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(0.0D));
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
56 public static final Constant DOUBLE_1 = new PrimitiveConstant(Kind.Double, Double.doubleToRawLongBits(1.0D));
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
57 public static final Constant TRUE = new PrimitiveConstant(Kind.Boolean, 1L);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
58 public static final Constant FALSE = new PrimitiveConstant(Kind.Boolean, 0L);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 static {
5543
25d561cfdcfa Clean up in api classes. Removed CiGenericCallback. Simplified Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
61 assert FLOAT_0 != forFloat(-0.0F) : "Constant for 0.0f must be different from -0.0f";
25d561cfdcfa Clean up in api classes. Removed CiGenericCallback. Simplified Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
62 assert DOUBLE_0 != forDouble(-0.0d) : "Constant for 0.0d must be different from -0.0d";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 assert NULL_OBJECT.isNull();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
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 protected Constant(Kind kind) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 super(kind);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 * 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
72 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 * @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
74 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
75 public abstract boolean isNull();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
76
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
77 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
78 * 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
79 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
80 * @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
81 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
82 public final boolean isNonNull() {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
83 return !isNull();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
86 /**
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
87 * 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
88 *
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
89 * @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
90 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
91 public abstract boolean isDefaultForKind();
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 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
95 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
96 * @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
97 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
98 public abstract Object asBoxedPrimitive();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
99
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 * 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
102 * {@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
103 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
104 * @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
105 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
106 public abstract int asInt();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
107
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 * 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
110 * {@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
111 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
112 * @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
113 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
114 public abstract boolean asBoolean();
6708
a5156d39b622 add isDefaultForKind to Constant
Lukas Stadler <lukas.stadler@jku.at>
parents: 6539
diff changeset
115
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 * 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
118 * {@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
119 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
120 * @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
121 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
122 public abstract long asLong();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
123
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 * 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
126 * {@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
127 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
128 * @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
129 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
130 public abstract float asFloat();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
131
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
132 /**
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
133 * 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
134 * {@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
135 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
136 * @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
137 */
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
138 public abstract double asDouble();
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
139
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
140 public String toValueString() {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
141 return getKind().format(asBoxedPrimitive());
13576
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
142 }
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
143
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 @Override
4169
f5328dda9714 Initial commit of SSA-based spill-all register assignment
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4142
diff changeset
145 public String toString() {
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
146 if (getKind() == Kind.Illegal) {
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
147 return "illegal";
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
148 } else {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
149 return getKind().getJavaName() + "[" + toValueString() + "]";
6996
eec373d34caf added support for annotated Constants and used it to track Klass* values in Graal and register them in the metadata section of a nmethod during code installation
Doug Simon <doug.simon@oracle.com>
parents: 6994
diff changeset
150 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 * 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
155 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 * @param d the double value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
159 public static Constant forDouble(double d) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 if (Double.compare(0.0D, d) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 return DOUBLE_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 if (Double.compare(d, 1.0D) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 return DOUBLE_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
166 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
167 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 * 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
171 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 * @param f the float value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
175 public static Constant forFloat(float f) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 if (Float.compare(f, 0.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 return FLOAT_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 if (Float.compare(f, 1.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 return FLOAT_1;
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 if (Float.compare(f, 2.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 return FLOAT_2;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
185 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
186 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 * 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
190 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 * @param i the long value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
194 public static Constant forLong(long i) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
195 return i == 0 ? LONG_0 : i == 1 ? LONG_1 : new PrimitiveConstant(Kind.Long, i);
3733
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 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 * 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
200 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 * @param i the integer value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
204 public static Constant forInt(int i) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 if (i == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 return INT_MINUS_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 if (i >= 0 && i < INT_CONSTANT_CACHE.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 return INT_CONSTANT_CACHE[i];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
211 return new PrimitiveConstant(Kind.Int, i);
3733
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 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
220 public static Constant 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 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
230 public static Constant 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 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
240 public static Constant 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 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
250 public static Constant 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 /**
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
255 * Creates a {@link Constant} 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 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
257 public static Constant 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) {
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
259 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
260 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
261 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
262 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
263 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
264 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
265 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 /**
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
269 * Creates a {@link Constant} from a primitive integer of a certain width.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
270 */
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
271 public static Constant forPrimitiveInt(int bits, long i) {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
272 assert bits <= 64;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
273 if (bits > 32) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
274 return new PrimitiveConstant(Kind.Long, i);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
275 } else {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
276 return new PrimitiveConstant(Kind.Int, (int) i);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
277 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
278 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
279
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
280 /**
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
281 * 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
282 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
283 * @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
284 * @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
285 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
286 public static Constant forBoxedPrimitive(Object value) {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
287 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
288 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
289 } 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
290 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
291 } 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
292 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
293 } 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
294 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
295 } 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
296 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
297 } 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
298 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
299 } 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
300 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
301 } 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
302 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
303 } else {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
304 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
305 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
306 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
307
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
308 public static Constant forIllegal() {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
309 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
310 }
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
311
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
312 /**
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
313 * 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
314 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
315 public static Constant defaultForKind(Kind kind) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
316 switch (kind) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
317 case Boolean:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
318 return FALSE;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
319 case Byte:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
320 return forByte((byte) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
321 case Char:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
322 return forChar((char) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
323 case Short:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
324 return forShort((short) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
325 case Int:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
326 return INT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
327 case Double:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
328 return DOUBLE_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
329 case Float:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
330 return FLOAT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
331 case Long:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
332 return LONG_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
333 case Object:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
334 return NULL_OBJECT;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
335 default:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
336 throw new IllegalArgumentException(kind.toString());
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
337 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
338 }
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
339
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
340 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
341 * 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
342 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
343 public static Constant zero(Kind kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
344 switch (kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
345 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
346 return forByte((byte) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
347 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
348 return forChar((char) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
349 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
350 return DOUBLE_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
351 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
352 return FLOAT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
353 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
354 return INT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
355 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
356 return LONG_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
357 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
358 return forShort((short) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
359 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
360 throw new IllegalArgumentException(kind.toString());
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 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
363
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
364 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
365 * 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
366 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
367 public static Constant one(Kind kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
368 switch (kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
369 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
370 return forByte((byte) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
371 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
372 return forChar((char) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
373 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
374 return DOUBLE_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
375 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
376 return FLOAT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
377 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
378 return INT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
379 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
380 return LONG_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
381 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
382 return forShort((short) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
383 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
384 throw new IllegalArgumentException(kind.toString());
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 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
389 * Adds two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
390 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
391 public static Constant add(Constant x, Constant y) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
392 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
393 switch (x.getKind()) {
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) (x.asInt() + y.asInt()));
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) (x.asInt() + y.asInt()));
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 forDouble(x.asDouble() + y.asDouble());
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 forFloat(x.asFloat() + y.asFloat());
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 forInt(x.asInt() + y.asInt());
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 forLong(x.asLong() + y.asLong());
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) (x.asInt() + y.asInt()));
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(x.getKind().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 * Multiplies two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
415 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
416 public static Constant mul(Constant x, Constant y) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
417 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
418 switch (x.getKind()) {
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:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
434 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
435 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
436 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437 }