private static short[] FindStartInstructions(InstructionSequence seq)
        {
            int len = seq.Length();

            short[]       inststates = new short[len];
            HashSet <int> excSet     = new HashSet <int>();

            foreach (ExceptionHandler handler in seq.GetExceptionTable().GetHandlers())
            {
                excSet.Add(handler.from_instr);
                excSet.Add(handler.to_instr);
                excSet.Add(handler.handler_instr);
            }
            for (int i = 0; i < len; i++)
            {
                // exception blocks
                if (excSet.Contains(i))
                {
                    inststates[i] = 1;
                }
                Instruction instr = seq.GetInstr(i);
                switch (instr.group)
                {
                case Group_Jump:
                {
                    inststates[((JumpInstruction)instr).destination] = 1;
                    goto case Group_Return;
                }

                case Group_Return:
                {
                    if (i + 1 < len)
                    {
                        inststates[i + 1] = 1;
                    }
                    break;
                }

                case Group_Switch:
                {
                    SwitchInstruction swinstr = (SwitchInstruction)instr;
                    int[]             dests   = swinstr.GetDestinations();
                    for (int j = dests.Length - 1; j >= 0; j--)
                    {
                        inststates[dests[j]] = 1;
                    }
                    inststates[swinstr.GetDefaultDestination()] = 1;
                    if (i + 1 < len)
                    {
                        inststates[i + 1] = 1;
                    }
                    break;
                }
                }
            }
            // first instruction
            inststates[0] = 1;
            return(inststates);
        }
        private static void ConnectBlocks(List <BasicBlock> lstbb, Dictionary <int, BasicBlock
                                                                               > mapInstrBlocks)
        {
            for (int i = 0; i < lstbb.Count; i++)
            {
                BasicBlock  block       = lstbb[i];
                Instruction instr       = block.GetLastInstruction();
                bool        fallthrough = instr.CanFallThrough();
                BasicBlock  bTemp;
                switch (instr.group)
                {
                case Group_Jump:
                {
                    int dest = ((JumpInstruction)instr).destination;
                    bTemp = mapInstrBlocks.GetOrNull(dest);
                    block.AddSuccessor(bTemp);
                    break;
                }

                case Group_Switch:
                {
                    SwitchInstruction sinstr = (SwitchInstruction)instr;
                    int[]             dests  = sinstr.GetDestinations();
                    bTemp = mapInstrBlocks.GetOrNull(((SwitchInstruction)instr).GetDefaultDestination
                                                         ());
                    block.AddSuccessor(bTemp);
                    foreach (int dest1 in dests)
                    {
                        bTemp = mapInstrBlocks.GetOrNull(dest1);
                        block.AddSuccessor(bTemp);
                    }
                    break;
                }
                }
                if (fallthrough && i < lstbb.Count - 1)
                {
                    BasicBlock defaultBlock = lstbb[i + 1];
                    block.AddSuccessor(defaultBlock);
                }
            }
        }