Updates
This commit is contained in:
24
h8536/cli.py
24
h8536/cli.py
@@ -3,10 +3,11 @@ from __future__ import annotations
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from .analysis import collect_labels, linear_sweep, trace
|
||||
from .analysis import build_call_graph, collect_labels, linear_sweep, trace
|
||||
from .data_analysis import analyze_unreached_data
|
||||
from .decoder import H8536Decoder
|
||||
from .formatting import parse_int
|
||||
from .render import format_listing, write_json
|
||||
from .render import format_callgraph_dot, format_listing, write_json
|
||||
from .rom import Rom
|
||||
from .vectors import read_dtc_vectors_max, read_dtc_vectors_min, read_vectors_max, read_vectors_min
|
||||
|
||||
@@ -30,6 +31,7 @@ def main() -> int:
|
||||
parser.add_argument("--entry", type=parse_int, action="append", default=[], help="extra entry point to trace")
|
||||
parser.add_argument("--br", type=parse_int, default=None, help="optional BR value for @aa:8 short absolute operands")
|
||||
parser.add_argument("--linear", action="store_true", help="linear-sweep the selected range instead of tracing from vectors")
|
||||
parser.add_argument("--callgraph-dot", type=Path, default=None, help="optional Graphviz DOT call graph output")
|
||||
args = parser.parse_args()
|
||||
|
||||
data = args.rom.read_bytes()
|
||||
@@ -58,6 +60,8 @@ def main() -> int:
|
||||
else:
|
||||
instructions = trace(decoder, starts, args.start, end)
|
||||
labels.update(collect_labels(instructions.values(), vectors))
|
||||
data_candidates = analyze_unreached_data(rom, instructions, args.start, end)
|
||||
call_graph = build_call_graph(instructions, vectors, labels)
|
||||
|
||||
args.out.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.out.write_text(
|
||||
@@ -70,15 +74,29 @@ def main() -> int:
|
||||
args.mode,
|
||||
traced=not args.linear,
|
||||
dtc_vectors=dtc_vectors,
|
||||
data_candidates=data_candidates,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
if args.json:
|
||||
args.json.parent.mkdir(parents=True, exist_ok=True)
|
||||
write_json(args.json, instructions, vectors, labels, dtc_vectors=dtc_vectors)
|
||||
write_json(
|
||||
args.json,
|
||||
instructions,
|
||||
vectors,
|
||||
labels,
|
||||
dtc_vectors=dtc_vectors,
|
||||
data_candidates=data_candidates,
|
||||
call_graph=call_graph,
|
||||
)
|
||||
if args.callgraph_dot:
|
||||
args.callgraph_dot.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.callgraph_dot.write_text(format_callgraph_dot(call_graph), encoding="utf-8")
|
||||
|
||||
invalid = sum(1 for ins in instructions.values() if not ins.valid)
|
||||
print(f"wrote {args.out} ({len(instructions)} items, {invalid} invalid/data bytes)")
|
||||
if args.json:
|
||||
print(f"wrote {args.json}")
|
||||
if args.callgraph_dot:
|
||||
print(f"wrote {args.callgraph_dot}")
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user