Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TestHelper.java @ 10027:e561e0a6f727
DynamicNewArrayNode
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 12 Jun 2013 16:29:12 +0200 |
parents | 8e3a1635cc9e |
children | 3cc5fb59916e |
rev | line source |
---|---|
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.codegen.test; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.util.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.codegen.*; |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
29 import com.oracle.truffle.api.codegen.test.BuiltinTest.*; |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.codegen.test.TypeSystemTest.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 /** |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 * Utility class to provide some test helper functions. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 */ |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 class TestHelper { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 private static ArgumentNode[] arguments(int count) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 ArgumentNode[] nodes = new ArgumentNode[count]; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 for (int i = 0; i < nodes.length; i++) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 nodes[i] = new ArgumentNode(i); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 return nodes; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
45 static <E extends ValueNode> E createNode(NodeFactory<E> factory, Object... constants) { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 List<Object> argumentList = new ArrayList<>(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 argumentList.addAll(Arrays.asList(constants)); |
9223
5f7f0d3e3638
Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents:
8596
diff
changeset
|
50 if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass()) || BuiltinNode.class.isAssignableFrom(factory.getNodeClass())) { |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 argumentList.add(argumentNodes); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 } else { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 argumentList.addAll(Arrays.asList(argumentNodes)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 } |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
55 return factory.createNode(argumentList.toArray(new Object[argumentList.size()])); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
56 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
57 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
58 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
59 return new TestRootNode<>(createNode(factory, constants)); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
60 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
61 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
62 static CallTarget createCallTarget(ValueNode node) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
63 return createCallTarget(new TestRootNode<>(node)); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
64 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
65 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
66 static CallTarget createCallTarget(TestRootNode<? extends ValueNode> node) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
67 return Truffle.getRuntime().createCallTarget(node); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9223
diff
changeset
|
71 return createCallTarget(node).call(new TestArguments(values)); |
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 } |