Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.BranchInstruction


            // i == old instruction; c == copied instruction
            Instruction i = ih.getInstruction();
            Instruction c = ch.getInstruction();

            if (i instanceof BranchInstruction) {
                BranchInstruction bc      = (BranchInstruction)c;
                BranchInstruction bi      = (BranchInstruction)i;
                InstructionHandle itarget = bi.getTarget(); // old target

                // New target must be in targetMap
                InstructionHandle newTarget =
                    (InstructionHandle)targetMap.get(itarget);
View Full Code Here


  if (hasNodeSetArgs() || hasReferenceArgs()) {
      translate(classGen, methodGen);
      desynthesize(classGen, methodGen);
  }
  else {
      BranchInstruction bi = null;
      final InstructionList il = methodGen.getInstructionList();

      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
View Full Code Here

            // i == old instruction; c == copied instruction
            Instruction i = ih.getInstruction();
            Instruction c = ch.getInstruction();

            if (i instanceof BranchInstruction) {
                BranchInstruction bc      = (BranchInstruction)c;
                BranchInstruction bi      = (BranchInstruction)i;
                InstructionHandle itarget = bi.getTarget(); // old target

                // New target must be in targetMap
                InstructionHandle newTarget =
                    (InstructionHandle)targetMap.get(itarget);
View Full Code Here

  if (hasNodeSetArgs() || hasReferenceArgs()) {
      translate(classGen, methodGen);
      desynthesize(classGen, methodGen);
  }
  else {
      BranchInstruction bi = null;
      final InstructionList il = methodGen.getInstructionList();

      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
View Full Code Here

            int pos;
            while (sequence.available() > 0 && ((pos = sequence.getIndex()) < end)) {
                Instruction ins = Instruction.readInstruction(sequence);
                if ((ins instanceof BranchInstruction) && !(ins instanceof TABLESWITCH) && !(ins instanceof LOOKUPSWITCH)) {
                    BranchInstruction bi = (BranchInstruction) ins;
                    int offset = bi.getIndex();
                    int target = offset + pos;
                    if (target >= end) { // or target < start ??
                        byte hiByte = (byte) ((target >> 8) & 0x000000FF);
                        byte loByte = (byte) (target & 0x000000FF);
                        bytes[pos + bi.getLength() - 2 - start] = hiByte;
                        bytes[pos + bi.getLength() - 1 - start] = loByte;
                    }
                }
            }
        } catch (IOException ioe) {
        }
View Full Code Here

    }


    private void updateBranchTargets() {
        for (Iterator i = branches.iterator(); i.hasNext();) {
            BranchInstruction bi = (BranchInstruction) i.next();
            BranchHandle bh = (BranchHandle) branch_map.get(bi);
            int pos = bh.getPosition();
            String name = bi.getName() + "_" + pos;
            int t_pos = bh.getTarget().getPosition();
            _out.println("    " + name + ".setTarget(ih_" + t_pos + ");");
            if (bi instanceof Select) {
                InstructionHandle[] ihs = ((Select) bi).getTargets();
                for (int j = 0; j < ihs.length; j++) {
View Full Code Here

     */
    map = new Hashtable();

    for(int i=0; i < ihs.length; i++) {
      if(ihs[i] instanceof BranchHandle) {
  BranchInstruction bi = (BranchInstruction)ihs[i].getInstruction();
 
  if(bi instanceof Select) { // Special cases LOOKUPSWITCH and TABLESWITCH
    InstructionHandle[] targets = ((Select)bi).getTargets();
   
    for(int j=0; j < targets.length; j++) {
        put(targets[j], "Label" + label_counter++ + ":");
    }
  }

  InstructionHandle ih = bi.getTarget();
  put(ih, "Label" + label_counter++ + ":");
      }
    }

    LocalVariableGen[] lvs = mg.getLocalVariables();
    for(int i=0; i < lvs.length; i++) {
      InstructionHandle ih = lvs[i].getStart();
      put(ih, "Label" + label_counter++ + ":");
      ih = lvs[i].getEnd();
      put(ih, "Label" + label_counter++ + ":")
    }
   
    CodeExceptionGen[] ehs = mg.getExceptionHandlers();
    for(int i=0; i < ehs.length; i++) {
      CodeExceptionGen  c  = ehs[i];
      InstructionHandle ih = c.getStartPC();

      put(ih, "Label" + label_counter++ + ":")
      ih = c.getEndPC();
      put(ih, "Label" + label_counter++ + ":")
      ih = c.getHandlerPC();
      put(ih, "Label" + label_counter++ + ":")
    }

    LineNumberGen[] lns = mg.getLineNumbers();
    for(int i=0; i < lns.length; i++) {
      InstructionHandle ih = lns[i].getInstruction();
      put(ih, ".line " + lns[i].getSourceLine());
    }
    /* Pass 2: Output code.
     */
    for(int i=0; i < lvs.length; i++) {
      LocalVariableGen l = lvs[i];
      out.println(".var " + l.getIndex() + " is " + l.getName() + " " +
      l.getType().getSignature() +
      " from " + get(l.getStart()) +
      " to " + get(l.getEnd()));
    }

    out.print("\n");
   
    for(int i=0; i < ihs.length; i++) {
      InstructionHandle ih   = ihs[i];
      Instruction       inst = ih.getInstruction();
      String            str  = (String)map.get(ih);
     
      if(str != null) {
        out.println(str);
    }

      if(inst instanceof BranchInstruction) {
  if(inst instanceof Select) { // Special cases LOOKUPSWITCH and TABLESWITCH
    Select              s       = (Select)inst;
    int[]               matchs  = s.getMatchs();
    InstructionHandle[] targets = s.getTargets();
   
    if(s instanceof TABLESWITCH) {
      out.println("\ttableswitch " + matchs[0] + " " +
      matchs[matchs.length - 1]);
     
      for(int j=0; j < targets.length; j++) {
            out.println("\t\t" + get(targets[j]));
        }

    } else { // LOOKUPSWITCH
      out.println("\tlookupswitch ");

      for(int j=0; j < targets.length; j++) {
            out.println("\t\t" + matchs[j] + " : " + get(targets[j]));
        }
    }

    out.println("\t\tdefault: " + get(s.getTarget())); // Applies for both
  } else {
    BranchInstruction bi  = (BranchInstruction)inst;
    ih  = bi.getTarget();
    str = get(ih);
    out.println("\t" + Constants.OPCODE_NAMES[bi.getOpcode()] + " " + str);
  }
      } else {
        out.println("\t" + inst.toString(cp.getConstantPool()));
    }
    }
View Full Code Here

    String      pat = "IF_ICMP ICONST_1 GOTO ICONST_0 IFEQ Instruction";

    for(Iterator it = f.search(pat, my_constraint); it.hasNext();) {
      InstructionHandle[] match = (InstructionHandle[])it.next();
      // Everything ok, update code
      BranchInstruction ifeq    = (BranchInstruction)(match[4].getInstruction());
      BranchHandle      if_icmp = (BranchHandle)match[0];

      if_icmp.setTarget(ifeq.getTarget());

      try {
  il.delete(match[1], match[4]);
      } catch(TargetLostException e) {
  InstructionHandle[] targets = e.getTargets();
View Full Code Here

  if (hasNodeSetArgs() || hasReferenceArgs()) {
      translate(classGen, methodGen);
      desynthesize(classGen, methodGen);
  }
  else {
      BranchInstruction bi = null;
      final InstructionList il = methodGen.getInstructionList();

      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
View Full Code Here

      // To close the last branch, I must jump to super.invokeImpl(), so I need its first instruction here
      InstructionHandle invokeSuper = implementation.append(factory.createThis());
      for (int i = 0; i < tests.size(); ++i)
      {
         BranchInstruction branch = (BranchInstruction)tests.get(i);
         branch.setTarget(invokeSuper);
      }
      tests.clear();
      for (int i = 0; i < catches.size(); ++i)
      {
         BranchInstruction branch = (BranchInstruction)catches.get(i);
         branch.setTarget(invokeSuper);
      }
      catches.clear();

      //
      // return super.invokeImpl(metadata, method, params, args);
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.BranchInstruction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.