1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package com.oracle.graal.compiler.ptx.test; 24 25 import org.junit.Test; 26 27 import java.lang.reflect.Method; 28 29 public class ControlTest extends PTXTestBase { 30 31 @Test 32 public void testControl() { 33 compile("testFor2I"); 34 compile("testWhile2I"); 35 // compile("testSwitch1I"); 36 // compile("testIfThen1Z"); 37 compile("testStatic"); 38 // compile("testSync"); 39 // compile("testSyncObject"); 40 } 41 42 public static int testFor2I(int a, int b) { 43 int indexed = 0; 44 for (int i = a; i < b; i++) { 45 indexed++; 46 } 47 return indexed; 48 } 49 50 public static int testWhile2I(int a, int b) { 51 int indexed = 0; 52 while (a < b) { 53 indexed++; 54 } 55 return indexed; 56 } 57 58 /* 59 * NYI - PTXLIRGenerator.emitSequentialSwitch 60 * 61 * public static int testSwitch1I(int a) { 62 * switch (a) { 63 * case 1: 64 * return 2; 65 * case 2: 66 * return 3; 67 * default: 68 * return 4; 69 * } 70 * } 71 */ 72 73 /* 74 * NYI - PTXControlFlow 75 * 76 * public static int testIfThen1Z(boolean a) { 77 * if (a) { 78 * return 2; 79 * } else { 80 * return 3; 81 * } 82 * } 83 */ 84 85 @SuppressWarnings("unused") 86 private static Object foo = null; 87 88 public static boolean testStatic(Object o) { 89 foo = o; 90 return true; 91 } 92 93 /* 94 * Throws ClassCastException - PTXLIRGenerator not HotSpotLIRGenerator as there 95 * is no com.oracle.graal.hotspot.ptx yet. 96 * 97 * public static synchronized void testSync() { 98 * } 99 * 100 * public static void testSyncObject(Object o) { 101 * synchronized (o) { 102 * } 103 * } 104 */ 105 106 public static void main(String[] args) { 107 ControlTest test = new ControlTest(); 108 for (Method m : ControlTest.class.getMethods()) { 109 String name = m.getName(); 110 if (m.getAnnotation(Test.class) == null && name.startsWith("test")) { 111 System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode())); 112 } 113 } 114 } 115 }