Пример #1
0
  @Override
  public void acceptInstruction(GenericInstruction instruction) {
    // Initial case
    if (lastAddress == -1) {
      currentInstructions.add(instruction);
      lastAddress = instruction.getAddress();
      return;
    }

    // Check if instruction is a branch
    // if(jumpFilter.accept(instruction)) {
    if (isShortBackwardBranch(instruction.getAddress(), lastAddress)) {
      completeBasicBlock();
    }

    // Add instruction to current block of instructions
    currentInstructions.add(instruction);
    lastAddress = instruction.getAddress();
  }
Пример #2
0
  private void completeBasicBlock() {
    if (currentInstructions.isEmpty()) {
      return;
    }

    // According to the paper, the Daprof block can be identified by
    // the address of the first instruction and by the number of instructions
    // the block has, but I think there can be ambiguities.
    int originalId = BitUtils.superFastHash(currentInstructions.get(0).getAddress(), 32);
    originalId = BitUtils.superFastHash(currentInstructions.size(), originalId);

    // As an alternative, I'm calculating an hash with the values of
    // the addresses of all instructions in the block.
    int completeId = 32;
    for (GenericInstruction instruction : currentInstructions) {
      completeId = BitUtils.superFastHash(instruction.getAddress(), completeId);
    }

    int repetitions = 1;
    int id = 0;
    if (useDaprofId) {
      id = originalId;
    } else {
      id = completeId;
    }

    // Build Instruction Block
    InstructionBlock iBlock =
        new InstructionBlock(
            currentInstructions, repetitions, id, repetitions * currentInstructions.size());

    noticeListeners(iBlock);

    // Clean current instructions
    currentInstructions = new ArrayList<GenericInstruction>();
  }