Skip to content

Commit

Permalink
refactor(instruction/prev): return first matching
Browse files Browse the repository at this point in the history
* Idea is that the diasassembler is more likely to find (bad) small instructions instead of large ones
  • Loading branch information
Curve committed May 20, 2024
1 parent 5833687 commit c35ea64
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ namespace lime
return disasm::immediates(m_impl->address);
}

std::optional<instruction> instruction::next() const
{
return *this + size();
}

std::optional<instruction> instruction::prev() const
{
const auto start = m_impl->address - max_instruction_size;
std::optional<instruction> last;

for (auto current = start; current < m_impl->address; current++)
{
Expand All @@ -84,16 +88,10 @@ namespace lime
continue;
}

last.emplace(std::move(instruction.value()));
break;
return instruction;
}

return last;
}

std::optional<instruction> instruction::next() const
{
return *this + size();
return std::nullopt;
}

std::optional<instruction> instruction::next(std::size_t mnemonic) const
Expand Down

0 comments on commit c35ea64

Please sign in to comment.