com.android.dx.rop.code.SourcePosition Java Examples

The following examples show how to use com.android.dx.rop.code.SourcePosition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RopperMachine.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Sets or updates the information about the return block.
 *
 * @param op {@code non-null;} the opcode to use
 * @param pos {@code non-null;} the position to use
 */
private void updateReturnOp(Rop op, SourcePosition pos) {
    if (op == null) {
        throw new NullPointerException("op == null");
    }

    if (pos == null) {
        throw new NullPointerException("pos == null");
    }

    if (returnOp == null) {
        returnOp = op;
        returnPosition = pos;
    } else {
        if (returnOp != op) {
            throw new SimException("return op mismatch: " + op + ", " +
                                   returnOp);
        }

        if (pos.getLine() > returnPosition.getLine()) {
            // Pick the largest line number to be the "canonical" return.
            returnPosition = pos;
        }
    }
}
 
Example #2
Source File: BlockAddresses.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();

    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);

        starts[label] = new CodeAddress(insn.getPosition());

        SourcePosition pos = one.getLastInsn().getPosition();

        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
 
Example #3
Source File: DalvInsn.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * <p><b>Note:</b> In the unlikely event that an instruction takes
 * absolutely no registers (e.g., a {@code nop} or a
 * no-argument no-result static method call), then the given
 * register list may be passed as {@link
 * RegisterSpecList#EMPTY}.</p>
 *
 * @param opcode the opcode; one of the constants from {@link Dops}
 * @param position {@code non-null;} source position
 * @param registers {@code non-null;} register list, including a
 * result register if appropriate (that is, registers may be either
 * ins and outs)
 */
public DalvInsn(Dop opcode, SourcePosition position,
                RegisterSpecList registers) {
    if (opcode == null) {
        throw new NullPointerException("opcode == null");
    }

    if (position == null) {
        throw new NullPointerException("position == null");
    }

    if (registers == null) {
        throw new NullPointerException("registers == null");
    }

    this.address = -1;
    this.opcode = opcode;
    this.position = position;
    this.registers = registers;
}
 
Example #4
Source File: RopTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitFillArrayDataInsn(FillArrayDataInsn insn) {
    SourcePosition pos = insn.getPosition();
    Constant cst = insn.getConstant();
    ArrayList<Constant> values = insn.getInitValues();
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_NONE) {
        throw new RuntimeException("shouldn't happen");
    }
    CodeAddress dataAddress = new CodeAddress(pos);
    ArrayData dataInsn =
        new ArrayData(pos, lastAddress, values, cst);

    TargetInsn fillArrayDataInsn =
        new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
                dataAddress);

    addOutput(lastAddress);
    addOutput(fillArrayDataInsn);

    addOutputSuffix(new OddSpacer(pos));
    addOutputSuffix(dataAddress);
    addOutputSuffix(dataInsn);
}
 
Example #5
Source File: RopTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitInvokePolymorphicInsn(InvokePolymorphicInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_THROW) {
        throw new RuntimeException("Expected BRANCH_THROW got " + rop.getBranchingness());
    } else if (!rop.isCallLike()) {
        throw new RuntimeException("Expected call-like operation");
    }

    addOutput(lastAddress);

    RegisterSpecList regs = insn.getSources();
    Constant[] constants = new Constant[] {
        insn.getPolymorphicMethod(),
        insn.getCallSiteProto()
        };
    DalvInsn di = new MultiCstInsn(opcode, pos, regs, constants);

    addOutput(di);
}
 
Example #6
Source File: RopTranslator.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void visitThrowingInsn(ThrowingInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();
    RegisterSpec realResult;

    if (rop.getBranchingness() != Rop.BRANCH_THROW) {
        throw new RuntimeException("shouldn't happen");
    }

    realResult = getNextMoveResultPseudo();

    if (opcode.hasResult() != (realResult != null)) {
        throw new RuntimeException(
                "Insn with result/move-result-pseudo mismatch" + insn);
    }

    addOutput(lastAddress);

    DalvInsn di = new SimpleInsn(opcode, pos,
            getRegs(insn, realResult));

    addOutput(di);
}
 
Example #7
Source File: BlockAddresses.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();

    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);

        starts[label] = new CodeAddress(insn.getPosition());

        SourcePosition pos = one.getLastInsn().getPosition();

        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
 
Example #8
Source File: RopperMachine.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Sets or updates the information about the return block.
 *
 * @param op {@code non-null;} the opcode to use
 * @param pos {@code non-null;} the position to use
 */
private void updateReturnOp(Rop op, SourcePosition pos) {
    if (op == null) {
        throw new NullPointerException("op == null");
    }

    if (pos == null) {
        throw new NullPointerException("pos == null");
    }

    if (returnOp == null) {
        returnOp = op;
        returnPosition = pos;
    } else {
        if (returnOp != op) {
            throw new SimException("return op mismatch: " + op + ", " +
                                   returnOp);
        }

        if (pos.getLine() > returnPosition.getLine()) {
            // Pick the largest line number to be the "canonical" return.
            returnPosition = pos;
        }
    }
}
 
Example #9
Source File: DalvInsn.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * <p><b>Note:</b> In the unlikely event that an instruction takes
 * absolutely no registers (e.g., a {@code nop} or a
 * no-argument no-result static method call), then the given
 * register list may be passed as {@link
 * RegisterSpecList#EMPTY}.</p>
 *
 * @param opcode the opcode; one of the constants from {@link Dops}
 * @param position {@code non-null;} source position
 * @param registers {@code non-null;} register list, including a
 * result register if appropriate (that is, registers may be either
 * ins and outs)
 */
public DalvInsn(Dop opcode, SourcePosition position,
                RegisterSpecList registers) {
    if (opcode == null) {
        throw new NullPointerException("opcode == null");
    }

    if (position == null) {
        throw new NullPointerException("position == null");
    }

    if (registers == null) {
        throw new NullPointerException("registers == null");
    }

    this.address = -1;
    this.opcode = opcode;
    this.position = position;
    this.registers = registers;
}
 
Example #10
Source File: DalvInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a move instruction, appropriate and ideal for the given arguments.
 *
 * @param position {@code non-null;} source position information
 * @param dest {@code non-null;} destination register
 * @param src {@code non-null;} source register
 * @return {@code non-null;} an appropriately-constructed instance
 */
public static SimpleInsn makeMove(SourcePosition position,
        RegisterSpec dest, RegisterSpec src) {
    boolean category1 = dest.getCategory() == 1;
    boolean reference = dest.getType().isReference();
    int destReg = dest.getReg();
    int srcReg = src.getReg();
    Dop opcode;

    if ((srcReg | destReg) < 16) {
        opcode = reference ? Dops.MOVE_OBJECT :
            (category1 ? Dops.MOVE : Dops.MOVE_WIDE);
    } else if (destReg < 256) {
        opcode = reference ? Dops.MOVE_OBJECT_FROM16 :
            (category1 ? Dops.MOVE_FROM16 : Dops.MOVE_WIDE_FROM16);
    } else {
        opcode = reference ? Dops.MOVE_OBJECT_16 :
            (category1 ? Dops.MOVE_16 : Dops.MOVE_WIDE_16);
    }

    return new SimpleInsn(opcode, position,
                          RegisterSpecList.make(dest, src));
}
 
Example #11
Source File: DalvInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a move instruction, appropriate and ideal for the given arguments.
 *
 * @param position {@code non-null;} source position information
 * @param dest {@code non-null;} destination register
 * @param src {@code non-null;} source register
 * @return {@code non-null;} an appropriately-constructed instance
 */
public static SimpleInsn makeMove(SourcePosition position,
        RegisterSpec dest, RegisterSpec src) {
    boolean category1 = dest.getCategory() == 1;
    boolean reference = dest.getType().isReference();
    int destReg = dest.getReg();
    int srcReg = src.getReg();
    Dop opcode;

    if ((srcReg | destReg) < 16) {
        opcode = reference ? Dops.MOVE_OBJECT :
            (category1 ? Dops.MOVE : Dops.MOVE_WIDE);
    } else if (destReg < 256) {
        opcode = reference ? Dops.MOVE_OBJECT_FROM16 :
            (category1 ? Dops.MOVE_FROM16 : Dops.MOVE_WIDE_FROM16);
    } else {
        opcode = reference ? Dops.MOVE_OBJECT_16 :
            (category1 ? Dops.MOVE_16 : Dops.MOVE_WIDE_16);
    }

    return new SimpleInsn(opcode, position,
                          RegisterSpecList.make(dest, src));
}
 
Example #12
Source File: RopTranslator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
      @Override
public void visitFillArrayDataInsn(FillArrayDataInsn insn) {
          SourcePosition pos = insn.getPosition();
          Constant cst = insn.getConstant();
          ArrayList<Constant> values = insn.getInitValues();
          Rop rop = insn.getOpcode();

          if (rop.getBranchingness() != Rop.BRANCH_NONE) {
              throw new RuntimeException("shouldn't happen");
          }
          CodeAddress dataAddress = new CodeAddress(pos);
          ArrayData dataInsn =
              new ArrayData(pos, lastAddress, values, cst);

          TargetInsn fillArrayDataInsn =
              new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
                      dataAddress);

          addOutput(lastAddress);
          addOutput(fillArrayDataInsn);

          addOutputSuffix(new OddSpacer(pos));
          addOutputSuffix(dataAddress);
          addOutputSuffix(dataInsn);
      }
 
Example #13
Source File: RopTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitInvokePolymorphicInsn(InvokePolymorphicInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_THROW) {
        throw new RuntimeException("Expected BRANCH_THROW got " + rop.getBranchingness());
    } else if (!rop.isCallLike()) {
        throw new RuntimeException("Expected call-like operation");
    }

    addOutput(lastAddress);

    RegisterSpecList regs = insn.getSources();
    Constant[] constants = new Constant[] {
        insn.getPolymorphicMethod(),
        insn.getCallSiteProto()
        };
    DalvInsn di = new MultiCstInsn(opcode, pos, regs, constants);

    addOutput(di);
}
 
Example #14
Source File: DalvInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * <p><b>Note:</b> In the unlikely event that an instruction takes
 * absolutely no registers (e.g., a {@code nop} or a
 * no-argument no-result static method call), then the given
 * register list may be passed as {@link
 * RegisterSpecList#EMPTY}.</p>
 *
 * @param opcode the opcode; one of the constants from {@link Dops}
 * @param position {@code non-null;} source position
 * @param registers {@code non-null;} register list, including a
 * result register if appropriate (that is, registers may be either
 * ins and outs)
 */
public DalvInsn(Dop opcode, SourcePosition position,
                RegisterSpecList registers) {
    if (opcode == null) {
        throw new NullPointerException("opcode == null");
    }

    if (position == null) {
        throw new NullPointerException("position == null");
    }

    if (registers == null) {
        throw new NullPointerException("registers == null");
    }

    this.address = -1;
    this.opcode = opcode;
    this.position = position;
    this.registers = registers;
}
 
Example #15
Source File: BlockAddresses.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();

    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);

        starts[label] = new CodeAddress(insn.getPosition());

        SourcePosition pos = one.getLastInsn().getPosition();

        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
 
Example #16
Source File: PositionList.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param address {@code >= 0;} address of this entry
 * @param position {@code non-null;} corresponding source position information
 */
public Entry (int address, SourcePosition position) {
    if (address < 0) {
        throw new IllegalArgumentException("address < 0");
    }

    if (position == null) {
        throw new NullPointerException("position == null");
    }

    this.address = address;
    this.position = position;
}
 
Example #17
Source File: SwitchData.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param user {@code non-null;} address representing the instruction that
 * uses this instance
 * @param cases {@code non-null;} sorted list of switch cases (keys)
 * @param targets {@code non-null;} corresponding list of code addresses; the
 * branch target for each case
 */
public SwitchData(SourcePosition position, CodeAddress user,
                  IntList cases, CodeAddress[] targets) {
    super(position, RegisterSpecList.EMPTY);

    if (user == null) {
        throw new NullPointerException("user == null");
    }

    if (cases == null) {
        throw new NullPointerException("cases == null");
    }

    if (targets == null) {
        throw new NullPointerException("targets == null");
    }

    int sz = cases.size();

    if (sz != targets.length) {
        throw new IllegalArgumentException("cases / targets mismatch");
    }

    if (sz > 65535) {
        throw new IllegalArgumentException("too many cases");
    }

    this.user = user;
    this.cases = cases;
    this.targets = targets;
    this.packed = shouldPack(cases);
}
 
Example #18
Source File: PhiInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns human-readable string for listing dumps. This method
 * allows sub-classes to specify extra text.
 *
 * @param extra {@code null-ok;} the argument to print after the opcode
 * @return human-readable string for listing dumps
 */
protected final String toHumanWithInline(String extra) {
    StringBuilder sb = new StringBuilder(80);

    sb.append(SourcePosition.NO_INFO);
    sb.append(": phi");

    if (extra != null) {
        sb.append("(");
        sb.append(extra);
        sb.append(")");
    }

    RegisterSpec result = getResult();

    if (result == null) {
        sb.append(" .");
    } else {
        sb.append(" ");
        sb.append(result.toHuman());
    }

    sb.append(" <-");

    int sz = getSources().size();
    if (sz == 0) {
        sb.append(" .");
    } else {
        for (int i = 0; i < sz; i++) {
            sb.append(" ");
            sb.append(sources.get(i).toHuman()
                    + "[b="
                    + Hex.u2(operands.get(i).ropLabel)  + "]");
        }
    }

    return sb.toString();
}
 
Example #19
Source File: LocalSnapshot.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param locals {@code non-null;} associated local variable state
 */
public LocalSnapshot(SourcePosition position, RegisterSpecSet locals) {
    super(position);

    if (locals == null) {
        throw new NullPointerException("locals == null");
    }

    this.locals = locals;
}
 
Example #20
Source File: PhiInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns human-readable string for listing dumps. This method
 * allows sub-classes to specify extra text.
 *
 * @param extra {@code null-ok;} the argument to print after the opcode
 * @return human-readable string for listing dumps
 */
protected final String toHumanWithInline(String extra) {
    StringBuilder sb = new StringBuilder(80);

    sb.append(SourcePosition.NO_INFO);
    sb.append(": phi");

    if (extra != null) {
        sb.append("(");
        sb.append(extra);
        sb.append(")");
    }

    RegisterSpec result = getResult();

    if (result == null) {
        sb.append(" .");
    } else {
        sb.append(" ");
        sb.append(result.toHuman());
    }

    sb.append(" <-");

    int sz = getSources().size();
    if (sz == 0) {
        sb.append(" .");
    } else {
        for (int i = 0; i < sz; i++) {
            sb.append(" ");
            sb.append(sources.get(i).toHuman()
                    + "[b="
                    + Hex.u2(operands.get(i).ropLabel)  + "]");
        }
    }

    return sb.toString();
}
 
Example #21
Source File: ConstCollector.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #22
Source File: OutputFinisher.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #add} and {@link #insert},
 * which updates the position and local info flags.
 *
 * @param insn {@code non-null;} an instruction that was just introduced
 */
private void updateInfo(DalvInsn insn) {
    if (! hasAnyPositionInfo) {
        SourcePosition pos = insn.getPosition();
        if (pos.getLine() >= 0) {
            hasAnyPositionInfo = true;
        }
    }

    if (! hasAnyLocalInfo) {
        if (hasLocalInfo(insn)) {
            hasAnyLocalInfo = true;
        }
    }
}
 
Example #23
Source File: MultiCstInsn.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
private MultiCstInsn(Dop opcode, SourcePosition position,
        RegisterSpecList registers, Constant[] constants, int[] index,
        int classIndex) {
    super(opcode, position, registers);
    this.constants = constants;
    this.index = index;
    this.classIndex = classIndex;
}
 
Example #24
Source File: LocalSnapshot.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param locals {@code non-null;} associated local variable state
 */
public LocalSnapshot(SourcePosition position, RegisterSpecSet locals) {
    super(position);

    if (locals == null) {
        throw new NullPointerException("locals == null");
    }

    this.locals = locals;
}
 
Example #25
Source File: MultiCstInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
private MultiCstInsn(Dop opcode, SourcePosition position,
        RegisterSpecList registers, Constant[] constants, int[] index,
        int classIndex) {
    super(opcode, position, registers);
    this.constants = constants;
    this.index = index;
    this.classIndex = classIndex;
}
 
Example #26
Source File: LocalStart.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param local {@code non-null;} register spec representing the local
 * variable introduced by this instance
 */
public LocalStart(SourcePosition position, RegisterSpec local) {
    super(position);

    if (local == null) {
        throw new NullPointerException("local == null");
    }

    this.local = local;
}
 
Example #27
Source File: SwitchData.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param user {@code non-null;} address representing the instruction that
 * uses this instance
 * @param cases {@code non-null;} sorted list of switch cases (keys)
 * @param targets {@code non-null;} corresponding list of code addresses; the
 * branch target for each case
 */
public SwitchData(SourcePosition position, CodeAddress user,
                  IntList cases, CodeAddress[] targets) {
    super(position, RegisterSpecList.EMPTY);

    if (user == null) {
        throw new NullPointerException("user == null");
    }

    if (cases == null) {
        throw new NullPointerException("cases == null");
    }

    if (targets == null) {
        throw new NullPointerException("targets == null");
    }

    int sz = cases.size();

    if (sz != targets.length) {
        throw new IllegalArgumentException("cases / targets mismatch");
    }

    if (sz > 65535) {
        throw new IllegalArgumentException("too many cases");
    }

    this.user = user;
    this.cases = cases;
    this.targets = targets;
    this.packed = shouldPack(cases);
}
 
Example #28
Source File: ConstCollector.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #29
Source File: PositionList.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param address {@code >= 0;} address of this entry
 * @param position {@code non-null;} corresponding source position information
 */
public Entry (int address, SourcePosition position) {
    if (address < 0) {
        throw new IllegalArgumentException("address < 0");
    }

    if (position == null) {
        throw new NullPointerException("position == null");
    }

    this.address = address;
    this.position = position;
}
 
Example #30
Source File: LocalStart.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is initially
 * unknown ({@code -1}).
 *
 * @param position {@code non-null;} source position
 * @param local {@code non-null;} register spec representing the local
 * variable introduced by this instance
 */
public LocalStart(SourcePosition position, RegisterSpec local) {
    super(position);

    if (local == null) {
        throw new NullPointerException("local == null");
    }

    this.local = local;
}