annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java @ 15183:b862cf4381ef

don't throw exception for Constant.toValueString with Kind.Illegal
author Lukas Stadler <lukas.stadler@oracle.com>
date Thu, 17 Apr 2014 09:59:27 +0200
parents db4254246f9a
children e43591136d9f
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() {
15183
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
141 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
142 return "illegal";
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
143 } else {
b862cf4381ef don't throw exception for Constant.toValueString with Kind.Illegal
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15018
diff changeset
144 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
145 }
13576
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
146 }
4e679d50ba9a Move data section building code to Java.
Roland Schatz <roland.schatz@oracle.com>
parents: 13140
diff changeset
147
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 @Override
4169
f5328dda9714 Initial commit of SSA-based spill-all register assignment
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4142
diff changeset
149 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
150 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
151 return "illegal";
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
152 } else {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
153 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
154 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158 * 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
159 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 * @param d the double value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
163 public static Constant forDouble(double d) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 if (Double.compare(0.0D, d) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 return DOUBLE_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167 if (Double.compare(d, 1.0D) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 return DOUBLE_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
170 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
171 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 * 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
175 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 * @param f the float value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
179 public static Constant forFloat(float f) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 if (Float.compare(f, 0.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 return FLOAT_0;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 if (Float.compare(f, 1.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 return FLOAT_1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186 if (Float.compare(f, 2.0F) == 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 return FLOAT_2;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
189 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
190 }
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 * 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
194 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 * @param i the long value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
198 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
199 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
200 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 * 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
204 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 * @param i the integer value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
208 public static Constant forInt(int i) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 if (i == -1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 return INT_MINUS_1;
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 if (i >= 0 && i < INT_CONSTANT_CACHE.length) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 return INT_CONSTANT_CACHE[i];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
215 return new PrimitiveConstant(Kind.Int, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 * Creates a boxed byte constant.
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
220 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 * @param i the byte value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
224 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
225 return new PrimitiveConstant(Kind.Byte, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
228 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 * Creates a boxed boolean constant.
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
230 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 * @param i the boolean value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
234 public static Constant forBoolean(boolean i) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 return i ? TRUE : FALSE;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 * Creates a boxed char constant.
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
240 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 * @param i the char value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
244 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
245 return new PrimitiveConstant(Kind.Char, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 * Creates a boxed short constant.
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
250 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 * @param i the short value to box
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
252 * @return a boxed copy of {@code value}
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 */
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
254 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
255 return new PrimitiveConstant(Kind.Short, i);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258 /**
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
259 * 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
260 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
270 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 /**
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
273 * 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
274 */
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
275 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
276 assert bits <= 64;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
277 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
278 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
279 } else {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
280 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
281 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
282 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
283
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents: 13726
diff changeset
284 /**
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
285 * 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
286 *
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
287 * @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
288 * @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
289 */
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
290 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
291 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
292 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
293 } 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
294 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
295 } 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
296 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
297 } 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
298 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
299 } 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
300 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
301 } 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
302 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
303 } 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
304 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
305 } 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
306 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
307 } else {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14563
diff changeset
308 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
309 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
311
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
312 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
313 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
314 }
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 11477
diff changeset
315
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
316 /**
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
317 * 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
318 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
319 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
320 switch (kind) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
321 case Boolean:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
322 return FALSE;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
323 case Byte:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
324 return forByte((byte) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
325 case Char:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
326 return forChar((char) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
327 case Short:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
328 return forShort((short) 0);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
329 case Int:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
330 return INT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
331 case Double:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
332 return DOUBLE_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
333 case Float:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
334 return FLOAT_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
335 case Long:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
336 return LONG_0;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
337 case Object:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
338 return NULL_OBJECT;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
339 default:
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
340 throw new IllegalArgumentException(kind.toString());
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
341 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7105
diff changeset
342 }
11477
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
343
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
344 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
345 * 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
346 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
347 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
348 switch (kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
349 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
350 return forByte((byte) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
351 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
352 return forChar((char) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
353 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
354 return DOUBLE_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
355 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
356 return FLOAT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
357 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
358 return INT_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
359 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
360 return LONG_0;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
361 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
362 return forShort((short) 0);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
363 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
364 throw new IllegalArgumentException(kind.toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
365 }
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
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
368 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
369 * 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
370 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
371 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
372 switch (kind) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
373 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
374 return forByte((byte) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
375 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
376 return forChar((char) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
377 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
378 return DOUBLE_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
379 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
380 return FLOAT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
381 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
382 return INT_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
383 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
384 return LONG_1;
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
385 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
386 return forShort((short) 1);
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
387 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
388 throw new IllegalArgumentException(kind.toString());
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
389 }
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
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
392 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
393 * Adds two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
394 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
395 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
396 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
397 switch (x.getKind()) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
398 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
399 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
400 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
401 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
402 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
403 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
404 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
405 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
406 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
407 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
408 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
409 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
410 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
411 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
412 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
413 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
414 }
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
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
417 /**
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
418 * Multiplies two numeric constants.
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
419 */
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
420 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
421 assert x.getKind() == y.getKind();
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
422 switch (x.getKind()) {
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
423 case Byte:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
424 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
425 case Char:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
426 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
427 case Double:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
428 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
429 case Float:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
430 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
431 case Int:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
432 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
433 case Long:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
434 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
435 case Short:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
436 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
437 default:
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
438 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
439 }
4b41416685e9 New static factory methods for constants and arithmetic.
Roland Schatz <roland.schatz@oracle.com>
parents: 7816
diff changeset
440 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
441 }