/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static void main(String args[]) { expectEqualsByte((byte)1, booleanToByte(true)); expectEqualsShort((short)1, booleanToShort(true)); expectEqualsChar((char)1, booleanToChar(true)); expectEqualsInt(1, booleanToInt(true)); expectEqualsLong(1L, booleanToLong(true)); expectEqualsInt(1, longToIntOfBoolean()); System.out.println("passed"); } /// CHECK-START: byte Main.booleanToByte(boolean) builder (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Equal [<>,<>] /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: byte Main.booleanToByte(boolean) select_generator (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: byte Main.booleanToByte(boolean) instruction_simplifier_after_bce (after) /// CHECK: <> ParameterValue /// CHECK-DAG: Return [<>] static byte booleanToByte(boolean b) { return (byte)(b ? 1 : 0); } /// CHECK-START: short Main.booleanToShort(boolean) builder (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Equal [<>,<>] /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: short Main.booleanToShort(boolean) select_generator (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: short Main.booleanToShort(boolean) instruction_simplifier_after_bce (after) /// CHECK: <> ParameterValue /// CHECK-DAG: Return [<>] static short booleanToShort(boolean b) { return (short)(b ? 1 : 0); } /// CHECK-START: char Main.booleanToChar(boolean) builder (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Equal [<>,<>] /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: char Main.booleanToChar(boolean) select_generator (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: char Main.booleanToChar(boolean) instruction_simplifier_after_bce (after) /// CHECK: <> ParameterValue /// CHECK-DAG: Return [<>] static char booleanToChar(boolean b) { return (char)(b ? 1 : 0); } /// CHECK-START: int Main.booleanToInt(boolean) builder (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Equal [<>,<>] /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: Return [<>] /// CHECK-START: int Main.booleanToInt(boolean) select_generator (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: Return [<>] /// CHECK-START: int Main.booleanToInt(boolean) instruction_simplifier_after_bce (after) /// CHECK: <> ParameterValue /// CHECK-DAG: Return [<>] static int booleanToInt(boolean b) { return b ? 1 : 0; } /// CHECK-START: long Main.booleanToLong(boolean) builder (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Equal [<>,<>] /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: long Main.booleanToLong(boolean) instruction_simplifier_after_bce (after) /// CHECK: <> ParameterValue /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] static long booleanToLong(boolean b) { return b ? 1 : 0; } /// CHECK-START: int Main.longToIntOfBoolean() builder (after) /// CHECK-DAG: <> CurrentMethod /// CHECK-DAG: <> StaticFieldGet /// CHECK-DAG: <> InvokeStaticOrDirect [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: int Main.longToIntOfBoolean() inliner (after) /// CHECK-DAG: <> CurrentMethod /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> StaticFieldGet /// CHECK-DAG: If [<>] /// CHECK-DAG: <> Phi [<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: int Main.longToIntOfBoolean() select_generator (after) /// CHECK-DAG: <> CurrentMethod /// CHECK-DAG: <> IntConstant 0 /// CHECK-DAG: <> IntConstant 1 /// CHECK-DAG: <> StaticFieldGet /// CHECK-DAG: <> Select [<>,<>,<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: <> TypeConversion [<>] /// CHECK-DAG: Return [<>] /// CHECK-START: int Main.longToIntOfBoolean() instruction_simplifier_after_bce (after) /// CHECK-DAG: <> CurrentMethod /// CHECK-DAG: <> StaticFieldGet /// CHECK-DAG: Return [<>] static int longToIntOfBoolean() { long l = booleanToLong(booleanField); return (int) l; } private static void expectEqualsByte(byte expected, byte result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } private static void expectEqualsShort(short expected, short result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } private static void expectEqualsChar(char expected, char result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } private static void expectEqualsInt(int expected, int result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } private static void expectEqualsLong(long expected, long result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } public static boolean booleanField = true; }