コード例 #1
0
 /**
  * Create the edges in the control flow graph with the basic blocks.
  *
  * @param insts the instructions
  * @param numBlocks an array containing the number of basic block for each instruction.
  * @param bbs the basic blocks
  */
 private void findCFGEdges(Instruction[] insts, short[] numBlocks, BasicBlock[] bbs) {
   for (int i = 0; i < bbs.length; ++i) {
     BasicBlock bb = bbs[i];
     Instruction lastInst = insts[bb.getEnd()];
     if (lastInst.canComplete() && i != bbs.length - 1) {
       // the next block is accessible
       bb.addDefaultNextBlock(bbs[i + 1]);
     }
     if (lastInst instanceof JumpInstruction) {
       // goto, jsr are distincts than other jump instructions.
       Edge edge;
       JumpInstruction jumpInst = (JumpInstruction) lastInst;
       if (lastInst.getOpcode() == ClassfileConstants2.opc_goto) {
         edge =
             bb.addDefaultNextBlock(
                 bbs[numBlocks[getInstructionLine(insts, jumpInst.getTarget())]]);
         jumpInst.setTarget(new EdgeLabel(edge));
       } else if (lastInst.getOpcode() == ClassfileConstants2.opc_jsr) {
         // do nothing here
         // see method findSubRoutines
       } else {
         edge =
             bb.addConditionNextBlock(
                 bbs[numBlocks[getInstructionLine(insts, jumpInst.getTarget())]]);
         jumpInst.setTarget(new EdgeLabel(edge));
       }
     }
     if (lastInst instanceof SwitchInstruction) {
       SwitchInstruction si = (SwitchInstruction) lastInst;
       for (int k = -1; k < si.getSwitchCount(); k++) {
         Edge edge =
             bb.addSwitchNextBlock(bbs[numBlocks[getInstructionLine(insts, si.getTarget(k))]]);
         si.setTarget(k, new EdgeLabel(edge));
       }
     }
   }
 }