Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/ExecuteEvaluatedTest.java @ 9800:2eaac2c3670b
VerifyUsageWithEquals/VerifyPhase: add documentation
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Thu, 23 May 2013 12:00:40 +0200 |
parents | 8e3a1635cc9e |
children |
rev | line source |
---|---|
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.codegen.test; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
25 import org.junit.*; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
26 |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.codegen.*; |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
29 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.DoubleEvaluatedNodeFactory; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
30 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.EvaluatedNodeFactory; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
31 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.UseDoubleEvaluatedNodeFactory; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
32 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.UseEvaluatedNodeFactory; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
33 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ArgumentNode; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
34 import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestArguments; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.frame.*; |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
37 import com.oracle.truffle.api.nodes.*; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public class ExecuteEvaluatedTest { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
41 @Test |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
42 public void testSingleEvaluated() { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
43 ArgumentNode arg0 = new ArgumentNode(0); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
44 CallTarget callTarget = TestHelper.createCallTarget(UseEvaluatedNodeFactory.create(arg0, EvaluatedNodeFactory.create(null))); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
45 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
46 Assert.assertEquals(43, callTarget.call(new TestArguments(42))); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
47 Assert.assertEquals(1, arg0.getInvocationCount()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
48 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
49 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
50 @NodeChild("exp") |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
51 abstract static class EvaluatedNode extends ValueNode { |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Specialization |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
54 int doExecuteWith(int exp) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
55 return exp + 1; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
58 public abstract Object executeEvaluated(VirtualFrame frame, Object targetValue); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
59 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
60 public abstract int executeIntEvaluated(VirtualFrame frame, Object targetValue) throws UnexpectedResultException; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
63 @NodeChildren({@NodeChild("exp0"), @NodeChild(value = "exp1", type = EvaluatedNode.class, executeWith = "exp0")}) |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
64 abstract static class UseEvaluatedNode extends ValueNode { |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 @Specialization |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
67 int call(int exp0, int exp1) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
68 Assert.assertEquals(exp0 + 1, exp1); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
69 return exp1; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
71 } |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
73 @Test |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
74 public void testDoubleEvaluated() { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
75 ArgumentNode arg0 = new ArgumentNode(0); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
76 ArgumentNode arg1 = new ArgumentNode(1); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
77 CallTarget callTarget = TestHelper.createCallTarget(UseDoubleEvaluatedNodeFactory.create(arg0, arg1, DoubleEvaluatedNodeFactory.create(null, null))); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
78 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
79 Assert.assertEquals(85, callTarget.call(new TestArguments(42, 43))); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
80 Assert.assertEquals(1, arg0.getInvocationCount()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
81 Assert.assertEquals(1, arg1.getInvocationCount()); |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
84 @NodeChildren({@NodeChild("exp0"), @NodeChild("exp1")}) |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
85 abstract static class DoubleEvaluatedNode extends ValueNode { |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
87 @Specialization |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
88 int doExecuteWith(int exp0, int exp1) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
89 return exp0 + exp1; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
92 public abstract Object executeEvaluated(VirtualFrame frame, Object exp0, Object exp1); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
93 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
94 public abstract int executeIntEvaluated(VirtualFrame frame, Object exp0, Object exp1) throws UnexpectedResultException; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
95 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
96 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
97 @NodeChildren({@NodeChild("exp0"), @NodeChild("exp1"), @NodeChild(value = "exp2", type = DoubleEvaluatedNode.class, executeWith = {"exp0", "exp1"})}) |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
98 abstract static class UseDoubleEvaluatedNode extends ValueNode { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
99 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
100 @Specialization |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
101 int call(int exp0, int exp1, int exp2) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
102 Assert.assertEquals(exp0 + exp1, exp2); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9229
diff
changeset
|
103 return exp2; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 } |