Skip to content

Commit

Permalink
Added compatibility for decomp-toolkit macros (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalatoni13 authored May 29, 2024
1 parent 6970f12 commit 81b1748
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 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 All @@ -528,8 +535,14 @@ def process_label(label: str, *, kind: LabelKind) -> None:
for w in args:
fval = try_parse(lambda: float(w))
asm_file.new_data_bytes(struct.pack(">d", fval))
elif directive in (".asci", ".asciz", ".ascii", ".asciiz"):
z = directive.endswith("z")
elif directive in (
".asci",
".asciz",
".ascii",
".asciiz",
".string",
):
z = directive.endswith("z") or directive == ".string"
asm_file.new_data_bytes(
parse_ascii_directive(line, z), is_string=True
)
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 81b1748

Please sign in to comment.