Пример #1
0
        private void AddPotentialHandlerSuccessors(
            ICollection <ControlFlowNode <TInstruction> > result,
            ControlFlowNode <TInstruction> node)
        {
            var ehRegion = node.GetParentExceptionHandler();

            while (ehRegion is {})
Пример #2
0
        private IReadOnlyList <ControlFlowNode <TInstruction> > ChildrenLister(ControlFlowNode <TInstruction> node)
        {
            // NOTE: Order of the resulting list is important.
            //       We want to prioritize normal edges over abnormal edges and exception handlers.

            var visited = new HashSet <ControlFlowNode <TInstruction> >();
            var result  = new List <ControlFlowNode <TInstruction> >();

            // Add fallthrough.
            if (node.FallThroughNeighbour is {} neighbour)
            {
                result.Add(neighbour);
                visited.Add(neighbour);
            }

            // Conditional edges.
            foreach (var edge in node.ConditionalEdges)
            {
                var target = edge.Target;
                if (visited.Add(target))
                {
                    result.Add(target);
                }
            }

            // Abnormal edges.
            foreach (var edge in node.AbnormalEdges)
            {
                var target = edge.Target;
                if (visited.Add(target))
                {
                    result.Add(target);
                }
            }

            // Check if any exception handler might catch an error within this node.
            var ehRegion = node.GetParentExceptionHandler();

            while (ehRegion is {})
Пример #3
0
        private void AddPotentialHandlerSuccessors(
            ICollection <ControlFlowNode <TInstruction> > result,
            ControlFlowNode <TInstruction> node)
        {
            // If the node is in an exception handler, here are a couple of "implicit" successors.
            //
            // - Any node in the protected region has an implicit successor to the start of every handler region.
            //
            // - Any node in a prologue/body/epilogue of a handler region has an implicit successor of the next
            //   embedded region. That is, a prologue node can transfer control to the body, and body to epilogue.
            //
            // - Any node in a handler region also implicitly can transfer control to one of the successors of any
            //   node in the protected region (e.g. a try-finally construct does not have explicit outgoing branches).
            //
            // These successors are not explicitly encoded as an edge in the input CFG, but do often matter
            // when it comes to ordering these nodes (e.g. CIL requires handlers to be after the protected region).
            // Therefore, we add these as "virtual" successors to the list, to ensure the topological sorting
            // takes this into account.

            var ehRegion = node.GetParentExceptionHandler();

            while (ehRegion is { })