示例#1
0
        /// <summary>
        /// Marks blocks that are recursively reachable from the given block.
        /// </summary>
        private static void MarkReachableFrom(ArrayBuilder <BasicBlock> reachableBlocks, BasicBlock block)
        {
tryAgain:

            if (block != null && block.Reachability == Reachability.NotReachable)
            {
                block.Reachability = Reachability.Reachable;

                ILOpCode branchCode = block.BranchCode;
                if (branchCode == ILOpCode.Nop && block.Type == BlockType.Normal)
                {
                    block = block.NextBlock;
                    goto tryAgain;
                }

                if (branchCode.CanFallThrough())
                {
                    PushReachableBlockToProcess(reachableBlocks, block.NextBlock);
                }
                else
                {
                    // If this block is an "endfinally" block, then clear
                    // the reachability of the following special block.
                    if (branchCode == ILOpCode.Endfinally)
                    {
                        ExceptionHandlerScope enclosingFinally = block.EnclosingHandler;
                        enclosingFinally?.UnblockFinally();
                    }
                }

                switch (block.Type)
                {
                case BlockType.Switch:
                    MarkReachableFromSwitch(reachableBlocks, block);
                    break;

                case BlockType.Try:
                    MarkReachableFromTry(reachableBlocks, block);
                    break;

                default:
                    MarkReachableFromBranch(reachableBlocks, block);
                    break;
                }
            }
        }