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 dbebf75 commit 7043db7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 5 additions & 7 deletions m2c/asm_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,11 @@ def process_label(label: str, *, kind: LabelKind) -> None:
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
if len(args) == 2:
kind = LabelKind.GLOBAL
if args[1] == "local":
kind = LabelKind.LOCAL
process_label(args[0], kind=kind)

elif ifdef_level == 0:
if directive == "jlabel":
Expand Down
10 changes: 4 additions & 6 deletions m2c/flow_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
class ArchFlowGraph(ArchAsm):
asm_patterns: List[AsmPattern] = []

def simplify_ir(self, flow_graph: FlowGraph) -> None:
...
def simplify_ir(self, flow_graph: FlowGraph) -> None: ...


class Reference(abc.ABC):
Expand Down Expand Up @@ -651,8 +650,7 @@ def name(self) -> str:
return str(self.block.index)

@abc.abstractmethod
def children(self) -> List[Node]:
...
def children(self) -> List[Node]: ...

def __repr__(self) -> str:
return f"<{self.__class__.__name__}: {self.name()}>"
Expand Down Expand Up @@ -862,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 @@ -879,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 7043db7

Please sign in to comment.