Mercurial > hg > truffle
annotate graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/TriState.java @ 21594:cc9e15bbbd3c
SSAMoveResolver: add support for non-virtual stack slots.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Fri, 29 May 2015 12:08:54 +0200 |
parents | 48c1ebd24120 |
children |
rev | line source |
---|---|
19717
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
20062
diff
changeset
|
23 package com.oracle.jvmci.meta; |
19717
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 /** |
20062
758c2bd9bc0d
Fix javadoc.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19717
diff
changeset
|
26 * Represents a logic value that can be either {@link #TRUE}, {@link #FALSE}, or {@link #UNKNOWN}. |
19717
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 */ |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 public enum TriState { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 TRUE, |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 FALSE, |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 UNKNOWN; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 public static TriState get(boolean value) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 return value ? TRUE : FALSE; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 /** |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 * This is optimistic about {@link #UNKNOWN} (it prefers known values over {@link #UNKNOWN}) and |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 * pesimistic about known (it perfers {@link #TRUE} over {@link #FALSE}). |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 */ |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 public static TriState merge(TriState a, TriState b) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 if (a == TRUE || b == TRUE) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 return TRUE; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 if (a == FALSE || b == FALSE) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 return FALSE; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 assert a == UNKNOWN && b == UNKNOWN; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 return UNKNOWN; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 public boolean isTrue() { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 return this == TRUE; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 public boolean isFalse() { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 return this == FALSE; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 public boolean isUnknown() { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 return this == UNKNOWN; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 public boolean isKnown() { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 return this != UNKNOWN; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 public boolean toBoolean() { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 if (isTrue()) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 return true; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 } else if (isFalse()) { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 return false; |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 } else { |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 throw new IllegalStateException("Cannot convert to boolean, TriState is in an unknown state"); |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 } |
70d565f6e127
Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 } |