Pseudocode decompialtion improvements and docs
This commit is contained in:
parent
f869a181a3
commit
589bfc31ef
1898 changed files with 60634 additions and 6597 deletions
|
|
@ -12,7 +12,13 @@ if str(REPO_ROOT) not in sys.path:
|
|||
sys.path.insert(0, str(REPO_ROOT))
|
||||
|
||||
|
||||
from tools.poc_crusader_usecode_parser import EXTRACTED_ROOT, parse_body_ir, render_pseudocode
|
||||
from tools.poc_crusader_usecode_parser import (
|
||||
EXTRACTED_ROOT,
|
||||
default_shape_catalog_path,
|
||||
load_shape_catalog,
|
||||
parse_body_ir,
|
||||
render_pseudocode,
|
||||
)
|
||||
|
||||
|
||||
def load_rows(class_event_index: Path) -> list[dict[str, str]]:
|
||||
|
|
@ -42,6 +48,14 @@ def safe_name(value: str) -> str:
|
|||
return cleaned.strip("._") or "unknown"
|
||||
|
||||
|
||||
def describe_row(row: dict[str, str]) -> str:
|
||||
class_name = row.get("class_name_hint") or "unknown"
|
||||
slot = parse_int(row.get("slot", "0"))
|
||||
event_name = row.get("event_name_hint") or f"slot_{slot:02X}"
|
||||
entry_index = row.get("entry_index", "?")
|
||||
return f"entry {entry_index} {class_name}::${event_name}".replace("::$", "::") + f" (slot 0x{slot:02X})"
|
||||
|
||||
|
||||
def output_path_for_row(output_root: Path, row: dict[str, str]) -> Path:
|
||||
class_name = row["class_name_hint"]
|
||||
slot = parse_int(row["slot"])
|
||||
|
|
@ -119,35 +133,57 @@ def main() -> None:
|
|||
default="auto",
|
||||
help="Crusader intrinsic numbering to apply during export (default: auto, fallback regret)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shape-csv",
|
||||
help=(
|
||||
"Shape catalog CSV to apply to pseudocode output "
|
||||
"(default: Remorse uses <extracted-root>/usecode_shape_catalog_remorse.csv; "
|
||||
"Regret uses <extracted-root>/usecode_shape_catalog_regret.csv)"
|
||||
),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
extracted_root = Path(args.extracted_root)
|
||||
class_event_index = extracted_root / "class_event_index.tsv"
|
||||
class_layout_index = extracted_root / "class_layout_index.tsv"
|
||||
output_root = Path(args.output_dir) if args.output_dir else extracted_root / "pseudocode"
|
||||
shape_csv = Path(args.shape_csv) if args.shape_csv else default_shape_catalog_path(extracted_root, args.variant)
|
||||
shape_catalog = load_shape_catalog(shape_csv)
|
||||
output_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
rows = load_rows(class_event_index)
|
||||
work_rows = [row for row in rows if row.get("derived_body_start") and row.get("derived_body_end")]
|
||||
layout_by_entry = load_layout_by_entry(class_layout_index)
|
||||
index_rows: list[dict[str, str]] = []
|
||||
exported = 0
|
||||
|
||||
for row in rows:
|
||||
if not row.get("derived_body_start") or not row.get("derived_body_end"):
|
||||
continue
|
||||
print(
|
||||
f"Exporting pseudocode from {extracted_root} to {output_root} using variant={args.variant} and shape_csv={shape_csv}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
for position, row in enumerate(work_rows, start=1):
|
||||
entry_index = parse_int(row["entry_index"])
|
||||
layout_row = layout_by_entry.get(entry_index)
|
||||
if layout_row is None:
|
||||
print(
|
||||
f"[{position}/{len(work_rows)}] Skipping {describe_row(row)} because no layout row was found",
|
||||
flush=True,
|
||||
)
|
||||
continue
|
||||
|
||||
label = describe_row(row)
|
||||
print(f"[{position}/{len(work_rows)}] Decoding {label}", flush=True)
|
||||
ir = parse_body_ir(row, layout_row, None if args.variant == "auto" else args.variant, extracted_root)
|
||||
pseudocode = render_pseudocode(ir)
|
||||
print(f"[{position}/{len(work_rows)}] Rendering {label}", flush=True)
|
||||
pseudocode = render_pseudocode(ir, shape_catalog=shape_catalog)
|
||||
|
||||
path = output_path_for_row(output_root, row)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(pseudocode, encoding="utf-8")
|
||||
index_rows.append(build_index_row(output_root, row, path, ir))
|
||||
exported += 1
|
||||
print(f"[{position}/{len(work_rows)}] Wrote {path.relative_to(output_root.parent).as_posix()}", flush=True)
|
||||
|
||||
write_index(output_root, index_rows)
|
||||
write_readme(output_root, exported)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue