Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jruby.ir.representations;
  
  import java.util.List;
 
 public class BasicBlock implements ExplicitVertexID {
     private int         id;             // Basic Block id
     private CFG         cfg;            // CFG that this basic block belongs to
     private Label       label;          // All basic blocks have a starting label
     private List<Instrinstrs;         // List of non-label instructions
     private boolean     isRescueEntry;  // Is this basic block entry of a rescue?
     private Instr[]     instrsArray;
 
     public BasicBlock(CFG cLabel l) {
                  = l;
                    = c;
                     = c.getNextBBID();
                 = new ArrayList<Instr>();
            = null;
          = false;
     }
 
     public int getID() {
         return ;
     }
 
     public Label getLabel() {
         return ;
     }
 
     public void markRescueEntryBB() {
         this. = true;
     }
 
     public boolean isRescueEntry() {
         return this.;
     }
 
     public void addInstr(Instr i) {
         .add(i);
     }
 
     public void insertInstr(Instr i) {
         .add(0, i);
     }
 
     public List<InstrgetInstrs() {
         return ;
     }
 
     public int instrCount() {
         return .size();
     }
 
     public Instr[] getInstrsArray() {
         if ( == null = .toArray(new Instr[.size()]);
 
         return ;
     }
 
     public Instr getLastInstr() {
         int n = .size();
         return (n == 0) ? null : .get(n-1);
     }
 
     public boolean removeInstr(Instr i) {
        return i == nullfalse : .remove(i);
     }
 
     public boolean isEmpty() {
         return .isEmpty();
     }
 
     public BasicBlock splitAtInstruction(Instr splitPointLabel newLabelboolean includeSplitPointInstr) {
         BasicBlock newBB = new BasicBlock(newLabel);
         int idx = 0;
         int numInstrs = .size();
         boolean found = false;
         for (Instr i) {
             if (i == splitPointfound = true;
 
             // Move instructions from split point into the new bb
             if (found) {
                 if (includeSplitPointInstr || i != splitPointnewBB.addInstr(i);
             } else {
                 idx++;
             }
         }
 
         // Remove all instructions from current bb that were moved over.
        for (int j = 0; j < numInstrs-idxj++) {
            .remove(idx);
        }
        return newBB;
    }
    public void swallowBB(BasicBlock foodBB) {
        // Gulp!
        this..addAll(foodBB.instrs);
    }
        IRScope hostScope = ii.getInlineHostScope();
        BasicBlock clonedBB = ii.getOrCreateRenamedBB(this);
        for (Instr igetInstrs()) {
            Instr clonedInstr = i.cloneForInlinedScope(ii);
            if (clonedInstr != null) {
                clonedBB.addInstr(clonedInstr);
                if (clonedInstr instanceof YieldInstrii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr);
                if (clonedInstr instanceof CallBase) {
                    CallBase call = (CallBase)clonedInstr;
                    Operand block = call.getClosureArg(null);
                    if (block instanceof WrappedIRClosurehostScope.addClosure(((WrappedIRClosure)block).getClosure());
                }
            }
        }
        return clonedBB;
    }
        // Update cfg for this bb
        IRScope hostScope = ii.getInlineHostScope();
        BasicBlock clonedBB = ii.getOrCreateRenamedBB(this);
        // Process instructions
        for (Instr igetInstrs()) {
            Instr clonedInstr = i.cloneForInlinedClosure(ii);
            if (clonedInstr != null) {
                clonedBB.addInstr(clonedInstr);
                if (clonedInstr instanceof CallBase) {
                    CallBase call = (CallBase)clonedInstr;
                    Operand block = call.getClosureArg(null);
                    if (block instanceof WrappedIRClosurehostScope.addClosure(((WrappedIRClosure)block).getClosure());
                }
            }
        }
        return clonedBB;
    }
    @Override
    public String toString() {
        return "BB [" +  + ":" +  + "]";
    }
    public String toStringInstrs() {
        StringBuilder buf = new StringBuilder(toString() + "\n");
        for (Instr instr : getInstrs()) {
            buf.append('\t').append(instr).append('\n');
        }
        
        return buf.toString();
    }
New to GrepCode? Check out our FAQ X