Skip to content

Commit

Permalink
Added compatibility for decomp-toolkit macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalatoni13 committed May 28, 2024
1 parent 2e7ec29 commit 26fcb86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions m2c/asm_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ def re_comment_replacer(match: Match[str]) -> str:
re_whitespace_or_string = re.compile(r'\s+|"(?:\\.|[^\\"])*"')
re_local_glabel = re.compile("L(_.*_)?[0-9A-F]{8}")
re_local_label = re.compile("loc_|locret_|def_|lbl_|LAB_|jump_")
re_label = re.compile(r'(?:([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)"):')
re_label = re.compile(
r'(?:(?:\.obj )?([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)")[:,]'
)

T = TypeVar("T")

Expand Down Expand Up @@ -528,7 +530,13 @@ 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"):
elif directive in (
".asci",
".asciz",
".ascii",
".asciiz",
"string",
):
z = directive.endswith("z")
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 @@ -862,7 +862,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 @@ -879,7 +879,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 26fcb86

Please sign in to comment.