Search in sources :

Example 11 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class AbstractRequestHandler method getScope.

protected static Object getScope(TextDocumentSurrogate surrogate, InstrumentableNode node) {
    List<CoverageData> coverageData = surrogate.getCoverageData(((Node) node).getSourceSection());
    MaterializedFrame frame = null;
    if (coverageData != null) {
        CoverageData data = coverageData.stream().findFirst().orElse(null);
        if (data != null) {
            frame = data.getFrame();
        }
    }
    NodeLibrary nodeLibrary = NodeLibrary.getUncached(node);
    if (nodeLibrary.hasScope(node, frame)) {
        try {
            return nodeLibrary.getScope(node, frame, true);
        } catch (UnsupportedMessageException e) {
            throw CompilerDirectives.shouldNotReachHere(e);
        }
    } else {
        return null;
    }
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) CoverageData(org.graalvm.tools.lsp.server.utils.CoverageData) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Example 12 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class SourceCodeEvaluator method evalWithCoverageData.

private EvaluationResult evalWithCoverageData(TextDocumentSurrogate textDocumentSurrogate, Node nearestNode) {
    if (!textDocumentSurrogate.hasCoverageData()) {
        return EvaluationResult.createEvaluationSectionNotReached();
    }
    List<CoverageData> dataBeforeNode = findCoverageDataBeforeNode(textDocumentSurrogate, nearestNode);
    if (dataBeforeNode == null || dataBeforeNode.isEmpty()) {
        return EvaluationResult.createEvaluationSectionNotReached();
    }
    CoverageData coverageData = dataBeforeNode.get(dataBeforeNode.size() - 1);
    if (((InstrumentableNode) nearestNode).hasTag(StandardTags.ReadVariableTag.class)) {
        // Shortcut for variables
        InteropUtils.VariableInfo[] variables = InteropUtils.getNodeObjectVariables((InstrumentableNode) nearestNode);
        if (variables.length == 1) {
            InteropUtils.VariableInfo var = variables[0];
            NodeLibrary nodeLibrary = NodeLibrary.getUncached(nearestNode);
            if (nodeLibrary.hasScope(nearestNode, coverageData.getFrame())) {
                try {
                    Object scope = nodeLibrary.getScope(nearestNode, coverageData.getFrame(), true);
                    if (INTEROP.isMemberReadable(scope, var.getName())) {
                        logger.fine("Coverage-based variable look-up");
                        Object value = INTEROP.readMember(scope, var.getName());
                        return EvaluationResult.createResult(value);
                    }
                } catch (UnknownIdentifierException | UnsupportedMessageException ex) {
                    throw CompilerDirectives.shouldNotReachHere(ex);
                }
            }
        }
    }
    LanguageInfo info = nearestNode.getRootNode().getLanguageInfo();
    String code = nearestNode.getSourceSection().getCharacters().toString();
    Source inlineEvalSource = Source.newBuilder(info.getId(), code, "in-line eval (hover request)").cached(false).build();
    ExecutableNode executableNode = env.parseInline(inlineEvalSource, nearestNode, coverageData.getFrame());
    CoverageEventNode coverageEventNode = coverageData.getCoverageEventNode();
    coverageEventNode.insertOrReplaceChild(executableNode);
    try {
        logger.fine("Trying coverage-based eval...");
        Object result = executableNode.execute(coverageData.getFrame());
        return EvaluationResult.createResult(result);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        coverageEventNode.clearChild();
    }
    return EvaluationResult.createEvaluationSectionNotReached();
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) CoverageData(org.graalvm.tools.lsp.server.utils.CoverageData) InteropUtils(org.graalvm.tools.lsp.server.utils.InteropUtils) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) Source(com.oracle.truffle.api.source.Source) UnknownLanguageException(org.graalvm.tools.lsp.exceptions.UnknownLanguageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) IOException(java.io.IOException) EvaluationResultException(org.graalvm.tools.lsp.exceptions.EvaluationResultException) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 13 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class DebugStackFrame method initName.

// Initialize the stack frame name while we're on the execution thread
private String initName() throws DebugException {
    verifyValidState(false);
    Node node;
    if (currentFrame == null) {
        node = getContext().getInstrumentedNode();
    } else {
        node = currentFrame.getCallNode();
        node = InstrumentableNode.findInstrumentableParent(node);
    }
    try {
        if (node != null) {
            Frame frame = findTruffleFrame(FrameAccess.READ_ONLY);
            NodeLibrary nodeLibrary = NodeLibrary.getUncached();
            if (nodeLibrary.hasRootInstance(node, frame)) {
                Object instance = nodeLibrary.getRootInstance(node, frame);
                InteropLibrary interop = InteropLibrary.getUncached();
                if (interop.hasExecutableName(instance)) {
                    return interop.asString(interop.getExecutableName(instance));
                }
            }
        }
        RootNode root = findCurrentRoot();
        if (root == null) {
            return null;
        }
        return root.getName();
    } catch (ThreadDeath td) {
        throw td;
    } catch (Throwable ex) {
        RootNode root = findCurrentRoot();
        LanguageInfo languageInfo = root != null ? root.getLanguageInfo() : null;
        throw DebugException.create(event.getSession(), ex, languageInfo);
    }
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) RootNode(com.oracle.truffle.api.nodes.RootNode) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) Frame(com.oracle.truffle.api.frame.Frame) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 14 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class CompletionRequestHandler method fillCompletionsWithLocals.

private void fillCompletionsWithLocals(final TextDocumentSurrogate surrogate, Node nearestNode, List<CompletionItem> completions, MaterializedFrame frame) {
    NodeLibrary nodeLibrary = NodeLibrary.getUncached(nearestNode);
    if (nodeLibrary.hasScope(nearestNode, frame)) {
        try {
            Object scope = nodeLibrary.getScope(nearestNode, frame, true);
            fillCompletionsWithScopesValues(surrogate, completions, scope, CompletionItemKind.Variable, SORTING_PRIORITY_LOCALS);
        } catch (UnsupportedMessageException e) {
            throw CompilerDirectives.shouldNotReachHere(e);
        }
    }
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 15 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class DebugExprVarNode method findMemberAndType.

private Pair<Object, DebugExprType> findMemberAndType(VirtualFrame frameValue) {
    NodeLibrary nodeLibrary = NodeLibrary.getUncached();
    InteropLibrary interopLibrary = InteropLibrary.getUncached();
    try {
        LLVMDebuggerValue entries = (LLVMDebuggerValue) nodeLibrary.getScope(location, frameValue, true);
        if (interopLibrary.isMemberReadable(entries, name)) {
            Object member = interopLibrary.readMember(entries, name);
            LLVMDebuggerValue ldv = (LLVMDebuggerValue) member;
            Object metaObj = ldv.resolveMetaObject();
            DebugExprType type = DebugExprType.getTypeFromSymbolTableMetaObject(metaObj);
            return Pair.create(member, type);
        }
    } catch (ClassCastException e) {
        // OR metaObj is no primitive type
        throw DebugExprException.create(this, "\"%s\" cannot be casted to a LLVMDebuggerValue", name);
    } catch (UnsupportedMessageException e) {
        // should only happen if hasMembers == false
        throw DebugExprException.symbolNotFound(this, name, null);
    } catch (UnknownIdentifierException e) {
        throw DebugExprException.symbolNotFound(this, e.getUnknownIdentifier(), null);
    }
    // not found: no exception is thrown as this node might be a function name
    return Pair.create(null, DebugExprType.getVoidType());
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) DebugExprType(com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) LLVMDebuggerValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue)

Aggregations

NodeLibrary (com.oracle.truffle.api.interop.NodeLibrary)17 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)8 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)8 Node (com.oracle.truffle.api.nodes.Node)8 Test (org.junit.Test)8 RootNode (com.oracle.truffle.api.nodes.RootNode)6 Frame (com.oracle.truffle.api.frame.Frame)4 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)4 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)4 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)3 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)2 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)2 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)2 LLVMDebuggerValue (com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue)2 Context (org.graalvm.polyglot.Context)2 CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)2 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1