Skip to content

regionstructure Inc 0: close the W7 block-graph adapter (analysis-only) - #68

Merged
mahaloz merged 2 commits into
mainfrom
feat/regionstructure-inc0
Jun 25, 2026
Merged

mahaloz merged 2 commits into
mainfrom
feat/regionstructure-inc0

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

regionstructure Inc 0: close the W7 block-graph adapter (analysis-only)

First increment of the region-structurer foundation (docs/region-structurer-roadmap.md).
Makes the ported angr RegionIdentifier (s7_regions/kuna_regionid.rs) runnable on a
real bblocks CFG, not just synthetic test nodes. No decompiler output changes —
this is the analysis-only adapter the rest of the structurer (Inc 1+) builds on.

What

The W7 seam was stubbed: build_from_block_graph / ends_with_branchind_or_cbranch only
served the synthetic add_synthetic_block/add_synthetic_edge API. This closes it:

  • KunaRegionIdentifier::build_from_block_graph(&Funcdata) (Input A): constructs the
    working graph from the decompiler's basic blocks read-only — one k_block node per
    basic block (carrying the real seams::BlockId, keyed on its start address) and one edge
    per CFG out-edge, with the entry address set to block 0's start.
  • ends_with_branchind_or_cbranch over real ops: each node parks the
    FlowBlock::lastOp()->code() probe (CPUI_BRANCHIND / CPUI_CBRANCH, via bb_op_tail)
    precomputed once per block on a new KunaRegionNode::branchy payload; the predicate reads
    the last chain member's flag. The basic-block CFG is immutable across identification, so
    the precompute is equivalent to the C++ live probe and deterministic (block iteration
    in CFG index order; the tail op is the unique last op under (addr, ident) ordering).
    Synthetic test nodes carry no block and stay false — exactly the C++ synthetic-node path.
  • The region tree/blocks/walk console commands now drive the real adapter (the inline
    synthetic-node construction in build_region_identifier is replaced by the new method).

Tests / parity

  • tests/stages/kuna-regions.xml: assertions Render unknown types as real C types (realtypes, DIV-6) #6–Perf/actionpool cursor #8 added — they pin the region tree
    built from the real bblocks CFG (the branchind/cbranch-aware supergraph keeps the
    CBRANCH-ending entry, the nested region, and the early-out as three distinct top nodes;
    the loop's enclosing acyclic region pairs the cyclic self-loop with its exit block).
  • 3 new kuna_regionid unit tests (build_from_block_graph_*) over a real Funcdata
    diamond/chain CFG: tree shape, the supergraph branchind/cbranch behavior, and the
    non-empty-graph guard.

Gates

  • make test → PARITY OK (675/675, byte-identical — nothing in the structuring/emit
    path was touched).
  • make test-stages → PARITY OK (164/164; baseline-stages.json bumped by exactly the
    3 new region assertions, no regressions).
  • make rust-test → green.

Not wired into ActionBlockStructure/output — that is Inc 1.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac

mahaloz and others added 2 commits June 25, 2026 15:46
Make `KunaRegionIdentifier::compute()` runnable on a REAL `bblocks` CFG by
closing the W7 block-graph adapter seam in the angr RegionIdentifier port
(`s7_regions/kuna_regionid.rs` + `kuna_regiongraph.rs`), previously stubbed
for synthetic nodes only.

- Add `build_from_block_graph(&Funcdata)` (Input A): builds the working graph
  from the decompiler's basic blocks read-only — one `k_block` node per block
  (carrying the real `BlockId`, keyed on its start address) and one edge per
  CFG out-edge, entry address = block 0's start.
- Implement `ends_with_branchind_or_cbranch` over real ops: each node parks the
  `FlowBlock::lastOp()->code()` probe (CPUI_BRANCHIND / CPUI_CBRANCH, via
  `bb_op_tail`) precomputed once per block on a new `KunaRegionNode::branchy`
  payload; the predicate reads the last chain member's flag. The block CFG is
  immutable across identification, so the precompute is equivalent to the C++
  live probe and deterministic. Synthetic test nodes stay `false` (C++ path).
- Route the `region tree/blocks/walk` console commands through the real adapter
  (replacing the inline synthetic-node construction in `build_region_identifier`).
- Extend `tests/stages/kuna-regions.xml` (assertions #6-#8) to pin the region
  tree built from the real bblocks CFG, including the branchind/cbranch-aware
  supergraph shape; add 3 `kuna_regionid` unit tests over a real `Funcdata`.

ANALYSIS-ONLY: no structuring/emit path touched. `make test` PARITY OK
(675/675 byte-identical), `make test-stages` PARITY OK (164/164), rust-test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Region-structurer foundation (Inc 0) — analysis-only, no new --option. Main had
advanced with #55 (loopbreak_recovery/DIV-10), #57 (gotoreduce), #67 (macho-arm64e);
the only conflict was docs/baseline-stages.json (data_footer counts), all other
region code (s7_regions/kuna_regiongraph.rs, kuna_regionid.rs, kuna_console.rs) and
the kuna-regions.xml assertions merged cleanly. Regenerated assertions.md (45
settables, unchanged) and baseline-stages.json (171/171, incl. the 8 KUNA-REGIONS
assertions plus main's gotoreduce/loopbreak/catalog ones).

Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (171/171).
Region unit tests: regionid 6/6, regiongraph 18/18 (incl. new build_from_block_graph_*).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz merged commit 217db16 into main Jun 25, 2026
mahaloz added a commit that referenced this pull request Jun 25, 2026
Resolve union conflicts with main (which landed #60 switchguardbound +
#68/#60 region work). Both opt-in/default-off knobs coexist:

- stages.toml: union [[settable]]/[[surface]] -> surface 91->93, settable
  45->47 (29 stage-model + 15 analysis + 3 loader); header counts updated.
- kuna_stages/tests.rs: surface_count 93, settable_count 47,
  live_value present-for-23 (switch_guard_bound + tail_call_jumps both
  field-backed), catalog-json trailing-commas 46.
- catalog_bytecompat.rs: fixture_has_all_47_settables; stage_catalog.json
  fixture auto-unioned (byte-for-byte test green).
- xml.rs corpus count 138->139 (83 datatests + 56 stage tests: both the
  missing-function-call and tee-o2-tail-jumps stage tests present).
- kuna-catalog.xml: source_decompiler=angr 12, structure-recovery 7,
  opt-in-tool 8.
- PROGRESS.md: union both session entries.
- tailcalljump ElementId stays 4101 (no collision; gotoreduce=4100 on main).

Regenerated docs/assertions.md + docs/baseline-stages.json (180/180).
Gates: kuna catalog --check OK; make test PARITY OK 675/675; make
test-stages PARITY OK 180/180. docs/baseline.json untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz deleted the feat/regionstructure-inc0 branch July 29, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant