Skip to content

Commit

Permalink
Manage m2c and asm-differ via pip (doldecomp#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbanya authored Jan 28, 2024
1 parent 411e2f1 commit 011c1bb
Show file tree
Hide file tree
Showing 813 changed files with 46 additions and 51,519 deletions.
9 changes: 3 additions & 6 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
-e file:tools/asm-differ#egg=asm-differ
argcomplete
beautifulsoup4
black
colorama
coverage
cxxfilt
git+https://github.com/matt-kempster/m2c.git
GitPython
graphviz
isort
humanfriendly
pycparser
isort
pcpp
pyelftools
Pygments
pyperclip
python_Levenshtein
watchdog
34 changes: 21 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile
# pip-compile --strip-extras
#
-e file:tools/asm-differ#egg=asm-differ
# via -r requirements.in
ansiwrap==0.8.4
# via asm-differ
argcomplete==3.2.2
# via -r requirements.in
beautifulsoup4==4.12.3
# via -r requirements.in
black==24.1.0
black==24.1.1
# via -r requirements.in
click==8.1.7
# via black
colorama==0.4.6
# via -r requirements.in
# via
# -r requirements.in
# asm-differ
coverage==7.4.1
# via -r requirements.in
cxxfilt==0.3.0
# via -r requirements.in
# via asm-differ
gitdb==4.0.11
# via gitpython
gitpython==3.1.41
# via -r requirements.in
graphviz==0.20.1
# via -r requirements.in
# via m2c
humanfriendly==10.0
# via -r requirements.in
isort==5.13.2
# via -r requirements.in
levenshtein==0.23.0
# via python-levenshtein
levenshtein==0.20.9
# via asm-differ
m2c @ git+https://github.com/matt-kempster/m2c.git
# via -r requirements.in
mypy-extensions==1.0.0
# via black
packaging==23.2
Expand All @@ -41,20 +49,20 @@ pcpp==1.30
platformdirs==4.1.0
# via black
pycparser==2.21
# via -r requirements.in
# via m2c
pyelftools==0.30
# via -r requirements.in
pygments==2.17.2
# via -r requirements.in
pyperclip==1.8.2
# via -r requirements.in
python-levenshtein==0.23.0
# via -r requirements.in
rapidfuzz==3.6.1
rapidfuzz==2.15.2
# via levenshtein
smmap==5.0.1
# via gitdb
soupsieve==2.5
# via beautifulsoup4
watchdog==3.0.0
# via -r requirements.in
textwrap3==0.9.2
# via ansiwrap
watchdog==2.3.1
# via asm-differ
36 changes: 22 additions & 14 deletions tools/decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import SymbolTableSection

root = Path(__file__).parent.parent
root = Path(__file__).parents[1]
dtk_root = root / "build/GALE01"
obj_root = dtk_root / "obj"
asm_root = dtk_root / "asm"
m2c_script = root / "tools/m2c/m2c.py"
ctx_file = root / "build/ctx.c"
m2ctx_script = root / "tools/m2ctx/m2ctx.py"

Expand Down Expand Up @@ -60,7 +59,7 @@ def run_cmd(cmd: list[str]) -> str:
return result.stdout.decode()


def gen_ctx():
def gen_ctx() -> None:
run_cmd(
[
"python",
Expand All @@ -71,7 +70,7 @@ def gen_ctx():
)


def main():
def main() -> None:
parser = argparse.ArgumentParser(description="Decomp a function using m2c")
parser.add_argument(
"function",
Expand All @@ -93,19 +92,19 @@ def main():
"--no-copy",
action="store_false",
dest="copy",
help=f"do not copy the output to the clipboard",
help="do not copy the output to the clipboard",
)
parser.add_argument(
"--no-print",
action="store_false",
dest="print",
help=f"do not print the output",
help="do not print the output",
)
parser.add_argument(
"--colorize",
action="store_true",
dest="color",
help=f"colorize the output (requires pygments)",
help="colorize the output (requires pygments)",
)

args = parser.parse_args()
Expand All @@ -115,7 +114,8 @@ def main():

m2c_cmd: list[str] = [
"python",
resolve_path(m2c_script),
"-m",
"m2c.main",
*args.m2c_args,
"--target",
"ppc-mwcc-c",
Expand All @@ -131,21 +131,29 @@ def main():

output = run_cmd(m2c_cmd)
if args.copy:
import pyperclip
try:
import pyperclip

pyperclip.copy(output)
except ModuleNotFoundError:
print("Failed to import pyperclip; could not copy", file=stderr)

pyperclip.copy(output)
if args.print:
if args.color:
try:
import colorama

colorama.just_fix_windows_console()
except ModuleNotFoundError:
pass
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import CLexer
try:
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import CLexer

output = highlight(output, CLexer(), TerminalFormatter())
output = highlight(output, CLexer(), TerminalFormatter())
except ModuleNotFoundError:
print("Failed to import pygments; could not colorize", file=stderr)
print(output, file=sys.stdout)
else:
print(f"Could not find {args.function}", file=stderr)
Expand Down
34 changes: 0 additions & 34 deletions tools/m2c/.github/workflows/python-app.yml

This file was deleted.

89 changes: 0 additions & 89 deletions tools/m2c/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions tools/m2c/.pre-commit-config.yaml

This file was deleted.

Loading

0 comments on commit 011c1bb

Please sign in to comment.