Search in sources :

Example 31 with Node

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

the class SLInstrumentTest method checkRootNode.

private static void checkRootNode(Scope ls, String name, MaterializedFrame frame) {
    assertEquals(name, ls.getName());
    Node node = ls.getNode();
    assertTrue(node.getClass().getName(), node instanceof RootNode);
    assertEquals(name, ((RootNode) node).getName());
    assertEquals(frame.getFrameDescriptor(), ((RootNode) node).getFrameDescriptor());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootNode(com.oracle.truffle.api.nodes.RootNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node)

Example 32 with Node

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

the class PolyglotExceptionFrame method createGuest.

static PolyglotExceptionFrame createGuest(PolyglotExceptionImpl exception, TruffleStackTraceElement frame, boolean first) {
    if (frame == null) {
        return null;
    }
    RootNode targetRoot = frame.getTarget().getRootNode();
    if (targetRoot.isInternal()) {
        return null;
    }
    LanguageInfo info = targetRoot.getLanguageInfo();
    if (info == null) {
        return null;
    }
    PolyglotEngineImpl engine = exception.context.getEngine();
    PolyglotLanguage language = engine.idToLanguage.get(info.getId());
    String rootName = targetRoot.getName();
    SourceSection location;
    Node callNode = frame.getLocation();
    if (callNode != null) {
        com.oracle.truffle.api.source.SourceSection section = callNode.getEncapsulatingSourceSection();
        if (section != null) {
            Source source = engine.getAPIAccess().newSource(language.getId(), section.getSource());
            location = engine.getAPIAccess().newSourceSection(source, section);
        } else {
            location = null;
        }
    } else {
        location = first ? exception.getSourceLocation() : null;
    }
    return new PolyglotExceptionFrame(exception, language, location, rootName, false, null);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(org.graalvm.polyglot.Source) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) SourceSection(org.graalvm.polyglot.SourceSection)

Example 33 with Node

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

the class InstrumentationTest method testQueryTags2.

/*
     * Test behavior of queryTags when used with languages
     */
@Test
public void testQueryTags2() throws IOException {
    Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
    assureEnabled(instrument);
    TestIsNodeTaggedWith1.expressionNode = null;
    TestIsNodeTaggedWith1.statementNode = null;
    TestIsNodeTaggedWith1Language.instrumenter = null;
    Source otherLanguageSource = Source.create("testIsNodeTaggedWith1-lang", "STATEMENT(EXPRESSION)");
    run(otherLanguageSource);
    Instrumenter instrumenter = TestIsNodeTaggedWith1Language.instrumenter;
    Node languageExpression = TestIsNodeTaggedWith1.expressionNode;
    Node languageStatement = TestIsNodeTaggedWith1.statementNode;
    assertTags(instrumenter.queryTags(languageExpression), InstrumentationTestLanguage.EXPRESSION);
    assertTags(instrumenter.queryTags(languageStatement), InstrumentationTestLanguage.STATEMENT);
    TestIsNodeTaggedWith1.expressionNode = null;
    TestIsNodeTaggedWith1.statementNode = null;
    run("EXPRESSION");
    // fail if called with nodes from a different language
    Node otherLanguageExpression = TestIsNodeTaggedWith1.expressionNode;
    try {
        instrumenter.queryTags(otherLanguageExpression);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 34 with Node

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

the class Context method parse.

@Override
protected ExecutableNode parse(InlineParsingRequest request) throws Exception {
    Source code = request.getSource();
    Node location = request.getLocation();
    if (location == null) {
        throw new IllegalArgumentException("Location must not be null.");
    }
    BaseNode node;
    try {
        node = parse(code);
    } catch (LanguageError e) {
        throw new IOException(e);
    }
    return new InlineExecutableNode(this, node);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) IOException(java.io.IOException) Source(com.oracle.truffle.api.source.Source)

Example 35 with Node

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

the class InstrumentationUpdateTest method assertLoaded.

private void assertLoaded(Node... children) {
    Iterator<LoadSourceSectionEvent> loadIterator = loadEvents.iterator();
    for (Node loadedChild : children) {
        Assert.assertTrue(loadIterator.hasNext());
        Assert.assertSame(loadedChild, loadIterator.next().getNode());
    }
    Assert.assertFalse(loadIterator.hasNext());
}
Also used : LoadSourceSectionEvent(com.oracle.truffle.api.instrumentation.LoadSourceSectionEvent) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode)

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