#!/usr/bin/env python3 """delever.py — take the compiler-forcing constructs ("levers") out of matched C, byte-gated per translation unit (Phase 36: the probe engine at T2, the campaign tool at T3). tools/delever.py --plan [--batch 300] [--headers] [--only X ...] # what the next batch would do (no writes) tools/delever.py --apply --batch 300 --label tu1 [--headers] [--only X ...] [-j 12] # judge every drawable body of the batch's files, KEEP the winning # text in place, mark the survivors `// !FAKE:`, ledger every site tools/delever.py --restore # every in-flight file back from inflight.json (never git checkout, R102) tools/delever.py --status # the ledger's totals tools/delever.py --apply-body TU FN FILE --label w1 [--rung E] # T6/T7: a reshaped function judged on the bytes and kept tools/delever.py --selftest # the fixture: every site kind, the decoys, a stub oracle tools/delever.py --probe --sample 150 [--seed 1] [-j 12] # T2's measurement (unchanged) THE LADDER PER BODY (deterministic, zero tokens): replay a body whose normalized text (`nhash`, func_/D_ addresses masked) matches a body the ledger already judged replays that body's accepted edit set: one compile. A disagreement falls through to the full ladder and is recorded. rung A strip-all — every removable site of the body rewritten at once, one compile, the object compared with the fleet run's (tools/delever_oracle.py). rung B greedy — if A differs: from the untouched text, the sites are re-applied one at a time (asm statements first, then pins, volatile, register); a site whose removal keeps the object identical is REMOVED, one that changes it is NEEDED — with the oracle's word (DIFFERS / COMPILE-ERROR / COMPILE-CRASH) as the reason. The verdict of a body = the set of NEEDED sites; a body with none is lever-free. THE REWRITE PER SITE (positional on the RAW text at the census's line/col; a token that is not what the census saw is REFUSED, R43): pin `register T x __asm__("$N") [= e];` -> `T x [= e];` (the `$0` zero-register variable: the declaration deleted, every use -> 0; a variable that is ever assigned is REFUSED) barrier `__asm__("" ::: "memory");`, keep-alive `__asm__("" : : "r"(x));`, launder `__asm__("" : "=r"(x) : "0"(x));` -> deleted launder whose output and input DIFFER `__asm__("" : "=r"(p) : "0"(&D_x));` -> the assignment it is: `p = &D_x;` (deleting it leaves `p` undefined — cc1 2.7.2 ABORTS on such a candidate; the T2 probe counted those as NEEDED) a hand-placed instruction (`addu %0,%1,$zero` / move / la / lh / lw / addiu / sll / …) -> its C statement, or REFUSED (no spelling) a macro-carried site: `SHB(x);` (a pure launder statement macro) -> deleted; `LAUNDER(p)` (a launder statement-expression) -> its value `((T)(p))`; a COMPOUND macro (XFER, DRAW, RTP_SND, …: real code around the asm) -> REFUSED, the lever is in the #define (T5) volatile (a cast, a body declaration, a parameter, a file-scope declaration) -> the qualifier dropped; bare `register` -> dropped GTE ops, the manifest's verbatim bodies: never touched. An asm-body (a whole routine in a C shell) is DEFERRED to T7 and marked. THE FILE IS THE WRITE UNIT, ITS FINAL COMPILE THE PROOF: every body's candidates are judged against the file's ORIGINAL text; the accepted edits of every body, the file-scope edits and the `// !FAKE:` markers are spliced once at the end, and that final text is compiled through EVERY recipe of the file (a twin's object too; every includer of a header, in parallel) — IDENTICAL or the file-scope edits are dropped and it is compiled again, or the file is restored and REFUSED (COMBINATION-FAILED, loud). The batch's touched files are left in place for the outer gate (the clean fleet run, R22, in tools/delever_cycle.sh); every file's original text is in .run/P36/delever/inflight.json before the first write, and --restore reads it. "DONE" IS A LEDGER FACT KEYED BY TEXT: every ledger row records the body's nhash BEFORE and AFTER. A body whose current nhash is some row's after-hash is done (drawn again only with --rejudge); one whose current nhash is some row's before-hash replays it. Markers are comments and do not change the hash; a reshaped body (T6/T7) gets a new hash and is drawn again. Class C/D survivors are never marked (Drew's decision 3) — the ledger is their record; class A/B survivors carry `// !FAKE: — (P36