Exemple #1
0
  /**
   * Extracts and returns the source position information out of an instruction list.
   *
   * @param insns {@code non-null;} instructions to convert
   * @param howMuch how much information should be included; one of the static constants defined by
   *     this class
   * @return {@code non-null;} the positions list
   */
  public static PositionList make(DalvInsnList insns, int howMuch) {
    switch (howMuch) {
      case NONE:
        {
          return EMPTY;
        }
      case LINES:
      case IMPORTANT:
        {
          // Valid.
          break;
        }
      default:
        {
          throw new IllegalArgumentException("bogus howMuch");
        }
    }

    SourcePosition noInfo = SourcePosition.NO_INFO;
    SourcePosition cur = noInfo;
    int sz = insns.size();
    PositionList.Entry[] arr = new PositionList.Entry[sz];
    boolean lastWasTarget = false;
    int at = 0;

    for (int i = 0; i < sz; i++) {
      DalvInsn insn = insns.get(i);

      if (insn instanceof CodeAddress) {
        lastWasTarget = true;
        ;
        continue;
      }

      SourcePosition pos = insn.getPosition();

      if (pos.equals(noInfo) || pos.sameLine(cur)) {
        continue;
      }

      if ((howMuch == IMPORTANT) && !lastWasTarget) {
        continue;
      }

      cur = pos;
      arr[at] = new PositionList.Entry(insn.getAddress(), pos);
      at++;

      lastWasTarget = false;
    }

    PositionList result = new PositionList(at);
    for (int i = 0; i < at; i++) {
      result.set(i, arr[i]);
    }

    result.setImmutable();
    return result;
  }
Exemple #2
0
  /**
   * Constructs and returns an immutable instance whose elements are identical to the ones in the
   * given list, in the same order.
   *
   * @param list {@code non-null;} the list to use for elements
   * @param regCount count, in register-units, of the number of registers this code block requires.
   * @return {@code non-null;} an appropriately-constructed instance of this class
   */
  public static DalvInsnList makeImmutable(ArrayList<DalvInsn> list, int regCount) {
    int size = list.size();
    DalvInsnList result = new DalvInsnList(size, regCount);

    for (int i = 0; i < size; i++) {
      result.set(i, list.get(i));
    }

    result.setImmutable();
    return result;
  }