Search in sources :

Example 96 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class NodeUtilTest method testAccept.

@Test
public void testAccept() {
    TestRootNode root = new TestRootNode();
    TestForEachNode testForEachNode = new TestForEachNode(1);
    root.child0 = testForEachNode;
    TestNode testNode1 = new TestNode();
    testForEachNode.firstChild = testNode1;
    TestNode testNode2 = new TestNode();
    testForEachNode.children[0] = testNode2;
    TestNode testNode3 = new TestNode();
    testForEachNode.lastChild = testNode3;
    root.adoptChildren();
    int[] count = new int[1];
    testForEachNode.accept(new NodeVisitor() {

        public boolean visit(Node node) {
            ((VisitableNode) node).visited++;
            count[0]++;
            return true;
        }
    });
    Assert.assertEquals(4, count[0]);
    Assert.assertEquals(1, testForEachNode.visited);
    Assert.assertEquals(1, testNode1.visited);
    Assert.assertEquals(1, testNode2.visited);
    Assert.assertEquals(1, testNode3.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) Test(org.junit.Test)

Example 97 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class NodeUtilTest method iterate.

private static int iterate(Iterator<Node> iterator) {
    int iterationCount = 0;
    while (iterator.hasNext()) {
        Node node = iterator.next();
        if (node == null) {
            continue;
        }
        if (node instanceof TestNode) {
            ((TestNode) node).visited = iterationCount;
        } else if (node instanceof TestRootNode) {
            ((TestRootNode) node).visited = iterationCount;
        } else {
            throw new AssertionError();
        }
        iterationCount++;
    }
    return iterationCount;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 98 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class NodeUtilTest method testForEachChild.

@Test
public void testForEachChild() {
    TestRootNode root = new TestRootNode();
    TestForEachNode testForEachNode = new TestForEachNode(1);
    root.child0 = testForEachNode;
    TestNode testNode1 = new TestNode();
    testForEachNode.firstChild = testNode1;
    TestNode testNode2 = new TestNode();
    testForEachNode.children[0] = testNode2;
    TestNode testNode3 = new TestNode();
    testForEachNode.lastChild = testNode3;
    root.adoptChildren();
    int[] count = new int[1];
    NodeUtil.forEachChild(root, new NodeVisitor() {

        public boolean visit(Node node) {
            Assert.assertSame(testForEachNode, node);
            count[0]++;
            return true;
        }
    });
    Assert.assertEquals(1, count[0]);
    count[0] = 0;
    NodeUtil.forEachChild(testForEachNode, new NodeVisitor() {

        public boolean visit(Node node) {
            ((VisitableNode) node).visited++;
            count[0]++;
            return true;
        }
    });
    Assert.assertEquals(3, count[0]);
    Assert.assertEquals(1, testNode1.visited);
    Assert.assertEquals(1, testNode2.visited);
    Assert.assertEquals(1, testNode3.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) Test(org.junit.Test)

Example 99 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class RootNodeTest method testNotReplacable3.

@Test(expected = IllegalStateException.class)
@Ignore
public void testNotReplacable3() {
    TestRootNode2 rootNode = new TestRootNode2();
    rootNode.rootNodeAsChild = new Node() {
    };
    rootNode.adoptChildren();
    rootNode.rootNodeAsChild.replace(new TestRootNode());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 100 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class ChildrenNodesTest method testMultipleChildrenFields.

@Test
public void testMultipleChildrenFields() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildNode firstChild = new TestChildNode();
    TestChildNode secondChild = new TestChildNode();
    TestChildNode thirdChild = new TestChildNode();
    TestChildNode forthChild = new TestChildNode();
    TestRootNode rootNode = new TestRoot2Node(new TestChildNode[] { firstChild, secondChild }, new TestChildNode[] { thirdChild, forthChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    Assert.assertEquals(rootNode, firstChild.getParent());
    Assert.assertEquals(rootNode, secondChild.getParent());
    Assert.assertEquals(rootNode, thirdChild.getParent());
    Assert.assertEquals(rootNode, forthChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(firstChild, iterator.next());
    Assert.assertEquals(secondChild, iterator.next());
    Assert.assertEquals(thirdChild, iterator.next());
    Assert.assertEquals(forthChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(2 * 42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)101 RootNode (com.oracle.truffle.api.nodes.RootNode)65 Test (org.junit.Test)46 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)21 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)21 Source (com.oracle.truffle.api.source.Source)16 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 CallTarget (com.oracle.truffle.api.CallTarget)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)8 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)7 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 TestHelper.createNode (com.oracle.truffle.api.dsl.test.TestHelper.createNode)5 ValueNode (com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode)5 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)5 LinkedHashMap (java.util.LinkedHashMap)5 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)4