blob: fbc28d8d52902006bb5fdf5c55861e15815c86d9 [file] [log] [blame]
David Brazdil13b47182015-04-15 16:29:32 +01001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
David Brazdil13b47182015-04-15 16:29:32 +010016
17public class Main {
18
19 public static void assertBoolEquals(boolean expected, boolean result) {
20 if (expected != result) {
21 throw new Error("Expected: " + expected + ", found: " + result);
22 }
23 }
24
25 /*
David Brazdil2fa194b2015-04-20 10:14:42 +010026 * Test that integer Phis are accepted as Boolean inputs until
27 * we implement a suitable type analysis.
David Brazdil13b47182015-04-15 16:29:32 +010028 */
29
David Brazdil74eb1b22015-12-14 11:44:01 +000030 /// CHECK-START: boolean Main.TestPhiAsBoolean(int) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010031 /// CHECK-DAG: <<Phi:i\d+>> Phi
David Brazdil74eb1b22015-12-14 11:44:01 +000032 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Phi>>]
David Brazdil13b47182015-04-15 16:29:32 +010033
34 public static boolean f1;
35 public static boolean f2;
36
37 public static boolean InlinePhi(int x) {
38 return (x == 42) ? f1 : f2;
39 }
40
41 public static boolean TestPhiAsBoolean(int x) {
42 return InlinePhi(x) != true ? true : false;
43 }
44
David Brazdil2fa194b2015-04-20 10:14:42 +010045 /*
46 * Test that integer And is accepted as a Boolean input until
47 * we implement a suitable type analysis.
48 */
49
David Brazdil74eb1b22015-12-14 11:44:01 +000050 /// CHECK-START: boolean Main.TestAndAsBoolean(boolean, boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010051 /// CHECK-DAG: <<And:i\d+>> And
David Brazdil74eb1b22015-12-14 11:44:01 +000052 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<And>>]
David Brazdil2fa194b2015-04-20 10:14:42 +010053
54 public static boolean InlineAnd(boolean x, boolean y) {
55 return x & y;
56 }
57
58 public static boolean TestAndAsBoolean(boolean x, boolean y) {
59 return InlineAnd(x, y) != true ? true : false;
60 }
61
62 /*
63 * Test that integer Or is accepted as a Boolean input until
64 * we implement a suitable type analysis.
65 */
66
David Brazdil74eb1b22015-12-14 11:44:01 +000067 /// CHECK-START: boolean Main.TestOrAsBoolean(boolean, boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010068 /// CHECK-DAG: <<Or:i\d+>> Or
David Brazdil74eb1b22015-12-14 11:44:01 +000069 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Or>>]
David Brazdil2fa194b2015-04-20 10:14:42 +010070
71 public static boolean InlineOr(boolean x, boolean y) {
72 return x | y;
73 }
74
75 public static boolean TestOrAsBoolean(boolean x, boolean y) {
76 return InlineOr(x, y) != true ? true : false;
77 }
78
79 /*
80 * Test that integer Xor is accepted as a Boolean input until
81 * we implement a suitable type analysis.
82 */
83
David Brazdil74eb1b22015-12-14 11:44:01 +000084 /// CHECK-START: boolean Main.TestXorAsBoolean(boolean, boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010085 /// CHECK-DAG: <<Xor:i\d+>> Xor
David Brazdil74eb1b22015-12-14 11:44:01 +000086 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Xor>>]
David Brazdil2fa194b2015-04-20 10:14:42 +010087
88 public static boolean InlineXor(boolean x, boolean y) {
89 return x ^ y;
90 }
91
92 public static boolean TestXorAsBoolean(boolean x, boolean y) {
93 return InlineXor(x, y) != true ? true : false;
94 }
95
David Brazdil13b47182015-04-15 16:29:32 +010096 public static void main(String[] args) {
97 f1 = true;
98 f2 = false;
99 assertBoolEquals(true, TestPhiAsBoolean(0));
100 assertBoolEquals(false, TestPhiAsBoolean(42));
David Brazdil2fa194b2015-04-20 10:14:42 +0100101 assertBoolEquals(true, TestAndAsBoolean(true, false));
102 assertBoolEquals(false, TestAndAsBoolean(true, true));
103 assertBoolEquals(true, TestOrAsBoolean(false, false));
104 assertBoolEquals(false, TestOrAsBoolean(true, true));
105 assertBoolEquals(true, TestXorAsBoolean(true, true));
106 assertBoolEquals(false, TestXorAsBoolean(true, false));
David Brazdil13b47182015-04-15 16:29:32 +0100107 }
108}