From 38db51152d9ddf967aa2c65a8565d1692c5cf818 Mon Sep 17 00:00:00 2001 From: kabiskac Date: Tue, 28 May 2024 20:36:42 +0200 Subject: [PATCH] Added an alternative jump table prefix and made the label format detection cleaner --- m2c/asm_file.py | 15 +++++++-------- m2c/flow_graph.py | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/m2c/asm_file.py b/m2c/asm_file.py index c03aa58b..27bdd268 100644 --- a/m2c/asm_file.py +++ b/m2c/asm_file.py @@ -512,6 +512,13 @@ def process_label(label: str, *, kind: LabelKind) -> None: # ".rel name, label" expands to ".4byte name + (label - name)" assert len(args) == 2 emit_word(args[1]) + elif directive == ".obj": + # dtk disassembler label format + assert len(args) == 2 + kind = ( + LabelKind.LOCAL if args[1] == "local" else LabelKind.GLOBAL + ) + process_label(args[0], kind=kind) elif directive in (".short", ".half", ".2byte"): for w in args: ival = try_parse(lambda: parse_int(w)) & 0xFFFF @@ -554,14 +561,6 @@ def process_label(label: str, *, kind: LabelKind) -> None: data = parse_incbin(args, options, warnings) if data is not None: asm_file.new_data_bytes(data) - elif directive == ".obj": # decomp-toolkit label format - parts = line.split() - if len(parts) >= 3: - try: - kind = LabelKind[parts[2].upper()] - process_label(parts[1].removesuffix(","), kind=kind) - except KeyError: - pass elif ifdef_level == 0: if directive == "jlabel": diff --git a/m2c/flow_graph.py b/m2c/flow_graph.py index baae8f63..53fbbdb7 100644 --- a/m2c/flow_graph.py +++ b/m2c/flow_graph.py @@ -860,7 +860,7 @@ def find_block_by_label(label: str) -> Optional[Block]: and isinstance(arg.argument, AsmGlobalSymbol) and any( arg.argument.symbol_name.startswith(prefix) - for prefix in ("jtbl", "jpt_", "lbl_") + for prefix in ("jtbl", "jpt_", "lbl_", "jumptable_") ) ): jtbl_names.add(arg.argument.symbol_name) @@ -877,7 +877,7 @@ def find_block_by_label(label: str) -> Optional[Block]: raise DecompFailure( f"Unable to determine jump table for {jump.mnemonic} instruction {jump.meta.loc_str()}.\n\n" "There must be a read of a variable before the instruction\n" - 'which has a name starting with with "jtbl"/"jpt_"/"lbl_".' + 'which has a name starting with with "jtbl"/"jpt_"/"lbl_"/"jumptable_".' ) jtbl_name = list(jtbl_names)[0]