From a6d386a393a51abde63a803a39fc17eec65e35f1 Mon Sep 17 00:00:00 2001 From: Gillou68310 Date: Mon, 10 Feb 2025 09:20:22 +0100 Subject: [PATCH] Rework https://github.com/simonlindholm/asm-differ/commit/ea176989620cef521198071a1aa56c7ede86be5f using pre_process --- diff.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/diff.py b/diff.py index 2b8f13e..22597a8 100755 --- a/diff.py +++ b/diff.py @@ -2032,6 +2032,24 @@ def _normalize_adrp_differences(self, mnemonic: str, row: str) -> str: class AsmProcessorX86(AsmProcessor): + def pre_process( + self, mnemonic: str, args: str, next_row: Optional[str], comment: Optional[str] + ) -> Tuple[str, str]: + if ( + comment is not None + and ( + next_row is None + or re.search(self.config.arch.re_reloc, next_row) is None + ) + and mnemonic == "call" + ): + # if the mnemonic is call and the comment doesn't match + # <.text+0x...> replace the args with the contents of the comment + if re.search(r"<.+\+0x[0-9a-fA-F]+>", comment) is None: + args = comment[1:-1] + + return mnemonic, args + def process_reloc(self, row: str, prev: str) -> Tuple[str, Optional[str]]: if "WRTSEG" in row: # ignore WRTSEG (watcom) return prev, None @@ -2049,7 +2067,7 @@ def process_reloc(self, row: str, prev: str) -> Tuple[str, Optional[str]]: # Example call a2f # Example call *0 # Example jmp 64 - elif mnemonic in X86_BRANCH_INSTRUCTIONS: + elif mnemonic in X86_BRANCH_INSTRUCTIONS or 'call' in mnemonic: addr_imm = re.search(r"(^|(?<=\*)|(?<=\*\%cs\:))[0-9a-f]+", args) # Direct use of reloc @@ -2351,7 +2369,6 @@ class ArchSettings: } X86_BRANCH_INSTRUCTIONS = { - "call", "jmp", "ljmp", "ja", @@ -2930,14 +2947,6 @@ def process(dump: str, config: Config) -> List[Line]: break i += 1 - # Example call 0 - if arch.name is "x86" and mnemonic == "call" and comment and symbol is None: - addr_imm = re.search(r"(?:0x)?0+$", original) - if addr_imm is not None: - start, end = addr_imm.span() - symbol = comment[1 : len(comment) - 1] - original = original[:start] + symbol - is_text_relative_j = False if ( arch.name in MIPS_ARCH_NAMES