mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-27 18:21:15 +00:00
Basic check on instruction relocation
This commit is contained in:
parent
a9a137ff66
commit
719d1585fa
@ -124,6 +124,10 @@ def effective_match_possible(orig_asm: List[str], recomp_asm: List[str]) -> bool
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def find_regs_used(inst: str) -> List[str]:
|
||||||
|
return REG_FIND.findall(inst)
|
||||||
|
|
||||||
|
|
||||||
def find_regs_changed(a: str, b: str) -> List[Tuple[str, str]]:
|
def find_regs_changed(a: str, b: str) -> List[Tuple[str, str]]:
|
||||||
"""For instructions a, b, return the pairs of registers that were used.
|
"""For instructions a, b, return the pairs of registers that were used.
|
||||||
This is not a very precise way to compare the instructions, so it depends
|
This is not a very precise way to compare the instructions, so it depends
|
||||||
@ -192,14 +196,22 @@ def relocate_instructions(
|
|||||||
|
|
||||||
for j in inserts:
|
for j in inserts:
|
||||||
line = recomp_asm[j]
|
line = recomp_asm[j]
|
||||||
|
recomp_regs_used = set(find_regs_used(line))
|
||||||
for i in deletes:
|
for i in deletes:
|
||||||
# Check for exact match.
|
# Check for exact match.
|
||||||
# TODO: This will grab the first instruction that matches.
|
# TODO: This will grab the first instruction that matches.
|
||||||
# We should probably use the nearest index instead, if it matters
|
# We should probably use the nearest index instead, if it matters
|
||||||
if orig_asm[i] == line:
|
if orig_asm[i] == line:
|
||||||
relocated.add(j)
|
# To account for a move in either direction
|
||||||
deletes.remove(i)
|
reloc_start = min(i, j)
|
||||||
break
|
reloc_end = max(i, j)
|
||||||
|
if all(
|
||||||
|
recomp_regs_used.isdisjoint(set(find_regs_used(orig_asm[k])))
|
||||||
|
for k in range(reloc_start + 1, reloc_end)
|
||||||
|
):
|
||||||
|
relocated.add(j)
|
||||||
|
deletes.remove(i)
|
||||||
|
break
|
||||||
|
|
||||||
return relocated
|
return relocated
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user