Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/ExecuteEvaluatedTest.java @ 9223:5f7f0d3e3638
Updated codegen tests to new codegen API.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 20 Apr 2013 12:17:47 +0200 |
parents | |
children | 76a6e7907b67 |
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 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.*; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.codegen.*; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 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
|
28 import com.oracle.truffle.api.frame.*; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.nodes.*; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 public class ExecuteEvaluatedTest { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 public abstract static class ExtValueNode extends ValueNode { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 public CallTarget executeCallTarget(VirtualFrame frame) throws UnexpectedResultException { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 return SimpleTypesGen.SIMPLETYPES.expectCallTarget(execute(frame)); |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 } |
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 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 /* Represents target[element] */ |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 @NodeChildren({@NodeChild("targetNode"), @NodeChild("elementNode")}) |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 abstract static class ReadElementNode extends ExtValueNode { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 @Specialization |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 int getInt(Object[] target, int element) { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 return (int) target[element]; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 public abstract Object executeWith(VirtualFrame frame, Object targetValue); |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
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 /* Represents target[element]() */ |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 @NodeChildren({@NodeChild("targetNode"), @NodeChild(value = "elementNode", type = ReadElementNode.class, executeWith = "targetNode")}) |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 abstract static class ElementCallNode extends ExtValueNode { |
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 @Specialization |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 Object call(Object receiver, CallTarget callTarget) { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 return callTarget.call(new TestArguments(receiver)); |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 } |
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 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 public static class TestArguments extends Arguments { |
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 private final Object receiver; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 public TestArguments(Object receiver) { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 this.receiver = receiver; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 public Object getReceiver() { |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 return receiver; |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 } |