mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-27 18:21:15 +00:00
More targeted check for relocation
This commit is contained in:
parent
719d1585fa
commit
6b0aab2323
@ -174,6 +174,19 @@ def bad_register_swaps(
|
|||||||
return rejects
|
return rejects
|
||||||
|
|
||||||
|
|
||||||
|
# Instructions that result in a change to the first operand
|
||||||
|
MODIFIER_INSTRUCTIONS = ("adc", "add", "lea", "mov", "neg", "sbb", "sub", "pop", "xor")
|
||||||
|
|
||||||
|
|
||||||
|
def instruction_alters_regs(inst: str, regs: Set[str]) -> bool:
|
||||||
|
(mnemonic, _, op_str) = inst.partition(" ")
|
||||||
|
(first_operand, _, __) = op_str.partition(", ")
|
||||||
|
|
||||||
|
return (mnemonic in MODIFIER_INSTRUCTIONS and first_operand in regs) or (
|
||||||
|
mnemonic == "call" and "eax" in regs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def relocate_instructions(
|
def relocate_instructions(
|
||||||
codes: List[DiffOpcode], orig_asm: List[str], recomp_asm: List[str]
|
codes: List[DiffOpcode], orig_asm: List[str], recomp_asm: List[str]
|
||||||
) -> Set[int]:
|
) -> Set[int]:
|
||||||
@ -205,9 +218,9 @@ def relocate_instructions(
|
|||||||
# To account for a move in either direction
|
# To account for a move in either direction
|
||||||
reloc_start = min(i, j)
|
reloc_start = min(i, j)
|
||||||
reloc_end = max(i, j)
|
reloc_end = max(i, j)
|
||||||
if all(
|
if not any(
|
||||||
recomp_regs_used.isdisjoint(set(find_regs_used(orig_asm[k])))
|
instruction_alters_regs(orig_asm[k], recomp_regs_used)
|
||||||
for k in range(reloc_start + 1, reloc_end)
|
for k in range(reloc_start, reloc_end)
|
||||||
):
|
):
|
||||||
relocated.add(j)
|
relocated.add(j)
|
||||||
deletes.remove(i)
|
deletes.remove(i)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user