Exemplo n.º 1
0
        private void SetExceptionEdges(InstructionSequence instrseq, Dictionary <int, BasicBlock
                                                                                 > instrBlocks)
        {
            exceptions = new List <ExceptionRangeCFG>();
            Dictionary <string, ExceptionRangeCFG> mapRanges = new Dictionary <string, ExceptionRangeCFG
                                                                               >();

            foreach (ExceptionHandler handler in instrseq.GetExceptionTable().GetHandlers())
            {
                BasicBlock from   = instrBlocks.GetOrNull(handler.from_instr);
                BasicBlock to     = instrBlocks.GetOrNull(handler.to_instr);
                BasicBlock handle = instrBlocks.GetOrNull(handler.handler_instr);
                string     key    = from.id + ":" + to.id + ":" + handle.id;
                if (mapRanges.ContainsKey(key))
                {
                    ExceptionRangeCFG range = mapRanges.GetOrNull(key);
                    range.AddExceptionType(handler.exceptionClass);
                }
                else
                {
                    List <BasicBlock> protectedRange = new List <BasicBlock>();
                    for (int j = from.id; j < to.id; j++)
                    {
                        BasicBlock block = blocks.GetWithKey(j);
                        protectedRange.Add(block);
                        block.AddSuccessorException(handle);
                    }
                    ExceptionRangeCFG range = new ExceptionRangeCFG(protectedRange, handle, handler.exceptionClass
                                                                    == null ? null : System.Linq.Enumerable.ToList(new [] { handler.exceptionClass })
                                                                    );
                    Sharpen.Collections.Put(mapRanges, key, range);
                    exceptions.Add(range);
                }
            }
        }
Exemplo n.º 2
0
        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);
        }