Пример #1
0
 public bool BeginsCatch(BasicBlock bb)
 {
     ExceptionHandler handler = printer.StartsHandlerRegion (bb.FirstInstruction);
     if (handler != null && handler.Type == ExceptionHandlerType.Catch)
         return true;
     return false;
 }
Пример #2
0
    private void BuildGraph() {
        BasicBlock tail = null;
        Instruction prevInsn = null;
        BasicBlock prevBB = null;
        int currentInsnNum = 0;
        Hashtable insnBB = new Hashtable();
        BasicBlock exit = new BasicBlock(instructions);
        exit.first = exit.last = 0;
        exit.isExit = true;
        AddNode(exit);

        foreach(Instruction insn in instructions) {
            if (printer.IsLeader (insn, prevInsn)) {
                tail = new BasicBlock(instructions);
                tail.first = currentInsnNum;
                AddNode(tail);
                if(prevBB != null) {
                    prevBB.last = currentInsnNum - 1;
                    if(HasNext(instructions[currentInsnNum - 1])) {
                        CFGEdge edge = new CFGEdge(prevBB, tail,
                                CFGEdgeType.Forward);
                        AddEdge(edge);
                    }
                }
            }
            insnBB.Add(insn.Offset, tail);
            prevInsn = insn;
            prevBB = tail;
            currentInsnNum++;
        }
        if(prevBB != null) {
            prevBB.last = currentInsnNum - 1;
        }

        foreach(Instruction insn in instructions) {
            if ((printer.EndsTryRegion (insn) != null) ||
                    (printer.EndsHandlerRegion (insn) != null)) { 
                BasicBlock finallyBB = GetNearestFinally(insn, insnBB);
                if(finallyBB != null)
                    AddEdge(new CFGEdge((BasicBlock)insnBB[insn.Offset],
                                finallyBB, CFGEdgeType.Forward));
            }

            if(insn.OpCode.FlowControl == FlowControl.Return) {
                if(insn.OpCode.Code == Code.Endfinally &&
                        insn.Next != null) {
                    AddEdge(new CFGEdge((BasicBlock)insnBB[insn.Offset],
                                (BasicBlock)insnBB[insn.Next.Offset],
                                CFGEdgeType.Forward));
                } else {
                    AddEdge(new CFGEdge((BasicBlock)insnBB[insn.Offset],
                                exit, CFGEdgeType.Return));
                }
            }
            /*
            if((insn.OpCode.Value != OpCodeConstants.Leave) &&
                    (insn.OpCode.Value != OpCodeConstants.Endfinally)) {
                    */
                int[] targets = MethodPrinter.BranchTargets (insn);
                if(targets == null)
                    continue;
                foreach(int target in targets) {
                    AddEdge(new CFGEdge((BasicBlock)insnBB[insn.Offset],
                                (BasicBlock)insnBB[target],
                                CFGEdgeType.Branch));
                }
            /*} */
        }

        entryPoint = (BasicBlock)insnBB[0];
    }