Skip to content

cite_labels ​

Tool tools/triage/cite_labels.py (program, Triage). Make function labels from a reimplementation's citations: every item whose comment says "Original: FUN_xxxx" names that original function.

Run it with ./gameframe run cite_labels ARGS or python3 tools/triage/cite_labels.py. Source on GitHub.

Its own help ​

This is the help text in the tool itself, as ./gameframe tool cite_labels prints it.

text
Make function labels from a reimplementation's citations: every item whose comment says
"Original: FUN_xxxx" names that original function.

Usage: cite_labels.py SOURCE_DIR [--existing names.tsv] [--functions functions.tsv] [--any] [--prefix P]
                      [--notes] [--module NAME [--segment SEG]] [--no-lines] [--out FILE] [--check FILE]

GameFrame's rule is that every ported item names the original function it came from, in a
comment such as `/// Original: FUN_1400be770` (or `// Original: 1400be770`). The port then knows
far more names than labels/names.tsv, and the decompiled code that the next session reads still
says FUN_1400be770. This tool reads the citations and writes a labels file: each cited address
gets the name of the item declared after the comment, a function, a method (Type::method), a
struct, an enum or a class, in Rust, C, C++, Python, JavaScript or TypeScript.

- In a git repository only tracked files are read, so decompiled code and game files in ignored
  folders (analysis/, derived/, game/) are never read. Elsewhere hidden and build folders are
  skipped.
- An "Original:" list that ends with a comma goes on in the next comment line.
- When one item cites several functions, the first gets the item's name and the others get the
  name with _2, _3 and so on after it.
- A citation on a struct's field, an enum's variant or a constant names Type::field,
  Enum::Variant or Block::NAME. A function's or a type's name wins over these for the same
  address, because a field or a variant only mentions a function that something else ports.
- A citation that is not followed by an item (a module's comment, a note in a body) is counted and
  left out.
- --notes also reads a Rust module's note (`//!`): its citations name the module (the file, or its
  folder for mod.rs, lib.rs and main.rs), ranked below every item's name.
- --existing names.tsv: addresses already labelled there by hand are left out, so a person's label
  always wins.
- --out FILE writes the labels (address, label, evidence as file:line); without it they are printed.
- --functions FILE (Ghidra's functions.tsv from the export) keeps only addresses where a function
  starts, which leaves out the ends of ranges and addresses inside functions.
- --any counts the first address in a comment directly above an item, not only those after
  "Original:", for ports that cite as `unit.Procedure` (1000:abf8). Use it with --functions.
  Each function or type takes one such address; fields, variants and constants take none. An
  "Original:" citation of the same address wins.
- --prefix P, with --any: an address outside an "Original:" citation counts only when written
  with P before it (--prefix FUN_). Ports that write instruction addresses as 0x1401259c5 and
  functions as FUN_1401259c0 then need no functions.tsv, so the result is the same on every
  machine.
- --module NAME reads citations written as NAME:offset (an overlay or module and an offset in it,
  `EL2MATH3:1cf5`) and gives the address as SEG:offset, Ghidra's numbering of that overlay
  (--segment, 1000 by default). Run it once for each overlay, with --out labels/NAME.tsv:
  decomp_query.py reads labels/<binary name>.tsv for that binary.
  Other addresses are left out.
- --no-lines gives the evidence as the file alone. A committed labels file then changes only when
  a citation or an item's name changes, not with every edit above it.
- --check FILE exits 1 if FILE differs from what the tool would write, for a test that keeps the
  generated labels current.

Point decomp_query.py at the result with --labels, or keep it beside labels/names.tsv. Standard
library only.

Named by ​

Skills: re-land.

Code: Apache 2.0. Content: CC0 1.0. No game material: bring your own copy.