Search in sources :

Example 1 with LLVMNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode in project sulong by graalvm.

the class LLVMPrintStackTrace method fillStackTrace.

private static void fillStackTrace(SulongStackTrace stackTrace, Node node) {
    LLVMBasicBlockNode block = NodeUtil.findParent(node, LLVMBasicBlockNode.class);
    LLVMFunctionStartNode f = NodeUtil.findParent(node, LLVMFunctionStartNode.class);
    if (block == null || f == null) {
        LLVMIntrinsicExpressionNode intrinsic = NodeUtil.findParent(node, LLVMIntrinsicExpressionNode.class);
        if (intrinsic != null) {
            stackTrace.addStackTraceElement(intrinsic.toString(), null, null);
        }
        return;
    }
    LLVMSourceLocation location = null;
    if (node instanceof LLVMNode && ((LLVMNode) node).getSourceLocation() != null) {
        location = ((LLVMNode) node).getSourceLocation();
    }
    if (location == null) {
        location = block.getSourceLocation();
    }
    if (location != null) {
        stackTrace.addStackTraceElement(f.getOriginalName(), location, f.getBcName(), f.getBcSource().getName(), blockName(block));
        return;
    }
    SourceSection s = node.getSourceSection();
    if (s == null) {
        s = f.getSourceSection();
    }
    if (s == null) {
        stackTrace.addStackTraceElement(f.getBcName(), f.getBcSource().getName(), blockName(block));
    } else {
        location = LLVMSourceLocation.createUnknown(s);
        stackTrace.addStackTraceElement(f.getOriginalName(), location, f.getBcName(), f.getBcSource().getName(), blockName(block));
    }
}
Also used : LLVMFunctionStartNode(com.oracle.truffle.llvm.nodes.func.LLVMFunctionStartNode) LLVMIntrinsicExpressionNode(com.oracle.truffle.llvm.nodes.intrinsics.llvm.LLVMIntrinsicRootNode.LLVMIntrinsicExpressionNode) LLVMBasicBlockNode(com.oracle.truffle.llvm.nodes.base.LLVMBasicBlockNode) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode)

Example 2 with LLVMNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode in project sulong by graalvm.

the class LLVMSourceScope method create.

@TruffleBoundary
public static Iterable<Scope> create(Node node, Frame frame, LLVMContext context) {
    final LLVMSourceContext sourceContext = context.getSourceContext();
    final RootNode rootNode = node.getRootNode();
    LLVMNode llvmNode = findStatementNode(node);
    if (rootNode == null || llvmNode == null) {
        return Collections.singleton(new LLVMSourceScope(sourceContext, node).toScope(frame));
    }
    LLVMSourceLocation scope = llvmNode.getSourceLocation();
    final SourceSection sourceSection = llvmNode.getSourceSection();
    LLVMSourceScope baseScope = new LLVMSourceScope(sourceContext, new LinkedList<>(), rootNode);
    LLVMSourceScope staticScope = null;
    for (boolean isLocalScope = true; isLocalScope && scope != null; scope = scope.getParent()) {
        final LLVMSourceScope next = toScope(scope, sourceContext, rootNode, sourceSection);
        copySymbols(next, baseScope);
        if (scope.getKind() == LLVMSourceLocation.Kind.FUNCTION) {
            baseScope.setName(next.getName());
            if (scope.getCompileUnit() != null) {
                staticScope = toScope(scope.getCompileUnit(), sourceContext, null, sourceSection);
            }
            isLocalScope = false;
        }
    }
    List<Scope> scopeList = new ArrayList<>();
    scopeList.add(baseScope.toScope(frame));
    for (; scope != null; scope = scope.getParent()) {
        // e.g. lambdas are compiled to calls to a method in a locally defined class. We
        // cannot access the locals of the enclosing function since they do not lie on the
        // function's frame. They are still accessible from the calling function's frame, so
        // we can simply ignore this scope here. Also, any variables actually used in the
        // lambda would still be available as the members of the 'this' pointer.
        final LLVMSourceScope next = toScope(scope, sourceContext, null, sourceSection);
        switch(scope.getKind()) {
            case NAMESPACE:
            case FILE:
            case BLOCK:
                if (next.hasSymbols()) {
                    scopeList.add(next.toScope(frame));
                }
                break;
            case COMPILEUNIT:
                if (staticScope == null) {
                    staticScope = next;
                } else {
                    copySymbols(next, staticScope);
                }
                break;
        }
    }
    if (staticScope != null && staticScope.hasSymbols()) {
        scopeList.add(staticScope.toScope(frame));
    }
    return Collections.unmodifiableList(scopeList);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) ArrayList(java.util.ArrayList) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

SourceSection (com.oracle.truffle.api.source.SourceSection)2 LLVMNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Scope (com.oracle.truffle.api.Scope)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LLVMBasicBlockNode (com.oracle.truffle.llvm.nodes.base.LLVMBasicBlockNode)1 LLVMFunctionStartNode (com.oracle.truffle.llvm.nodes.func.LLVMFunctionStartNode)1 LLVMIntrinsicExpressionNode (com.oracle.truffle.llvm.nodes.intrinsics.llvm.LLVMIntrinsicRootNode.LLVMIntrinsicExpressionNode)1 LLVMSourceContext (com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext)1 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)1 ArrayList (java.util.ArrayList)1