Skip to content

Commit

Permalink
subrepo and update asm-differ (zeldaret#1664)
Browse files Browse the repository at this point in the history
* git subrepo clone [email protected]:simonlindholm/asm-differ.git tools/asm-differ

subrepo:
  subdir:   "tools/asm-differ"
  merged:   "11eee5916"
upstream:
  origin:   "[email protected]:simonlindholm/asm-differ.git"
  branch:   "main"
  commit:   "11eee5916"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "110b9eb"

* ln -s ./tools/asm-differ/diff.py diff.py
  • Loading branch information
Dragorn421 authored Jan 30, 2024
1 parent 18b7030 commit 17f0878
Show file tree
Hide file tree
Showing 17 changed files with 4,541 additions and 2,728 deletions.
2,728 changes: 0 additions & 2,728 deletions diff.py

This file was deleted.

1 change: 1 addition & 0 deletions diff.py
15 changes: 15 additions & 0 deletions tools/asm-differ/.github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: black

on:
pull_request:
push:

permissions: read-all

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python3 -m pip install --user colorama watchdog levenshtein cxxfilt black==23.12.1
- run: python3 -m black .
20 changes: 20 additions & 0 deletions tools/asm-differ/.github/workflows/check-poetry-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: flake check

on:
pull_request:
push:

permissions: read-all

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Install `nix` which is just a dead-simple way to get a stable `poetry`
# in scope.
- uses: cachix/install-nix-action@v20
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
# Check that poetry.lock is in sync with pyproject.toml
- run: nix run github:NixOS/nixpkgs/22.11#poetry -- lock --check
15 changes: 15 additions & 0 deletions tools/asm-differ/.github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: unit tests

on:
pull_request:
push:

permissions: read-all

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: python3 -m pip install --user colorama watchdog levenshtein cxxfilt
- run: python3 test.py
3 changes: 3 additions & 0 deletions tools/asm-differ/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.mypy_cache/
__pycache__/
.vscode/
12 changes: 12 additions & 0 deletions tools/asm-differ/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
;
[subrepo]
remote = [email protected]:simonlindholm/asm-differ.git
branch = main
commit = 11eee5916e4c7ee0cf1100c15034c3644de802ca
parent = 6d09437c2162a156a843f3f10b1f864437eee6ed
method = merge
cmdver = 0.4.6
5 changes: 5 additions & 0 deletions tools/asm-differ/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
hooks:
- id: black
24 changes: 24 additions & 0 deletions tools/asm-differ/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
56 changes: 56 additions & 0 deletions tools/asm-differ/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# asm-differ

Nice differ for assembly code. Currently supports MIPS, PPC, AArch64, ARM32, SH2, SH4, and m68k; should be easy to hack to support other instruction sets.

![](screenshot.png)

## Dependencies

- Python >= 3.6
- `python3 -m pip install --user colorama watchdog levenshtein cxxfilt` (also `dataclasses` if on 3.6)

## Usage

Create a file `diff_settings.py` in some directory (see the one in this repo for an example). Then from that directory, run

```bash
/path/to/diff.py [flags] (function|rom addr)
```

Recommended flags are `-mwo` (automatically run `make` on source file changes, and include symbols in diff). See `--help` for more details.

### Tab completion

[argcomplete](https://kislyuk.github.io/argcomplete/) can be optionally installed (with `python3 -m pip install argcomplete`) to enable tab completion in a bash shell, completing options and symbol names using the linker map. It also requires a bit more setup:

If invoking the script **exactly** as `./diff.py`, the following should be added to the `.bashrc` according to argcomplete's instructions:

```bash
eval "$(register-python-argcomplete ./diff.py)"
```

If that doesn't work, run `register-python-argcomplete ./diff.py` in your terminal and copy the output to `.bashrc`.

If setup correctly (don't forget to restart the shell), `complete | grep ./diff.py` should output:

```bash
complete -o bashdefault -o default -o nospace -F _python_argcomplete ./diff.py
```

Note for developers or for general troubleshooting: run `export _ARC_DEBUG=` to enable debug output during tab-completion, it may show otherwise silenced errors. Use `unset _ARC_DEBUG` or restart the terminal to disable.

### Contributing

Contributions are very welcome! Some notes on workflow:

`black` is used for code formatting. You can either run `black diff.py` manually, or set up a pre-commit hook:
```bash
pip install pre-commit black
pre-commit install
```

Type annotations are used for all Python code. `mypy` should pass without any errors.

PRs that skip the above are still welcome, however.

The targeted Python version is 3.6. There are currently no tests.
67 changes: 67 additions & 0 deletions tools/asm-differ/diff-stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
table.diff {
border: none;
font-family: Monospace;
white-space: pre;
}
tr.data-ref {
background-color: gray;
}
.immediate {
color: lightblue;
}
.stack {
color: yellow;
}
.register {
color: yellow;
}
.delay-slot {
font-weight: bold;
color: gray;
}
.diff-change {
color: lightblue;
}
.diff-add {
color: green;
}
.diff-remove {
color: red;
}
.source-filename {
font-weight: bold;
}
.source-function {
font-weight: bold;
text-decoration: underline;
}
.source-other {
font-style: italic;
}
.rotation-0 {
color: magenta;
}
.rotation-1 {
color: cyan;
}
.rotation-2 {
color: green;
}
.rotation-3 {
color: red;
}
.rotation-4 {
color: yellow;
}
.rotation-5 {
color: pink;
}
.rotation-6 {
color: blue;
}
.rotation-7 {
color: lime;
}
.rotation-8 {
color: gray;
}
Loading

0 comments on commit 17f0878

Please sign in to comment.