Skip to content

Commit

Permalink
Added an alternative jump table prefix and made the label format dete…
Browse files Browse the repository at this point in the history
…ction cleaner
  • Loading branch information
dbalatoni13 committed May 28, 2024
1 parent 9781ee7 commit 38db511
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions m2c/asm_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions m2c/flow_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down

0 comments on commit 38db511

Please sign in to comment.