Usecode pseudocode

This commit is contained in:
MaddoScientisto 2026-03-26 00:37:17 +01:00
commit c12bb39437
1362 changed files with 71072 additions and 38056 deletions

View file

@ -12,19 +12,16 @@ if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
from tools.poc_crusader_usecode_parser import CLASS_LAYOUT_INDEX, EXTRACTED_ROOT, parse_body_ir, render_pseudocode
from tools.poc_crusader_usecode_parser import EXTRACTED_ROOT, parse_body_ir, render_pseudocode
CLASS_EVENT_INDEX = EXTRACTED_ROOT / "class_event_index.tsv"
def load_rows() -> list[dict[str, str]]:
with CLASS_EVENT_INDEX.open("r", encoding="utf-8", newline="") as handle:
def load_rows(class_event_index: Path) -> list[dict[str, str]]:
with class_event_index.open("r", encoding="utf-8", newline="") as handle:
return list(csv.DictReader(handle, delimiter="\t"))
def load_layout_by_entry() -> dict[int, dict[str, str]]:
with CLASS_LAYOUT_INDEX.open("r", encoding="utf-8", newline="") as handle:
def load_layout_by_entry(class_layout_index: Path) -> dict[int, dict[str, str]]:
with class_layout_index.open("r", encoding="utf-8", newline="") as handle:
rows = list(csv.DictReader(handle, delimiter="\t"))
layout_by_entry: dict[int, dict[str, str]] = {}
for row in rows:
@ -107,18 +104,31 @@ def write_readme(output_root: Path, export_count: int) -> None:
def main() -> None:
parser = argparse.ArgumentParser(description="Export pseudocode for all decoded Crusader USECODE bodies")
parser.add_argument(
"--extracted-root",
default=str(EXTRACTED_ROOT),
help="Extracted USECODE root containing class_event_index.tsv and chunks/",
)
parser.add_argument(
"--output-dir",
default=str(EXTRACTED_ROOT / "pseudocode"),
help="Output directory for pseudocode files (default: USECODE/EUSECODE_extracted/pseudocode)",
help="Output directory for pseudocode files (default: <extracted-root>/pseudocode)",
)
parser.add_argument(
"--variant",
choices=["auto", "regret", "remorse"],
default="auto",
help="Crusader intrinsic numbering to apply during export (default: auto, fallback regret)",
)
args = parser.parse_args()
output_root = Path(args.output_dir)
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"
output_root.mkdir(parents=True, exist_ok=True)
rows = load_rows()
layout_by_entry = load_layout_by_entry()
rows = load_rows(class_event_index)
layout_by_entry = load_layout_by_entry(class_layout_index)
index_rows: list[dict[str, str]] = []
exported = 0
@ -130,7 +140,7 @@ def main() -> None:
layout_row = layout_by_entry.get(entry_index)
if layout_row is None:
continue
ir = parse_body_ir(row, layout_row)
ir = parse_body_ir(row, layout_row, None if args.variant == "auto" else args.variant, extracted_root)
pseudocode = render_pseudocode(ir)
path = output_path_for_row(output_root, row)