Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 21038:6868faf48f02
Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Sat, 18 Apr 2015 19:56:22 +0200 |
parents | a665483c3881 |
children |
rev | line source |
---|---|
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Polymorphic1Factory; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public class PolymorphicTest2 { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 @Test |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public void testMultipleTypes() { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 /* Tests the unexpected polymorphic case. */ |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
41 TestRootNode<Polymorphic1> node = TestHelper.createRoot(Polymorphic1Factory.getInstance()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 assertEquals(21, executeWith(node, false, false)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 assertEquals(42, executeWith(node, 21, 21)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
45 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 @SuppressWarnings("unused") |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
49 abstract static class Polymorphic1 extends BinaryNode { |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
51 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 int add(int left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 return 42; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
56 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 int add(boolean left, boolean right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 return 21; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
61 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 String add(boolean left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 return "(boolean,int)"; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |