comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 10597:79041ab43660

Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author Christian Humer <christian.humer@gmail.com>
date Mon, 01 Jul 2013 20:58:32 +0200
parents
children c7d9ff67beed
comparison
equal deleted inserted replaced
10596:f43eb2f1bbbc 10597:79041ab43660
1 /*
2 * Copyright (c) 2012, 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.truffle.api.dsl.test;
24
25 import java.util.*;
26
27 import com.oracle.truffle.api.*;
28 import com.oracle.truffle.api.dsl.*;
29 import com.oracle.truffle.api.dsl.test.NodeContainerTest.BuiltinNode;
30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode;
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode;
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestArguments;
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
35
36 /**
37 * Utility class to provide some test helper functions.
38 */
39 class TestHelper {
40
41 private static ArgumentNode[] arguments(int count) {
42 ArgumentNode[] nodes = new ArgumentNode[count];
43 for (int i = 0; i < nodes.length; i++) {
44 nodes[i] = new ArgumentNode(i);
45 }
46 return nodes;
47 }
48
49 static <E extends ValueNode> E createNode(NodeFactory<E> factory, Object... constants) {
50 ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size());
51
52 List<Object> argumentList = new ArrayList<>();
53 argumentList.addAll(Arrays.asList(constants));
54 if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass()) || BuiltinNode.class.isAssignableFrom(factory.getNodeClass())) {
55 argumentList.add(argumentNodes);
56 } else {
57 argumentList.addAll(Arrays.asList(argumentNodes));
58 }
59 return factory.createNode(argumentList.toArray(new Object[argumentList.size()]));
60 }
61
62 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) {
63 return new TestRootNode<>(createNode(factory, constants));
64 }
65
66 static CallTarget createCallTarget(ValueNode node) {
67 return createCallTarget(new TestRootNode<>(node));
68 }
69
70 static CallTarget createCallTarget(TestRootNode<? extends ValueNode> node) {
71 return Truffle.getRuntime().createCallTarget(node);
72 }
73
74 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) {
75 return createCallTarget(node).call(new TestArguments(values));
76 }
77
78 }