Skip to content

Commit

Permalink
Remove asm from tree (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored Jul 28, 2021
1 parent c96650b commit 258350b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ jobs:
Remove-Item '.\tools.zip'
Remove-Item -LiteralPath 'tools2' -Force -Recurse
- name: Re-generate assembly
run: python -m mkwutil.gen_asm
- uses: actions/cache@v2
with:
path: asm/dol
key: asm-dol

# https://stackoverflow.com/a/56389437
- name: Verify assembly still the same
run: |
$ChangedFiles = $(git status --porcelain | Measure-Object | Select-Object -expand Count)
if ($ChangedFiles -gt 0) {
git status --porcelain
throw "Found $ChangedFiles changed files! Did you run gen_asm?"
}
- uses: actions/cache@v2
with:
path: asm/rel
key: asm-rel

- name: Build mkw
shell: bash
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
/pack/dol.lcf
/pack/rel.lcf

# Auto-generated assembly
/asm/dol/
/asm/rel/

# Executables
*.exe
*.dll
Expand Down Expand Up @@ -58,9 +62,6 @@ tmp
*.map
out.html

# Compiler tools bundle
tools.7z

# Editors
.vscode/
*.bndb
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ The dead-stripping feature can be re-enabled by:
- [pack/dol_slices.csv](./pack/dol_slices.csv)
- [pack/rel_slices.csv](./pack/rel_slices.csv)
- Entries must be sorted in the spreadsheet (current limitation).
- After modifying slices, run `python3 -m mkwutil.gen_asm`.
- Add your new build target to `mkwutil/sources.py`.
- Run `build.py`.

Expand Down
11 changes: 10 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""


import argparse
from itertools import chain
import os
import os.path
Expand All @@ -26,9 +27,17 @@
from mkwutil.verify_main_dol import verify_dol
from mkwutil.verify_staticr_rel import verify_rel
from mkwutil.progress.percent_decompiled import percent_decompiled

from mkwutil.gen_asm import gen_asm
from mkwutil.project import load_dol_slices


parser = argparse.ArgumentParser(description="Build main.dol and StaticR.rel.")
parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM")
args = parser.parse_args()
# Start by running gen_asm.
gen_asm(args.regen_asm)


colorama.init()
print_mutex = Lock()

Expand Down
49 changes: 22 additions & 27 deletions mkwutil/gen_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,52 +454,47 @@ def __gen_asm(self, section: Section, _slice: Slice):
gen = AsmGenerator(data, _slice, SymbolsList(), asm_file)
gen.dump_section()

def main():
parser = argparse.ArgumentParser(
description="Generate ASM blobs and linker object lists."
)
parser.add_argument("--asm_dir", type=Path, default="./asm", help="Path to ASM dir")
parser.add_argument(
"--pack_dir", type=Path, default="./pack", help="Path to link instructions dir"
)
parser.add_argument(
"--binary_dir",
type=Path,
default="./artifacts/orig/pal",
help="Binary containing main.dol and StaticR.rel",
)
parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM")
args = parser.parse_args()
args.asm_dir.mkdir(exist_ok=True)

symbols = read_symbol_map(args.pack_dir / "symbols.txt")
def gen_asm(regen_asm=False):
asm_dir = Path("./asm")
pack_dir = Path("./pack")
binary_dir = Path("./artifacts/orig/pal")

dol = read_dol(args.binary_dir / "main.dol")
dol_slices = read_enabled_slices(dol, args.pack_dir / "dol_slices.csv")
asm_dir.mkdir(exist_ok=True)

symbols = read_symbol_map(pack_dir / "symbols.txt")

dol = read_dol(binary_dir / "main.dol")
dol_slices = read_enabled_slices(dol, pack_dir / "dol_slices.csv")

# Disassemble DOL sections.
dol_asm_dir = args.asm_dir / "dol"
dol_asm_dir = asm_dir / "dol"
dol_asm_dir.mkdir(exist_ok=True)
dol_gen = DOLSrcGenerator(
dol_slices, dol, symbols, dol_asm_dir, args.pack_dir, args.regen_asm
dol_slices, dol, symbols, dol_asm_dir, pack_dir, regen_asm
)
dol_gen.run()

rel = read_rel(args.binary_dir / "StaticR.rel")
rel = read_rel(binary_dir / "StaticR.rel")
# Dump StaticR.rel segments.
rel_bin_dir = args.binary_dir / "rel"
rel_bin_dir = binary_dir / "rel"
dump_staticr(rel, rel_bin_dir)
# Map out slices in REL.
rel_slices = load_rel_slices(sections=REL_SECTIONS)
rel_slices.filter(SliceTable.ONLY_ENABLED)
# Disassemble REL sections.
rel_asm_dir = args.asm_dir / "rel"
rel_asm_dir = asm_dir / "rel"
rel_asm_dir.mkdir(exist_ok=True)
rel_gen = RELSrcGenerator(
rel_slices, rel, rel_asm_dir, rel_bin_dir, args.pack_dir, args.regen_asm
rel_slices, rel, rel_asm_dir, rel_bin_dir, pack_dir, regen_asm
)
rel_gen.run()


if __name__ == "__main__":
main()
parser = argparse.ArgumentParser(
description="Generate ASM blobs and linker object lists."
)
parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM")
args = parser.parse_args()
gen_asm(args.regen_asm)

0 comments on commit 258350b

Please sign in to comment.