
    $Jj                       d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ej                  j                  d e e	e      j!                         j"                               ddlmZmZ  e	e      j!                         j*                  d   Zedz  Zed	z  Zd
ZdZddhZdZd)dZd*dZd+dZd,dZ d-dZ!d.dZ"d/dZ#d0dZ$d1dZ%d2dZ&d3dZ'd4dZ(d5dZ)	 	 	 	 	 	 	 	 	 	 	 	 d6dZ*	 	 	 	 	 	 d7dZ+dd	 	 	 	 	 	 	 	 	 	 	 	 	 d8d Z,d9d!Z-d"d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d#Z.d;d$Z/d<d%Z0d<d&Z1d=d'Z2e3d(k(  r e2        yy)>a  Review direct pre-entry references to route-relevant selector roots.

The selected-root consumer and opcode 0x4f selector-byte writer are already
grounded separately.  This pass asks a narrower static question:

Can any direct pointer/reference prove who enters a root-local opcode 0x4f
self-writer, or who selects the current route root before the consumer runs?

It deliberately separates selector-table root-start references from stronger
pre-entry execution proof.
    )annotationsN)Path)Any)offset_to_varead_sections   zHwanse2.exeoutz(selector-root-preentry-reference-blockedz2:0z0:0z1:0z10:0c                    | yd| dS )N 0x08x values    0tools/build_selector_root_preentry_ref_review.pyhxr   %   s    }c{    c                     | sy t        | d      S )N   )intr   s    r   	parse_hexr   +   s    ub>r   c                p    | j                         s|S t        j                  | j                  d            S Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     r   	load_jsonr#   1   s*    ;;=::dnngn677r   c                \    | j                  t        j                  |dd      dz   d       y )NF   )ensure_asciiindent
r   r   )
write_textr   dumps)r!   payloads     r   
write_jsonr,   7   s%    OODJJwU1ELW^O_r   c                *    | j                  |d       y r   )r)   )r!   texts     r   r)   r)   ;   s    OOD7O+r   c                N    t        j                  | d      S t        |             S )Nr   )htmlescapestrr   s    r   hr3   ?   s!    ;;U]r;;E
;;r   c                l    |y| D ],  }|d   |cxk  r|d   |d   z   k  sn t        |d         c S  y)Nfilevaraw_sizename)r2   )sectionsr6   sections      r   section_for_var;   C   sL    	z (4=BD1D!DDwv''( r   c                    | j                  d      xs i j                  d      xs i }|j                  d      xs g }|D cg c]  }|j                  d      s| c}S c c}w )Nopcode4fDataScanrootSelfWritePatternrouteContextSelfWriteRowsrootContextget)runtime_selector_writespatternrowsrows       r   
route_rowsrG   L   s]    '++,>?E2JJKabhfhG;;239rD:C377=#9C:::s   A A c                   i }| D ]}  }|j                  d      xs i }|j                  d      }|j                  d      xs d}|rd|vrE|j                  dd      \  }}t        |d      t        |d      f|t        |      <    |S )Nr@   selectorrootRangeHexr   ..r   r   )rB   splitr   r2   )rE   rangesrF   contextrI   
root_rangestartends           r   selector_rangesrR   R   s    )+F ?''-(.B;;z*[[06B
4z1%%dA.
s!$UBS" >s8}? Mr   c                b    |y | j                         D ]  \  }\  }}||cxk  r	|k  s|c S   y N)items)rM   r6   rI   rP   rQ   s        r   selector_for_ref_varV   _   sD    	z"(,,. ,5#BO  r   c           	        g }t        j                  d|      }d}	 | j                  ||      }|dk  r	 |S t        ||      }|j	                  t        |      t        |      t        ||      t        ||      d       |dz   }h)N<Ir   )fileOffsetHexrefVaHexr:   refSelectorr   )structpackfindr   appendr   r;   rV   )	exer9   r   rM   rE   rD   offsethitr6   s	            r   exact_dword_refsrc   h   s    !#Dkk$&GF
hhw'7 K (C(!#CrF)(B7262>		
 q r   c                    i }| D ]I  }|j                  d       d|j                  d       }|j                  d      }|s<t        |      ||<   K |S )Ngroup:slotselectedPointerVaHex)rB   r2   )	selectorsrE   rI   keyr6   s        r   selected_pointer_va_by_selectorrk   }   s`    D  g&'qf)=(>?\\01BDI	 
 Kr   c                r    t        |      }|*| j                  |t                     j                  |       y y rT   )r   
setdefaultsetadd)labelsr   labelparseds       r   add_target_labelrs      s4    uF&#%(,,U3 r   c                   i }| j                  d      xs i j                  d      xs i }|j                  d      xs g D ]f  }|j                  d      xs i }|j                  d      }	t        ||j                  d      |	 d       t        ||j                  d      |	 d	       h |j                  d
      xs g D ]T  }t        ||j                  d      d       |j                  d      xs g D ]  }
t        ||
j                  d      d         V |j                  d      xs g D ]:  }t        ||j                  d      d       t        ||j                  d      d       < |j                  d      xs g D ]T  }t        ||j                  d      d       |j                  d      xs g D ]  }
t        ||
j                  d      d         V |j                  d      xs g D ]:  }t        ||j                  d      d       t        ||j                  d      d       < |j                  d
      xs g D ](  }dD ]!  \  }}t        ||j                  |      |       # * |S )Nr=   r>   r?   r@   rI   rootHexz-root-startvaHexz-opcode4f-self-writerrE   scriptVaHexzopcode2f-scriptopcode2fCommandscommandVaHexzopcode2f-command	inventoryinitializerVaHexzactive-object-initializerzactive-object-scriptscriptsfirstCommandszactive-object-first-commandinitializerRefRowszselected-root-initializerz selected-root-initializer-script))rawTargetVaHexz0307-raw-target)targetEntryVaHexz0307-target-entry)rw   z0307-script)choiceEntryVaHexz0307-choice-entry)rB   rs   )rC   prompt_owner_auditactive_object_inventoryactive_initializer_reviewactive_target_auditrp   root_patternrF   rN   rI   commandrj   rq   s                r   known_current_target_labelsr      s~    #%F,001CDJOOPfgmkmL ;<B W''-(.B;;z*Y!7H:[9QR!1hZ?T3UV	W "%%f-3 V!79JKww128b 	VGVW[[%@BTU	VV
 '**;7=2 Q);!<>YZ!79OPQ '**95; Z!79OPww/52 	ZGVW[[%9;XY	ZZ
 ),,-ABHb ]);!<>YZ!79[\] #&&v.4" :
 	:JC VSWWS\59	:: Mr   c                  |r| j                  d      |k(  ry| j                  d      dk(  ry| j                  d      dk(  r| j                  d      dk(  ry	| j                  d      d
k(  r+| j                  d      dk(  ry| j                  d      dk(  ryy| j                  d      dk(  ry| j                  d      dk(  ryy)NrZ   z selector-table-current-root-cellpreviousDwordHex
0x00000307ztagged-0307-current-range-entry
0x0000005anextDwordHex
0x0000034bz/descriptor-0x5a-then-0x034b-current-range-entry
0x00000004targetFirstOpcodeHex0x6dzopcode04-to-object-script-entry0x01z opcode04-to-display-continuationz#opcode04-current-subentry-reference0x31zflag-write-current-range-entry0x32zflag-branch-current-range-entryz2unclassified-address-predecessor-current-range-refrA   )rF   current_selector_table_refs     r   'classify_address_predecessor_bridge_rowr      s    
 "cggj&9=W&W1
ww!"l20
ww!"l2sww~7NR^7^@
ww!"l277)*f4477)*f454
ww%&&0/
ww%&&00?r      )sample_limitc                  |j                  t              }|j                  t              }|r|s	ddi i g i dS |\  }}	|\  }
}|j                  t              }g }i }i }i }t        dt	        |       dz
  d      D ]  }t        j                  d| |      d   }|
|cxk  r|k  sn ,t        ||      }||cxk  r|	k  sn F|dk\  rt        j                  d| |dz
        d   nd }|dk\  rt        j                  d| |dz
        d   nd }|dz   t	        |       dz
  k  rt        j                  d| |dz         d   nd }d }d }d }d}d }d }|D ],  }|d	   |cxk  r|d	   |d
   z   k  sn |d   ||d	   z
  z   } n |d|cxk  rt	        |       k  rzn nw| |   }|dz   t	        |       k  rt        j                  d| |      d   }|dk(  rd}|dz   }n:|dk(  r5|dz   t	        |       k  r$d}t        j                  d| |dz         d   }|dz   }t        |j                  |t                           }t        |      t        |      t        |      d||
z
  d|d|dndt        |      |t        |      t        |      t        |      t        |      t        |      |d}t        ||      |d<   |j                  |       |d   } |j                  | d      dz   || <   |j                  | g       }!t	        |!      |k  r|!j                  |       |D ]  }"|j                  |"d      dz   ||"<     dt        t        |       dt        |	       t        t        |
       dt        |       |t	        |      ||dd||dS )Nzmissing-ranger   )statusrowCountclassificationCountsknownTargetLabelCountsrE   samplesByClassification      rX      r   r6   r7   raw1   zactual-dispatcher-flag-write2   zactual-dispatcher-flag-branch+0x03xr   02x)rZ   rY   targetValueHextargetOffsetHexr   targetFirstDwordHextargetActualOpcodeRoletargetBranchTargetHextargetFallthroughHexprevious2DwordHexr   r   knownTargetLabels)r   classificationr   
classifiedrK   Fa`  The 10:0 -> 2:0 bridge is real as a data-structure bridge, but its rows resolve to selector-table, 0x0307 initializer-list, 0x5a/0x034b descriptor packet, opcode04-style subentry references, and actual-dispatcher opcode31/32 flag-write/flag-branch subentries. No row is promoted to a concrete route execution producer without a scheduler/consumer path.)r   addressPredecessorSelectoraddressPredecessorRangeHexcurrentSelectorcurrentRangeHexcurrentSelectorTableRefVaHexr   r   r   routeExecutionProofFound
conclusionrE   r   )rB   ADDRESS_PREDECESSOR_SELECTORCURRENT_SELECTORrangelenr\   unpack_fromr   sortedrn   r   r   r_   rm   )#r`   r9   rM   selector_table_refstarget_labelsr   predecessor_rangecurrent_rangepredecessor_startpredecessor_endcurrent_startcurrent_endr   rE   classification_countslabel_countssamples_by_classificationra   targetref_vaprevious_dwordprevious2_dword
next_dwordtarget_offsettarget_first_opcodetarget_first_dwordtarget_actual_opcode_roletarget_branch_targettarget_fallthroughr:   rp   rF   r   samplesrq   s#                                      r   'scan_address_predecessor_current_bridger      s4    

#?@JJ/0MM%$&&(')
 	
 *;&!.M;!4!8!89I!J!#D,.#%LAC3s8a<+ :A##D#v6q95+5h/!V=o=IOST++D#vzB1EZ^JPTU+&,,T3
CAF[_EKaZSVWZS[^_S_E_V''c6A:>qAei
"!$&!#! 	Gt}L9L)LL '&74=2H I	 $m)Fc#h)F"%m"4q CH,%+%7%7c=%QRS%T""d*,J)%+aZ"$,1Bc#h1N,K)'-'9'9$]UVEV'WXY'Z$%+aZ"))&#%896
Z j!$Vm%;C$@AFYFeb)<S(A$Bkm#%&8#9&?%'(<%=$&'9$:!#O!4 "> 2zN!'
 !H'A!
 	C-.0E0I0I.Z[0\_`0`n-+66~rJw<,&NN3 	AE"."2"25!"<q"@L	As:Az &B)+,=)>(?r"_BUAV&W+ /02k?2CD(BI 5".$)k
 #<% r   c                N   |j                  |      }g }| D ]  }d}|r|j                  d      |k(  rd}nX|j                  d      dk(  rd}nA|j                  d      |k(  rd}n*|j                  d      rd	}n|j                  d      d
k(  rd}|j                  i |d|i        |S )NotherrZ   selector-table-selected-pointerr:   .textztext-direct-referencer[   zsame-root-referencezother-root-referencez.datazexternal-data-referencerole)rB   r_   )refsrI   r   selector_table_refrE   refr   s          r   annotate_root_refsr   @  s    ,00:D +#''*"59K"K4DWWY7**DWW]#x/(DWW]#)DWWY7*,D)s)FD)*+ Kr      c          
     :   i }i }g }	g }
t        dt        |       dz
  d      D ]  }t        j                  d| |      d   }||cxk  r|k  sn ,t	        ||      }t        ||      }t        ||      }|xs | d}|j                  |d      dz   ||<   |j                  |d      dz   ||<   t        |      t        |      ||t        |      d||z
  dd	}|t        v r*t        k(  r!t        |	      |k  s|	j                  |       |k7  st        |
      |k  s|
j                  |        t        |       d
t        |       t        |j                               ||t        fd|j                         D              |j                  dd      |
|	d	S )Nr   r   r   rX   z	:externalr   r   r   )rZ   rY   r:   r[   targetSelectorr   r   rK   c              3  J   K   | ]  \  }}t         k(  r|t        v r|  y wrT   )r   SOURCE_OR_PREDECESSOR_SELECTORS).0rN   counttarget_selectors      r   	<genexpr>z"scan_range_refs.<locals>.<genexpr>  s.      9
"22wBa7a 9
s    #r   )	r   targetRangeHextotalAlignedRangeRefCountcountsByRefContextcountsBySection)sourceOrPredecessorToCurrentRangeRefCounttextRangeRefCountexternalSamples#sourceOrPredecessorToCurrentSamples)r   r   r\   r   r   r;   rV   rB   r   r   r   r_   sumvaluesrU   )r`   r9   r   target_start
target_endrM   r   countssection_countssource_or_predecessor_samplesexternal_samplesra   r   r6   r:   ref_selectorbucketrF   s     `               r   scan_range_refsr   S  s     F%'N:<!-/3s8a<+ -""4f5a82
2(F+ 2.*6266G9I!6FA.2v"0"4"4Wa"@1"Dw2Z'- i!$U\%9#$>?
 ::Rb?b01L@-44S9_,#$|3 '',1-6 *-.bJ0@A%(%9$)58 9
"(,,.9
 6

 ,//;+/L r   c                ,   | j                   j                         }t        |      }t        | j                  g       }t        | j
                  i       }t        t        dz  i       }t        t        dz  i       }t        t        dz  i       }t        t        dz  i       }t        |      }	t        |	      }
t        |      }t        |||||      }g }d}d}d}|	D ]  }|j                  d      xs i }t        |j                  d            }t        |j                  d            }t        |j                  d	            }t        |d
      }t        |d
      }t        t        ||||
      ||      }t        ||||
      }|t!        |      z  }|t#        d |D              z  }||rt%        d |D              rdndz  }|j'                  |||j                  d      ||j                  d      |j                  d      |j                  d      t!        |      t#        d |D              |t!        |      t#        d |D              ||j                  |      d        |
j)                         D cg c]  \  }\  }}t+        ||||||
       }}}}t-        d |D        i       }|j                  di       xs i }|j                  t.        d      }t1        |||
||      } i dddt2        dt!        |	      d|D cg c]  }|d   	 c}d|d|d|dt4        d |j                  d!d      d"|j                  d"d      d#t.        d$|d%| j                  d&i       d'| j                  d(d)      d*d)d+|dkD  d,d-}!i |!||| g d.d/S c c}}}w c c}w )0Nz'opcode2f_prompt_stream_owner_audit.jsonz#active_object_script_inventory.jsonz7selected_root_active_object_initializer_ref_review.jsonz*scene_0307_active_object_target_audit.jsonr   r@   rI   ru   rv   r   c              3  J   K   | ]  }|j                  d       dk(  sd  ywr:   r   r   NrA   r   r   s     r   r   zbuild.<locals>.<genexpr>  s!     (as3779CUY`C`(a   ##c              3  D   K   | ]  }|j                  d       dk(    yw)r   r   NrA   r   s     r   r   zbuild.<locals>.<genexpr>  s+       EP  BSWWV_XyEy  EPs    r   rJ   valueHex	routeRolerelativeOffsetHexc              3  J   K   | ]  }|j                  d       dk(  sd  ywr   rA   r   s     r   r   zbuild.<locals>.<genexpr>  s!     ,e3swwyGY]dGdQ,er   c              3  J   K   | ]  }|j                  d       dk(  sd  ywr   rA   r   s     r   r   zbuild.<locals>.<genexpr>  s"     2mswwW`OaelOl12mr   )rI   ru   rJ   selfWriterVaHexselfWriterValueHexr  selfWriterOffsetHexrootExactRefCountrootExactTextRefCountrootRefsselfWriterExactRefCountselfWriterExactTextRefCountselfWriterRefsselectorTableRefVaHexc              3  :   K   | ]  }|d    t         k(  s|  ywr   Nr   r   rF   s     r   r   zbuild.<locals>.<genexpr>  s      kEUAVZjAj k   r   kindz(hwanse-selector-root-preentry-ref-reviewpromotionStatusrouteSelfWriterRowCountrouteSelectorsexactSelfWriterRefCountexactRootTextRefCountselectorTableOnlyRootRefCountr   currentRangeTextRefCountr   r   r   (addressPredecessorToCurrentRangeRefCount,addressPredecessorBridgeClassificationCountsr   0addressPredecessorBridgeRouteExecutionProofFoundr   FpreEntryProducerProofFound"rootLocalSelfWriterEntryProofFoundroutePromotionBlockedReasona  Route-relevant root starts are directly referenced only through selector-table selected-pointer cells, and root-local opcode 0x4f self-writer addresses have no direct dword references. No source/predecessor root contains an aligned pointer into the current selector 2:0 range. Address-predecessor selector 10:0 does contain current-range pointers, so that bridge is the next static candidate, but it is not source/predecessor route proof by itself.)zMfind a pre-entry command that writes selected root 0x00540714 into 0x0059de30zSfind a strict source/predecessor reference into the current selector 2:0 root/rangez:capture runtime selected-root consumer state at 0x0040adfezNprove a normal control path from a source hotspot to the current root consumer)rootReviewsrangeReviewsaddressPredecessorBridgeremainingProofs)r`   
read_bytesr   r#   ri   rC   OUTrG   rR   rk   r   rB   r2   r   r   rc   r   r   allr_   rU   r   nextr   r   PROMOTION_STATUSr   )"argsr`   r9   ri   rC   r   r   r   r   rE   rM   r   r   root_reviewsexact_self_writer_ref_countexact_root_text_ref_count"selector_table_only_root_ref_countrF   rN   rI   root_hex
writer_hexroot_va	writer_va	root_refswriter_refsrP   rQ   range_reviewscurrent_range_reviewcurrent_counts$address_predecessor_to_current_countaddress_predecessor_bridgesummarys"                                     r   buildr>    sn   
((


CS!H$.."-I'(D(DbI"3)R#RTVW'.S(SUWX )#0i*ikm n#C*V$VXZ[-.DT"F9)D/!M L"# !)*& 
''-(.Bw{{:./w{{9-.)*
h#
B'	&'7XwPV'WYacvw	&sHiH#s;'77#!S(ai(a%aa!*9  EP  FO  EP  BPa  VW  	W*$# 'N ;#-&)ggj&9 WW[1'.{{3F'G%(^),,e),e)e%+.{+;/22m2m/m"-)<)@)@)J	

B '-lln "Hluc 	XxVDM    k kmop)--.BBGM2N+9+=+=>Z\]+^(!H":+ 	"3t9 	lCs3z?C	
 	"#> 	 !: 	()K 	+ 	#$8$<$<=PRS$T 	45I5M5MNy{|5} 	%&B 	34X 	78R8V8VWmoq8r 	;<V<Z<Z[uw|<} 	%e  	-.IA.M!" 	&X%G2
#%$>
 Q& Ds   0N
;Nc                4   ddd| d    dd| d    d| d	    d
| d    d| d    d| d    d| d    d| d    d| d    d| d    d| d    dd| d    d| d   dddddg}| d    D ]  }d!j                  t        |j                  d"      xs g D ch c]  }|j                  d#d       c}            xs d$}|j                  d%|d&    d'|d(    d'|d)    d*|d+    d,|d-    d,|d.    d/|j                  d0      xs d$ d*| d1        |j	                  g d2       | d3   D ]x  }d!j                  d4 t        |j                  d5i       j                               D              }|j                  d%|d6    d'|d7    d*|d8    d,|d9    d,|d    d,|xs d$ d1       z |j	                  g d:       t        d; | d3   D        i       }|j	                  d<d=g       |j                  d>      xs g D ]B  }|j                  d%|d?    d*|d@    d/|j                  dA      xs d$ d'|dB    d'|dC    dD       D | j                  dE      xs i }|j	                  ddFd|j                  dG      xs dddHdIg       t        |j                  dJ      xs i j                               D ]  \  }}	|j                  d%| d*|	 d1        |j	                  g dK       t        |j                  dL      xs i j                               D ]  \  }}
|
D ]  }d!j                  |j                  dM      xs g       xs d$}|j                  d%| d'|d?    d'|dB    d'|dC    d'|j                  dN      xs d$ d*|j                  dO      xs d$ d/|j                  dP      xs d$ d'|j                  dQ      xs d$ d'|dR    d'|dS    d*| d1         |j	                  g dT       |j	                  dU | dV   D               |j                  d       dWj                  |      S c c}w )XNz*# Selector Root Pre-entry Reference Reviewr   z- promotion status: `r  `z- route self-writer rows: r  z - exact self-writer dword refs: r  z- exact root text refs: r  z!- selector-table-only root refs: r  z- current range text refs: r  z,- source/predecessor -> current range refs: r   z- address-predecessor `r   z` -> current range refs: r  z4- address-predecessor bridge route execution proof: r   z'- address-predecessor bridge classes: `r  z"- pre-entry producer proof found: r!  r#  z## Root Exact Referenceszn| selector | root | self-writer | root refs | root text refs | self-writer refs | selector table cell | role |z4| --- | --- | --- | ---: | ---: | ---: | --- | --- |r$  , r  r   -z| `rI   z` | `ru   r  z` | r
  z | r  r  z | `r  z |)r   z## Range Reference Summaryr   zu| target selector | range | total aligned refs | text refs | source/predecessor -> current refs | counts by context |z(| --- | --- | ---: | ---: | ---: | --- |r%  c              3  0   K   | ]  \  }}| d |   ywrf   Nr   r   rj   r   s      r   r   zmarkdown.<locals>.<genexpr>!  s     p
UcU!E7+p   r   r   r   r   r   )r   z!## Current Range External Samplesr   c              3  :   K   | ]  }|d    t         k(  s|  ywr  r  r  s     r   r   zmarkdown.<locals>.<genexpr>'       hCcBR>SWg>gChr  z?| ref | section | ref selector | target value | target offset |z| --- | --- | --- | --- | --- |r   rZ   r:   r[   r   r   z` |r&  z,## Address-Predecessor Bridge Classificationr   z| class | count |z| --- | ---: |r   )r   z### Bridge Samplesr   z| class | ref | target | offset | target first opcode | actual role | branch target | fallthrough | previous | next | known target labels |zC| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |r   r   r   r   r   r   r   r   )r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   yw)z- Nr   )r   items     r   r   zmarkdown.<locals>.<genexpr>L  s     D2dVDs   r'  r(   )joinr   rB   r_   extendrU   r+  )r+   linesrF   r   rolesr   currentbridgerj   r   r   rp   s               r   markdownrQ    su   4

(9 :;1=
$W-F%G$HI
*73L+M*NO
"7+B#C"DE
+G4S,T+UV
%g.H&I%JK
6w?j7k6lm
!'*F"G!HHabi  kU  cV  bW  	X
>wGy?z>{|
1':h2i1jjkl
,W5Q-R,ST
-.
"
x>)E, }% 
		&ATAZXZ![##''&""5![\]dad#j/"%I'7uSAR=S<TTX&'(C0G,H+ISQjMkLl m/07C8UG2G	

 
LL   ~& 
pfSWWMaceEfElElEn>opp#&'(c2B.C-DDMhIiHjjm&'(C0[,\+]]`agankn`ooqs	

 
LL>?h7>#:hjlmG	LLSUvwx{{,-3 
#j/"$s9~&6d377=;Q;XUX:Y Z$%&eC0A,B+C3H	


 [[34:F	LL
6


< &B
  fjj)?@FBMMOP /
Us3%tE7"-./	LL   

+D E KRRTU 	W 	CYYsww':;ArBIcFLLcU%J0c:J6K5LERUVgRhQi jGG23:s;4H`@a@heh?i jGG34;< =GG23:s;5EWAX@Y Z'(VHB	8		 
LL01	LLD1B)CDD	LL99Uw "\s   Pc                   dj                  d | d   D              }dj                  d | d   D              }t        d | d   D        i       }dj                  d |j                  d      xs g D              }| j                  d	      xs i }dj                  d
 t        |j                  d      xs i j	                               D              }dj                  d t        |j                  d      xs i j	                               D              }dj                  g dt        | d          dt        | d          d| d    d| d    d| d    d| d    d| d    d| d    dt        | d           d!| d"    d#| d$    d%| d&| d'| d(t        |j                  d)      xs d       d*| d+| d,      S )-Nr(   c              3    K   | ]  }d t        |d          dt        |d          dt        |d          d|d    d|d    d|d	    d
t        |j                  d      xs d       dt        dj                  t        |j                  d      xs g D ch c]  }|j                  dd       c}            xs d       d  yc c}w w)<tr><td><code>rI   </code></td><td><code>ru   r  </code></td><td>r
  	</td><td>r  r  </td><td><code>r  rB  rA  r  r   r   
</td></tr>N)r3   rB   rK  r   )r   rF   r   s      r   r   zhtml_page.<locals>.<genexpr>R  s       	s:'( )s9~&' (s,-./ 0&'( )*+, -,-. /sww67>3?@ A6#''*BUB[Y["\337762#6"\]^ebefg h		 #]s   BCC0+ Cr$  c              3    K   | ]  }d t        |d          dt        |d          d|d    d|d    d|d    dt        d	j                  d
 t        |j                  di       j	                               D              xs d       d  yw)rT  r   rU  r   rV  r   rW  r   r   rA  c              3  0   K   | ]  \  }}| d |   ywrD  r   )r   kvs      r   r   z&html_page.<locals>.<genexpr>.<genexpr>f  s     d$!QaS!:drF  r   rB  rY  N)r3   rK  r   rB   rU   r  s     r   r   zhtml_page.<locals>.<genexpr>_  s      
 	s+,-. /s+,-. /./0 1&'( )>?@ Ad&AUWY9Z9`9`9b2cddkhklm n	
s   B
Br%  c              3  :   K   | ]  }|d    t         k(  s|  ywr  r  r  s     r   r   zhtml_page.<locals>.<genexpr>j  rH  r  c              3     K   | ]b  }d t        |d          dt        |d          dt        |j                  d      xs d       dt        |d          dt        |d	          d
 d yw)rT  rZ   rV  r:   rX  r[   rB  rU  r   r   z</code></td></tr>N)r3   rB   r  s     r   r   zhtml_page.<locals>.<genexpr>k  s      	 	s:'( )Y ! "sww}-456 7s+,-. /s,-./ 0		s   A(A*r   r&  c              3  F   K   | ]  \  }}d t        |       d| d  yw)rT  rV  rY  N)r3   rE  s      r   r   zhtml_page.<locals>.<genexpr>v  s;      "
 C		sVH g 	"s   !r   c              3  H  K   | ]  \  }}|D ]  }d t        |       dt        |d          dt        |d          dt        |d          dt        |j                  d      xs d       dt        |j                  d      xs d       d	t        |j                  d
      xs d       dt        |j                  d      xs d       dt        |d          dt        |d          dt        dj                  |j                  d      xs g       xs d       d   yw)rT  rU  rZ   r   r   r   rB  rV  r   rX  r   r   r   r   rA  r   rY  N)r3   rB   rK  )r   r   r   rF   s       r   r   zhtml_page.<locals>.<genexpr>}  sb     # $NG# 	~&' (s:'( )s+,-. /s,-./ 0sww56=#>? @129c:; <sww67>3?@ Asww56=#>? @s-./0 1s>*+, -377#67=2>E#FG H	#	#s   D D"r   r   a  <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Selector Root Pre-entry Reference Review</title>
  <style>
    body { margin: 24px; background: #101010; color: #eee; font: 14px system-ui, sans-serif; }
    table { border-collapse: collapse; width: 100%; margin: 16px 0 28px; }
    th, td { border: 1px solid #333; padding: 6px 8px; vertical-align: top; }
    th { background: #1d1d1d; position: sticky; top: 0; }
    code { color: #f5d76e; }
    .warn { color: #ffd166; }
  </style>
</head>
<body>
  <h1>Selector Root Pre-entry Reference Review</h1>
  <p class="warn">promotion status: <code>r  z</code></p>
  <p>r#  z,</p>
  <ul>
    <li>route self-writer rows: r  z,</li>
    <li>exact self-writer dword refs: r  z$</li>
    <li>exact root text refs: r  z-</li>
    <li>selector-table-only root refs: r  z'</li>
    <li>current range text refs: r  z;</li>
    <li>source/predecessor -&gt; current range refs: r   z(</li>
    <li>address-predecessor <code>r   z"</code> -&gt; current range refs: r  z@</li>
    <li>address-predecessor bridge route execution proof: r   z</li>
  </ul>
  <h2>Root Exact References</h2>
  <table><thead><tr><th>selector</th><th>root</th><th>self-writer</th><th>root refs</th><th>root text refs</th><th>self-writer refs</th><th>selector table cell</th><th>root ref roles</th></tr></thead><tbody>
z
  </tbody></table>
  <h2>Range Reference Summary</h2>
  <table><thead><tr><th>target selector</th><th>range</th><th>total aligned refs</th><th>text refs</th><th>source/predecessor -&gt; current refs</th><th>counts by context</th></tr></thead><tbody>
z
  </tbody></table>
  <h2>Current Range External Samples</h2>
  <table><thead><tr><th>ref</th><th>section</th><th>ref selector</th><th>target value</th><th>target offset</th></tr></thead><tbody>
zN
  </tbody></table>
  <h2>Address-Predecessor Bridge Classification</h2>
  <p>r   zS</p>
  <table><thead><tr><th>classification</th><th>count</th></tr></thead><tbody>
a  
  </tbody></table>
  <table><thead><tr><th>classification</th><th>ref</th><th>target</th><th>offset</th><th>target first opcode</th><th>actual role</th><th>branch target</th><th>fallthrough</th><th>previous</th><th>next</th><th>known target labels</th></tr></thead><tbody>
z$
  </tbody></table>
</body>
</html>
)rK  r+  rB   r   rU   r3   )r+   	root_rows
range_rowsrO  sample_rowsrP  bridge_count_rowsbridge_sample_rowss           r   	html_pagerg  Q  sL   		  =) I  
 >*
 
J h7>#:hjlmG)) 	 ;;017R	 	K [[34:F		 "
 !&**-C"D"J!Q!Q!ST"   # (.vzz:S/T/ZXZ.a.a.c'd# "3 3 + 3" ,-W5F-G+H*I#3"J#3$ -./0%3$1!%3( "))B!C D)3(E')3* (//H'I&J+3*K+3,  ''>?@-3,A(-3. )00O(P'Q/3.R"/30 #**D"E!F130G6132 7>>i6j5k332l#334 $%W-I%J#K"L534 Mo534 pw  xb  pc  od534d;536 <CCu;v:w736x73> ?3>?3F G3FG3N O3NO3T 

< &B'(U3T)U3X  Y3XY3^  _3^_3 3r   c                 
   t        j                         } | j                  dt        t               | j                  dt        t
        dz         | j                  dt        t
        dz         | j                  dt        t
        dz         | j                  d	t        d d
       | j                  dt        d        | j                         }t        |      }t        |j                  |       |j                  rt        |j                  t        |             |j                  rEt        |j                  t        |             t        d|j                   d|j                          y t        d|j                          y )Nz--exe)typedefaultz--selectorszsave_scene_selectors.jsonz--runtime-selector-writesz/save_selector_runtime_selector_byte_writes.jsonz
--json-outz&selector_root_preentry_ref_review.jsonz--md-outzOptional markdown export path.)ri  rj  helpz
--html-outzwrote rA  )argparseArgumentParseradd_argumentr   EXEr)  
parse_argsr>  r,   json_outmd_outr)   rQ  html_outrg  print)parserr-  r+   s      r   mainrv    s0   $$&F
dC8
D#@[:[\
3$NH  A
4?g9gh

tBbc
4>DDkGt}}g&{{4;; 12}}4==)G"45t}}oR78t}}o&'r   __main__)r   
int | Nonereturnr2   )r   
str | Nonery  rx  )r!   r   r"   r   ry  r   )r!   r   r+   r   ry  None)r!   r   r.   r2   ry  r{  )r   r   ry  r2   )r9   list[dict[str, Any]]r6   rx  ry  r2   )rC   dict[str, Any]ry  r|  )rE   r|  ry  dict[str, tuple[int, int]])rM   r~  r6   rx  ry  rz  )
r`   bytesr9   r|  r   r   rM   r~  ry  r|  )ri   r|  ry  dict[str, str])rp   dict[int, set[str]]r   rz  rq   r2   ry  r{  )rC   r}  r   r}  r   r}  r   r}  r   r}  ry  r  )rF   r}  r   rz  ry  r2   )r`   r  r9   r|  rM   r~  r   r  r   r  r   r   ry  r}  )r   r|  rI   r2   r   r  ry  r|  )r`   r  r9   r|  r   r2   r   r   r   r   rM   r~  r   r   ry  r}  )r-  zargparse.Namespacery  r}  )r+   r}  ry  r2   )ry  r{  )4__doc__
__future__r   rl  r0   r   r\   syspathlibr   typingr   r!   insertr2   __file__resolveparentprobe_exe_scene_tablesr   r   parentsROOTro  r)  r,  r   r   r   r   r   r#   r,   r)   r3   r;   rG   rR   rV   rc   rk   rs   r   r   r   r   r   r>  rQ  rg  rv  __name__r   r   r   <module>r     s#  
 #     
   3tH~--/667 8 > H~''*
]
Ul=  #(%. % 8`,<;
*4)+)&) ,)  .	)
 () )X@	@ !+@ 		@> l	l"l 'l (	l
 'l l l^6 7	7"7 7 	7
 7 '7 7 7tk\Slpf(* zF r   