
    UHjh                       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 ddlmZ  e	e      j!                         j,                  d   Zed	z  Zd
ZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d4dZ%d4dZ&d5dZ'd6dZ(d7dZ)d8dZ*d9dZ+d:dZ,d;dZ-d<dZ.d=d Z/d>d!Z0	 	 	 	 	 	 	 	 	 	 	 	 d?d"Z1d@d#Z2	 	 dA	 	 	 	 	 	 	 	 	 	 	 dBd$Z3	 	 dA	 	 	 	 	 	 	 	 	 	 	 dCd%Z4dDd&Z5dEd'Z6dFd(Z7dGd)Z8dHd*Z9dId+Z:	 	 	 	 	 	 	 	 	 	 	 	 	 	 dJd,Z;dKd-Z<dLdMd.Z=dNd/Z>dNd0Z?dOd1Z@dPd2ZAeBd3k(  r eA        yy)QzISummarize the address-adjacent selector root before the current 2:0 root.    )annotationsN)Path)Any)read_sections)handler_for_opcode   outmap1_01amap2_02dz0:0z1:0z2:0i(T i)T i*T i*T i+T iD+T i+T c                    d| dS )N0x08x values    P/home/exedev/hwanse/tools/summarize_save_selector_address_predecessor_context.pyhex32r   #       c{    c                    d| dS )Nr   02xr   r   s    r   hex8r   '   r   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#   +   s*    ;;=::dnngn677r   c                L    | j                  d       d| j                  d       S )Ngroup:slotget)rows    r   selector_keyr+   1   s&    gggq 122r   c                R    | D ]  }t        |      |k(  s|c S  t        d| d      )Nz	selector z
 not found)r+   
ValueError)	selectorskeyr*   s      r   find_selectorr0   5   s9     #J yZ0
11r   c                "    | rt        | d      S d S )N   intr   s    r   	parse_hexr5   <   s    "3ub>,,r   c                    | D ]E  }t        |d         }|t        |d         z   }||cxk  r|k  s.n 1t        |d         ||z
  z   c S  y )Nvaraw_sizerawr3   sectionsr7   sectionstartends        r   va_to_offsetr?   @   s]     6GDM"c'*-..Bwu~&"u*55	6
 r   c                    | D ]O  }t        |d         }|t        |d         z   }||cxk  r|k  s.n 1t        |j                  d      xs d      c S  y )Nr7   r8   name )r4   strr)   r:   s        r   section_for_varD   I   s^     2GDM"c'*-..Bw{{6*0b11	2
 r   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   <Ir   )r?   lenstructunpack_from)exer;   r7   offsets       r   dword_atrM   R   s?    (B'F~!c#h.dC033r   c                    | D ch c]3  }|j                  d      r |j                  d      rt        |d   d      5 }}t        |      S c c}w )N	fieldMapsselectedPointerHexr2   )r)   r4   sorted)r.   r*   rootss      r   unique_rootsrS   Y   sW     77;CGG,@$A 	C$%r*E 
 %=s   8A
c                f    | D cg c]!  }t        |j                  d            |k(  r|# c}S c c}w )NrP   )r5   r)   )r.   root_var*   s      r   selectors_for_rootrV   b   s9     SWW123w> 	  s   &.c                x    t        |       }|j                  |      }|dz   t        |      k  r||dz      nd }||fS )Nr   )rS   indexrH   )r.   rU   rR   rX   r>   s        r   
root_rangerY   i   sC    #EKK E#ai#e*4%	
$CC<r   c           	     R   |g S t        ||      }t        ||      }||||k  rg S | || }t        j                  d|      }g }	d}
	 |j                  ||
      }|dk  r	 |	S ||z   }|	j	                  t        |      t        |      t        ||      |t        |      d       |dz   }
a)NrG   r   )refVaHextargetVaHexr<   offsetFromRangeStartoffsetFromRangeStartHexr   )r?   rI   packfindappendr   rD   hex)rK   r;   start_vaend_va	target_vastart_offset
end_offsetdatapatternrefscursorrX   ref_vas                r   dword_refs_in_rangerm   p   s     ~	(3Lh/Jz1Z<5O	|J'Dkk$	*GDF
		'6*19 K E!f +%h7$)'*5z
 	  r   c           	        |j                  d      }|j                  d      }g }| D ]W  }d}|j                  d      |k(  rd}|j                  i |||j                  d      |k(  |j                  d      |k(  d       Y |S )NselectedPointerVaHexrowPointerHexzdata-referencer[   z(current-selector-row-selected-root-entry)role"isCurrentSelectorSelectedRootEntryisCurrentSelectorRowPointer)r)   ra   )rj   current_selectorselected_entry_hexrow_pointer_hex	annotatedrefrq   s          r   #annotate_current_selector_ref_rolesry      s    )--.DE&**?;OI 	77:"44=D 

25''*2EI[2[+.77:+>/+Q	
 			 r   c                `   t        ||      }|g S | |||z    }g }d}|t        |      k  r|j                  d|      }	|	dk  rnh|||	 }
t        |
      dk\  rAt        d |
D              r/|j	                  t        ||z         |
j                  d      d       |	dz   }|t        |      k  r|d | S )Nr       rF   c              3  <   K   | ]  }d |cxk  xr dk  nc   yw)       Nr   ).0bytes     r   	<genexpr>z1printable_string_entries_after.<locals>.<genexpr>   s      Bdt!1c!1!1 Bs   ascii)vaHextextr   )r?   rH   r`   allra   r   decode)rK   r;   r7   limitmax_stringsrL   chunkentriesrk   r>   r9   s              r   printable_string_entries_afterr      s     (B'F~	v~&EGF
3u:
jj&)7F3s8q=S Bc BBNNrF{+

7+  q 3u:
 <K  r   c                L    t        | ||||      D cg c]  }|d   	 c}S c c}w )Nr   )r   )rK   r;   r7   r   r   r*   s         r   printable_strings_afterr      s5     2#xUKX 	F  s   !c                r    |xs i j                  d      xs g D ]  }|j                  d      | k(  s|c S  i S )NrR   rootHexr(   )root_hexsecondary_fill_rootsr*   s      r   fill_root_forr      sC    $*//8>B 779)J Ir   c                    |dz  }t        d      D ]  }|r|dz
  nd}| |   s n t        d      D ]  }|dz   dk\  rdn|dz   }| |   s |S  |S )N      r      r   )range)tabler=   r'   _s       r   simulate_opcode12_selected_slotr      sv    4<D2Y taxT; 2Y 1H$q$(;K	 Kr   c                    | j                  d      dk7  ry 	 t        t        | j                  d            d      }d|cxk  rdk  sy  y t	        d      D cg c]  }||k  rdnd c}S # t        $ r Y y w xY wc c}w )NhelperArgumentHex0x00streamPlus1Hexr2   r   r   r   )r)   r4   rC   r-   r   )fillcountrX   s      r   secondary_table_for_fillr      s    xx#$.C!123R8  389=%AA%==	   >s   $A) A8)	A54A5c           	        | s
g d d d d dg dS | d   }t        |      }g }|;t        d      D ]-  }t        ||      }|j                  ||||   ||   dk(  d       / t	        | D ch c]%  }|j                  d      s|j                  d      ' c}      |j                  d      |j                  d      |j                  d	      |t        |      xr t        d
 |D              |dS c c}w )NF)uniqueFillValueHexeslastFillValueHexlastFillHelperArgumentHexlastFillStreamPlus1Hex!secondaryBranchStateAfterLastFill"lastFillAllStartsPassCurrentReaderoutcomesr   r   )	startSlotselectedSlotselectedValuefrontierReaderFallsThroughvalueHexr   r   c              3  &   K   | ]	  }|d      yw)r   Nr   r   r*   s     r   r   zfill_effect.<locals>.<genexpr>  s      E
25C,-E
   )r   r   r   ra   rQ   r)   boolr   )fills	last_fillr   r   r=   selectedr   s          r   fill_effectr      s   $& $)-&*1527
 	
 b	I$Y/EH2Y 	E6ueDHOO" (!&x.3Ho.B	 	 !''gRVRZRZ[eRf(<'g h%MM*5%.]]3F%G"+--0@"A-2.28n /
 E
9AE
 B
 
 
'gs   %C(<C(c                    | dz  dk7  ry | dz	  dz  }| dz	  dz  }| dz	  dz  }|dk(  rdnd}|dk  }|d	k  }t        |      t        |      t        |      ||||dk(  xr |xr |d
S )Nr   r2         r   primaryBranchStatesecondaryBranchStater      )r   r   streamPlus3Hex
stateTablehelperDispatchValidscriptShapedvalidSecondaryFill)r   )r   stream_plus_1
helper_argstream_plus_3state_tablehelper_validscript_shapeds          r   decode_op10r     s    aZ4'M2+%Jb[D(M*71*<&BXK%L!T)M}-!*-}-!+%)-CCffYf r   c                   | |k(  ry| t         k(  ry| t        k(  ry| t        k(  ry| t        k(  ryt        | cxk  r	t
        k  ry ||| cxk  r|k  sy  y | t        k  ryt        | cxk  r	t         k  ry t         | cxk  r|k  ry	 y
y
)Ncurrent-root-exactfrontier-readerzfrontier-leafsource-recordtarget-recordleaf-table-windowzcurrent-root-before-writerzwriter-to-reader-windowzpost-reader-current-rootzcurrent-root-other)FRONTIER_READERFRONTIER_LEAFSOURCE_RECORDTARGET_RECORDLEAF_TABLE_STARTLEAF_TABLE_ENDCURRENT_WRITER)r   current_rootcurrent_ends      r   classify_current_root_pointerr   "  s    # 51>1" 2,%"E+"E #F~+00( 1,,) -r   c                   ||||k\  r;i 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i g g dS i }d}d}d}	d}
i }d}d}d}d}d}d}d}d}d}d}g }t        ||d      D ]  }t        | ||      }||dz  }t        |      }|j                  |d      dz   ||<   t	        | ||      }|j                  d      dk(  r|dz  }|j                  d      r|dz  }t        ||      }|r%|dz  }|dk(  r|dz  }n|dk(  r|	dz  }	n
|dk(  r|
dz  }
t        |||      }|rS|dz  }|j                  |d      dz   ||<   |dk(  r|dz  }n+|dk(  r|dz  }n |dk(  r|dz  }n|d k(  r|dz  }n
|d!k(  r|dz  }t        |      }|r|dz  }|d"   r|dz  }|s|j                  d      dk(  s|sCt        |      d#k  sS|j                  t        |      t        |      ||j                  d$      |j                  d      |||d%        t        d||z
  dz        }t        |j                         d& '      d d( D  cg c]
  \  } }| |d) }!} }|d*k\  xr( |d+k\  xr! |dk(  xr |dk(  xr |dk(  xr |dk(  xr |dkD  }"i dt        |       d,t        |       d|d|d|d|	d|
d|d	|d
|d|d|d|d|d|d|d|d|"t        t        |j                                     |!|dS c c}} w )-NrangeHex
dwordCountr   pointerDwordCountdataPointerDwordCounttextPointerDwordCountrelocPointerDwordCountcurrentRootRangePointerCountcurrentRootExactRefCountfrontierReaderRefCountsourceRecordRefCounttargetRecordRefCountleafTableWindowPointerCountdataHandlerLowByteCountdefaultHandlerLowByteCountopcode10LowByteCountvalidSecondaryFillCountlooksLikeDescriptorDataF)currentRootPointerClasseslowOpcodeTopsamplesrF   r   r   handlerSectionz.dataisDefaultHandlerz.textz.relocr   r   r   r   r   r   r}   handlerVaHex)r   r   lowOpcodeHexr   r   pointerSectioncurrentRootPointerClassop10c                    | d    | d   fS )Nr   r   r   )items    r   <lambda>z.tail_after_last_fill_summary.<locals>.<lambda>  s    tTUwhX\]^X_M` r   )r/   r   )r   r   2   
   ..)r   rM   r   r)   r   rD   r   r   rH   ra   r   maxrQ   itemsdict)#rK   r;   
tail_starttail_endr   r   low_opcode_countspointer_countdata_pointer_counttext_pointer_countreloc_pointer_countcurrent_root_pointer_classescurrent_root_pointer_countexact_current_root_countfrontier_reader_countsource_record_counttarget_record_countleaf_table_countdata_handler_countdefault_handler_countopcode10_countvalid_secondary_countr   r7   r   opcode
opcode_hexhandlerpointer_sectiontarget_classr   dword_countr/   low_opcode_toplooks_like_descriptor_datas#                                      r   tail_after_last_fill_summaryr  :  s^    X-x1G

!
  
 $Q	

 $Q
 %a
 +A
 '
 %a
 #A
 #A
 *1
 &q
 )!
 #A
  &q!
" &u#
$ *,)
 	
, )+M35 !" NGJ!, 3h+=&\
(9(=(=j!(Lq(P*%$S(F;;;'(G3!#;;)*!Q&!(59QM')"a'" G+"a'" H,#q(#4UL+V&!+&9U9Y9YZfhi9jmn9n(633(A-(!22%*%0#q(#0#q(#!44 A% 5!aN()%*%7;;'78GCt7|b "2Y %e$.$+KK$?&-kk2B&C&5/; 	  	U3h a(Z/A56K !!2!8!8!:@`abecefC u-N 
 	 	#&",	#$)	# "Q&	#  1$		#
  1$	# " uZ()E(O+<=k 	] 	 !3	
 	 !3 	!"5 	'(B 	#$< 	!"7 	 3 	 3 	&'7 	"#5 	%&; 	  	"#8!" 	"#=#$ &*&1M1S1S1U*V%W&) s   K;c                   t        | |      }|r|d   ni }|j                  d      xs g }t        t        |      |      }|j                  d      xs g }|r|d   ni }	t	        |      }
t        |	j                  d            }|D cg c]  }t        |       c}t        |      t        |       d|t        |      nd |t        |v t        |v |j                  dd      |r|d   xs i j                  d      nd |	j                  d      |&|$|d	z   |k  rt        |d	z          dt        |       nd |rd
nd d|
S c c}w )Nr   rO   r   r   r   r   ?	fillCountrF   F)r.   r   r   rO   containsSourcecontainsTargetr  firstFillHexlastFillHextailRangeAfterLastFillHex&tailHasKnownSecondaryFillAfterLastFill)	rV   r)   r   r   r   r5   r+   SOURCETARGET)r.   rU   root_end_var   rowsfirst
field_maps	fill_rootr   r   effectlast_fill_var*   s                r   root_recordr,    s[   i1DDGE;'-2JeGn.BCIMM'"(bE"b	IFY]]734L378Cl3'8>W~&b{?V{);\_(`a J. J.]];29>qR,,W5D }}W- 'K,CWXHX\gHg \A%&'r%*<)=>;@%d  ! 8s   D?c           
     
   t        |       }t        |t              }t        |t              }t        |t              }t        |d   d      }t        |      }|j                  |      }	||	dz
     }
|	dz   t        |      k  r||	dz      nd }t        ||
      \  }}t        ||      \  }}|t        ||t        ||      d   |      ni }t        |j                  d      xs g       }t        |j                  d      xs g       }t        ||
      }|r|d   ni }t        |j                  d      xs g       }t        |j                  d      xs g       }t        t        | ||||      |      }t        | ||||
      }|r t!        | |t        |d   d   d      dz         ng }|D cg c]  }|d   	 }}|rt#        |      nd }t        ||
||      }t        ||||      }t%        |j                  d	            }t'        | |||dz   nd |||      } d
}!d
}"t)        d |D              rdn|rt)        d |D              rdn|rdnd}#d}$dj+                  g dt         d| dt-        |
       dt-        |       d|j                  d       d| dt         dt.         dt0         d|j                  d       dd j+                  |      xs d! d"| d#    d$| d%    d&| d'    d&| d(    d&| d)    d*t         d+t0         d,t.         d-      }%i d.t0        d/t.        d0t        d1t        d2t        d3|j                  d      d4|j                  d      d5|j                  d      d6|j                  d7      d8|j                  d9      d:|j                  d      d;|d<t-        |
      d=t-        |       d>|t-        |      nd? d@|t-        |      nd dA|j                  d      xs g dB|j                  d      xs g i dC|j                  d      xs g dD|j                  d      xs g dEt0        |v dFt.        |v dG||k(  dH||k(  dI||t0        hz  k(  dJt3        ||z
        dKt        |      dL|dMt)        dN |D              dOt        |      dP|dQ|#dR|dS|dT|i dU|dV|dW| dX| dY   dZ| d[   d\| d#   d]| d%   d^| d'   d_| d(   d`| d)   da| db   dc| dd   de| df   dg| dh   di|j                  dj      dk|j                  dl      dm|j                  dj      dnu xr |" |!|"d
d
|$do| dpt         dqdrg|%dsS c c}w )tNrP   r2   r   rO   r   r[   rF   r   r   Fc              3  >   K   | ]  }|j                  d         ywrr   Nr(   r   s     r   r   z build_summary.<locals>.<genexpr>!  s     asww;<a   z-current-selector-row-entry-with-resource-listc              3  d   K   | ](  }|j                  d       xs |j                  d       * yw)z.cnsz.mlkN)endswithr   r   s     r   r   z build_summary.<locals>.<genexpr>$  s+     $rX\T]]6%:%SdmmF>S%S$rs   .0zresource-list-pointer-contextzunclassified-data-referencemissingblockedrB   z4The address-adjacent field-map root before selector z is z at z&. It ends exactly at the current root z	 and has r  z secondaryBranchState fill-shaped rows. Its last known fill would satisfy the current reader for every start slot if that root executed immediately before the current root and the state persisted. However it is selector z$, not the logical previous selector z; it contains z	 but not z]; and its direct current-root dword hit is the current selector's own selected-root entry at ro   z, followed by resource strings , nonez$. After the last fill, the tail has r   zq current-root-range pointers, but exact current-root, frontier-reader, source-record, and target-record refs are r   /r   r   r   z. Address adjacency, tail pointer density, a passing fill effect, and this selector-row metadata still do not prove that normal gameplay executes this root before the z frontier reader or that z->z has a strict source hotspot.sourcetargetsourceSelectorlogicalPredecessorSelectorcurrentSelectorsourceRootHexlogicalPredecessorRootHexcurrentRootHex&currentSelectorRowPointerTableEntryHexrowPointerVaHexcurrentSelectorRowPointerHexrp   #currentSelectorSelectedRootEntryHexaddressPredecessorSelectoraddressPredecessorRootHexaddressPredecessorRangeHexr   r  addressSuccessorRootHex
sourceMapslogicalPredecessorMapsaddressPredecessorMapscurrentMaps addressPredecessorContainsSource addressPredecessorContainsTarget0addressPredecessorEqualsLogicalPredecessorMapSet%addressPredecessorEqualsCurrentMapSet)currentEqualsAddressPredecessorPlusSource'sourceSelectorExtraMapsOmittedByCurrent'addressPredecessorToCurrentRootRefCount#addressPredecessorToCurrentRootRefs;addressPredecessorToCurrentRootRefIsCurrentSelectorRowEntryc              3  >   K   | ]  }|j                  d         ywr/  r(   r   s     r   r   z build_summary.<locals>.<genexpr>Y  s!      K
>ACGG89K
r0  'currentToAddressPredecessorRootRefCount#currentToAddressPredecessorRootRefs.addressPredecessorCurrentRootRefClassification0addressPredecessorCurrentRootRefFollowingStrings6addressPredecessorCurrentRootRefFollowingStringEntriesaddressPredecessorRootcurrentRootaddressSuccessorRoot#addressPredecessorTailAfterLastFill addressPredecessorTailDwordCountr   'addressPredecessorTailPointerDwordCountr   2addressPredecessorTailCurrentRootRangePointerCount.addressPredecessorTailCurrentRootExactRefCount,addressPredecessorTailFrontierReaderRefCount*addressPredecessorTailSourceRecordRefCount*addressPredecessorTailTargetRecordRefCount1addressPredecessorTailLeafTableWindowPointerCountr   -addressPredecessorTailDataHandlerLowByteCountr   -addressPredecessorTailValidSecondaryFillCountr   -addressPredecessorTailLooksLikeDescriptorDatar   4addressPredecessorLastFillAllStartsPassCurrentReaderr   8addressPredecessorTailHasKnownSecondaryFillAfterLastFillr"  3addressPredecessorPassingFillStillNotExecutionProofTz$prove whether address-adjacent root z executes before selector zptrace the selector loader or selected-pointer runtime state instead of treating 0x0053f328 metadata as executionzKcapture real selector 2:0 savedata or find a strict map1_01a source hotspot)#selectorIndexOrderSupportsExecution addressContiguityProvesExecutionexecutionOrderProvenstrictHotspotFoundpromotionStatusremainingProofs
conclusion)r   r0   CURRENT_SELECTORSOURCE_SELECTORLOGICAL_PREDECESSOR_SELECTORr4   rS   rX   rH   rY   r,  setr)   rV   ry   rm   r   r+   r5   r  anyjoinr   r$  r#  rQ   )&rK   r.   r   r;   current_row
source_rowlogical_predecessor_rowr   rR   
root_indexaddress_predecessor_rootaddress_successor_rootprevious_startprevious_endcurrent_startr   successor_recordsource_mapslogical_predecessor_mapsaddress_predecessor_rowsaddress_predecessor_rowaddress_predecessor_mapscurrent_mapsprevious_to_current_refscurrent_to_previous_refsfollowing_string_entriesr*   following_stringsaddress_predecessor_selectoraddress_predecessor_root_recordcurrent_root_recordr+  address_predecessor_tail'selector_index_order_supports_execution#address_contiguity_proves_executiondword_ref_classificationpromotion_statusrt  s&                                         r   build_summaryr    s	   S!H	+;<Ky/:J+I7ST{#78"=L#E\*J$Z!^46@1ns5z6QU:>2W[#-i9Q#R NL!+I|!DM; "- 	I5z)Mc7def7gi}~ 
 jnn[17R8K"#:#>#>{#K#QrR1)=UV=U6q9[]"#:#>#>{#K#QrR{{39r:LBCVD    3   $ 	'sHc:RST:UV`:ace6fij6jk 
 1IIVIILc<0G#Him &1 	'# &i{L`a<@@OPL;(4q$  /4+*/' aH`aa 	8 $r`q$r!r 	( $ +  !	j 	j
> 	j?O>P 	jPT 	j'
(	j(,	j-23K-L,M	jMs	j
	j(	j)H)L)L[)Y(Z	j[	j
 11	j
 2V	j
 WsUs	j
t	j h	j (	j )/x	j0"	j #.//2H"I!J	j Kj	j 99&'16
2	j3-	j .FFd-e,f	jgh	j $$>?
@	j AB	j $$<=
>	j ?@	j $$:;
<	j =>	j $$:;
<	j=	j    !	j  !:!	j  ;A!	j  BD!	j  EK8!	j  Li!	j &L&L&L 	/L 	%&B	L
 	+L 	(<=L 	$%<%@%@AU%VL 	+//*>?L 	1+//BS2TL 	'(HL 	.{?U/VL 	%&BL 	$U+C%DL 	%~)>(?rYeYq%BUwzA{&|L 	"DZDf5)?#@lpL  	jnn[17R!L" 	!"9"="=k"J"Pb#L$ 	!"9"="=k"J"Pb%L& 	{{39r'L( 	+F6N,N)L* 	+F6N,N+L, 	;<TXp<p-L. 	01I\1Y/L0 	4\F^bhaiFi5j1L2 	26+:T3U3L4 	237O3P5L6 	./G7L8 	Fs K
E]K
 H
9L> 	237O3P?L@ 	./GALB 	9:RCLD 	;<MELF 	ABZGLH 	!"AILJ 	*KLL 	 0MLN 	./GOLP 	+,D\,RQLR 	23KL_3`SLT 	=>V*?
ULZ 	9:RSm:n[L\ 	78PQi8j]L^ 	56NOe6f_L` 	56NOe6faLb 	<=U)>
cLh 	89QRk9liLj 	89QRk9lkLl 	89QRk9lmLn 	?@_@c@c0A
oLt 	CDcDgDg4E
uLz 	>+//0TUY]] 877LB 0W,O %#+23O2PPjk{j|}~Y

 !WL Le Js   $U%c                
   g 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    d| d    d| d     dd!| d"    dd#| d$    d%| d&    dd'| d(    d)| d*    d+| d,    d-| d.    d/| d0    d1| d2    d3| d4    d5| d6    d7| d8    d9| d:    d;| d<    d=| d>    dd| d?   dd@ddAdB}dC| dD   fdE| dF   fdG| dH   ffD ]  \  }}|s	|j                  dI| dJdKj                  dL |j                  dM      xs g D               dN|j                  dO       dP|j                  dQ       dJ|j                  dR       dJ|j                  dS       dN|j                  dT      xs dU dV|j                  dW      xs dU dV|j                  dX      xs dU dP|j                  dY       dN|j                  dZ      xs dU d[        |j                  g d\       | d]   }|r|j                  d^ |D               n|j                  d_       |j                  d       |j                  d`dKj                  da | db   D              xs dUz          | dc   }|j                  ddddde|j                  dO       ddf|j                  dg       dh|j                  di       dj|j                  dk       dl|j                  dm       dn|j                  do       dp	dq|j                  dr       ds|j                  dt       d5|j                  du       d5|j                  dv       d5|j                  dw       dx|j                  dy       dz|j                  d{       d||j                  d}       d7|j                  d~       dddKj                  d |j                  d      xs i j	                         D              xs dUz   dddg       |j                  d      xs g D ]  }|j                  d|j                  d       dV|j                  d       dV|j                  d       dV|j                  d      xs dU d|j                  d      xs dU dJ|j                  d      xs dU dJ|j                  d      xs dU dJ|j                  d      r$|j                  d      xs i j                  d      ndU d        |j                  g d       |j                  d | d   D               |j                  d       dj                  |      S )Nz+# Save Selector Address Predecessor ContextrB   z
- route: `r9  z -> r:  `z- source selector: `r;  z` root `r>  z- logical predecessor: `r<  r?  z- address predecessor: `rE  rF  z	` range `rG  z- current selector: `r=  r@  z:- address predecessor equals logical predecessor map set: rO  z2- current equals address predecessor plus source: rQ  z,- address predecessor -> current root refs: rS  z2- current-root ref is current selector row entry: rU  z!- current selector row pointer: `rC  z)- current selector selected-root entry: `rD  z,- current -> address predecessor root refs: rW  z$- current-root ref classification: `rY  z#- last fill passes current reader: rk  z1- tail has known secondary fill after last fill: rl  z*- passing fill still not execution proof: rm  z$- tail current-root-range pointers: rb  z - tail exact current-root refs: rc  z- tail frontier-reader refs: rd  z"- tail source/target record refs: re  r8  rf  z- tail descriptor-like data: rj  z'- address contiguity proves execution: ro  z- execution order proven: rp  z- promotion status: `rr  rt  z## Root Summaryz| role | selectors | range | contains source | contains target | fills | first fill | last fill | last fill value | all-starts pass | tail after last fill |zD| --- | --- | --- | --- | --- | ---: | --- | --- | --- | --- | --- |address predecessorr\  currentr]  address successorr^  z| z | r6  c              3  (   K   | ]
  }d | d   ywr  Nr   r3  s     r   r   zmarkdown.<locals>.<genexpr>  s     #WDavQK#W   r.   z | `r   z` | r  r  r  r  -z` | `r   r   r   r!  z` |)rB   z## Direct RefsrB   rT  c              3  v   K   | ]1  }d |d    d|d    d|d    d|d    d|j                  d	       d
 3 yw)z- `r[   z` -> `r\   z` section `r<   z
` offset `r^   z` role `rq   r  Nr(   r   s     r   r   zmarkdown.<locals>.<genexpr>  s      
 #j/"&]);(<KIGWWabef  cA  bB  BJ  KN  KR  KR  SY  KZ  J[  [\  ]
s   79z- nonez- following strings: c              3  (   K   | ]
  }d | d   ywr  r   r3  s     r   r   zmarkdown.<locals>.<genexpr>  s     iTqa[ir  rZ  r_  z## Tail After Last Fillz
- range: `z
- dwords: r   z- pointer dwords: r    (data r   , text r   , reloc r   )z- current-root-range pointers: r   zM- exact current-root / frontier-reader / source-record / target-record refs: r   r   r   r   z- leaf-table window pointers: r   z- data-handler low-byte rows: r   z)- valid secondary fills after last fill: r   r   zcurrent-root pointer classes: c              3  0   K   | ]  \  }}| d |   ywr&   Nr   r   r/   r   s      r   r   zmarkdown.<locals>.<genexpr>  s     n*#uuAeW%n   r   zc| va | value | low opcode | handler | pointer section | current-root class | valid secondary fill |z+| --- | --- | --- | --- | --- | --- | --- |r   z| `r   r   r   r   z` r   r   r   r   r   z |)rB   z## Remaining ProofsrB   c              3  &   K   | ]	  }d |   yw)z- Nr   r3  s     r   r   zmarkdown.<locals>.<genexpr>  s     D2dVDr   rs  
)ra   rz  r)   extendr   )summarylinesrq   r*   rj   tails         r   markdownr    s   "5"
" WX&'tGH,=+>a@" w'789'/BZA[[\]	"
 #7+G#H"IRYZuRvQwwxy" #7+G#H"IRYZuRvQw  xA  BI  Jf  Bg  Ah  hi  	j"  (9 :;8GL\D]C^^_`" EWM  FA  EB  	C" =WEp=q<rs" 7w?h7i6jk" =W  FC  >D  =E  	F" ,G4R,S+TTUV" 4G<a4b3ccde" 7w?h7i6jk" /w7g/h.iijk"  .g6l.m-no!"" <GD~<  <A  	B#"$ 5W=r5s4tu%"& /w7k/l.mn'"( +73c+d*ef)"* (0^(_'`a+", -W5a-b,ccdel  nZ  f[  e\  	]-". (0_(`'ab/"0 2':\2]1^_1"2 %W-C%D$EF3"4  (9 :;1=5"6 	7"8 	9": 	;"< 	="> 	?"@ 	gA"B 	OC"EH 
(@ AB	GM*+	g&<=> 
	c
 c$))#WCGGK<P<VTV#WWX Y
#$D1A)B(C3swwO_G`Faadww{#$D)@)GC(HcggVcNdNkhkMl m*+2s34@d8e7f g34;<C	A	

 
LL+,89D 

 	

 	X	LL	LL99iW5g-hiipmp	r 89D	LL
!

TXXj)*!,
TXXl+,-
TXX&9:;7488LcCdBeelmqmumu  wN  nO  mP  PX  Y]  Ya  Ya  bz  Y{  X|  |}  	~
)$((3Q*R)ST
WX\X`X`a{X|W}}~  @D  @H  @H  Ia  @b  c  cd  ei  em  em  nD  eE  dF  FG  HL  HP  HP  Qg  Hh  Gi  	j
(2O)P(QR
(2K)L(MN
3DHH=V4W3XY
'1J(K'LM
(99nB]9^9dbd8k8k8mnnuru	w
m5% ( xx	"(b 
#'''"#5)<(=U377>CZB[ \'.3/r#'':J2K2Rs1SSVww'(/C0CGG<U4V4]Z]3^^aDGGGFO%2**+?@Y\]]_a	

 
LL01	LLD1B)CDD	LL99Ur   c                X   g }d| d   fd| d   fd| d   ffD ]~  \  }}|s
|j                  dt        j                  |       dt        j                  d	j                  |j	                  d
      xs g              dt        j                  |j	                  d      xs d       d|j	                  d       d|j	                  d       d|j	                  d       dt        j                  |j	                  d      xs d       dt        j                  |j	                  d      xs d       dt        j                  |j	                  d      xs d       d|j	                  d       dt        j                  |j	                  d      xs d       d        | d   D cg c]  }dt        j                  |d          dt        j                  |d          dt        j                  t        |d                dt        j                  |d          dt        j                  t        |j	                  d       xs d             d! }}| d"   }|j	                  d#      xs g D cg c]y  }dt        j                  |j	                  d$      xs d       dt        j                  |j	                  d%      xs d       dt        j                  |j	                  d&      xs d       dt        j                  |j	                  d'      xs d       d(t        j                  |j	                  d)      xs d       dt        j                  |j	                  d*      xs d       dt        j                  |j	                  d+      xs d       dt        j                  t        |j	                  d,      r$|j	                  d,      xs i j	                  d-      nd             d!| }}dj                  d. | d/   D              }d0j                  g d1d2d3d4d5d6d7d8d9d:d;t        j                  | d<          d=t        j                  | d>          d?| d@    dA| dB    dC| dD    dE| dF    dGdH| dI    dJ| dK    dL| dM    dN| dO    dP| dQ    dR| dS    dTt        j                  | dU          dV| dW    dX| dY    dZd[| d\    d]| d^    d_| d`    dZda| db    dc| dd    de| df    dg| dh    di| dj    dk| dl    dZdmt        j                  | dn          dodpdq|drdsdt|xs dugdrdvt        j                  d	j                  | dw         xs d       dodxdj                  g dyt        j                  |j	                  d      xs d       dz|j	                  d{       d||j	                  d}       d~|j	                  d       d|j	                  d       d|j	                  d       d|j	                  d       d|j	                  d       di|j	                  d       di|j	                  d       di|j	                  d       d|j	                  d       d|j	                  d       d|j	                  d       dk|j	                  d       dZ      dt        j                  d	j                  d |j	                  d      xs i j                         D              xs d       dod|xs dgdrdd| dddd      S c c}w c c}w )Nr  r\  r  r]  r  r^  z<tr><td>z	</td><td>r6  r.   z</td><td><code>r   rB   z</code></td><td>r  r  r  r  r  z</code></td><td><code>r   r   r   r!  z</code></td></tr>rT  z<tr><td><code>r[   r\   r<   r^   rq   z
</td></tr>r_  r   r   r   r   r   z</code> r   r   r   r   r   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>N)htmlescaper3  s     r   r   zhtml_page.<locals>.<genexpr>  s#     \tDKK-.e4\s   #%rs  r  z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">zF  <meta name="viewport" content="width=device-width, initial-scale=1">z:  <title>Save Selector Address Predecessor Context</title>a    <style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;margin:24px}table{border-collapse:collapse;width:100%;max-width:1180px}td,th{border:1px solid #333;padding:6px 8px;text-align:left;vertical-align:top}th{background:#1f1f1f}code{color:#9bd4ff}</style>z</head>z<body>z4  <h1>Save Selector Address Predecessor Context</h1>z  <p>route <code>r9  z -&gt; r:  z#</code>; logical predecessor <code>r<  z#</code>; address predecessor <code>rE  z</code>; current <code>r=  z </code>; promotion status <code>rr  z</code>.</p>z=  <p>address predecessor equals logical predecessor map set: rO  z2; current equals address predecessor plus source: rQ  z/; address predecessor -&gt; current root refs: rS  z2; current-root ref is current selector row entry: rU  z&; current selector row pointer: <code>rC  z5</code>; current selector selected-root entry: <code>rD  z*</code>; current-root ref classification: rY  z'; address contiguity proves execution: ro  z; execution order proven: rp  z.</p>z&  <p>last fill passes current reader: rk  z1; tail has known secondary fill after last fill: rl  z*; passing fill still not execution proof: rm  z'  <p>tail current-root-range pointers: rb  z; exact current-root refs: rc  z; frontier-reader refs: rd  z; source/target record refs: re  r8  rf  z; tail descriptor-like data: rj  z  <p>rt  z</p>z  <h2>Root Summary</h2>z  <table><thead><tr><th>role</th><th>selectors</th><th>range</th><th>source</th><th>target</th><th>fills</th><th>first fill</th><th>last fill</th><th>last fill value</th><th>all-starts pass</th><th>tail after last fill</th></tr></thead><tbody>z  </tbody></table>z  <h2>Direct Refs</h2>zo  <table><thead><tr><th>ref</th><th>target</th><th>section</th><th>offset</th><th>role</th></tr></thead><tbody>z"<tr><td colspan="5">none</td></tr>z  <p>following strings: rZ  z  <h2>Tail After Last Fill</h2>z  <p>range <code>z</code>; dwords: r   z; pointer dwords: r   r  r   r  r   r  r   z ); current-root-range pointers: r   zG; exact current-root/frontier-reader/source-record/target-record refs: r   r   r   r   z; leaf-table window pointers: r   z; data-handler low-byte rows: r   z; valid secondary fills: r   r   z#  <p>current-root pointer classes: c              3  0   K   | ]  \  }}| d |   ywr  r   r  s      r   r   zhtml_page.<locals>.<genexpr>9  s*       D^YcY\^cse1UGDT  D^r  r   z  <table><thead><tr><th>va</th><th>value</th><th>low opcode</th><th>handler</th><th>pointer section</th><th>current-root class</th><th>valid secondary fill</th></tr></thead><tbody>z"<tr><td colspan="7">none</td></tr>z  <h2>Remaining Proofs</h2>z  <ul>z</ul>z</body>z</html>)ra   r  r  rz  r)   rC   r   )r  	root_rowsrq   r*   ref_rowsr  	tail_rowsproofss           r   	html_pager    s   I	(@ AB	GM*+	g&<=> 
	c
 ;;t$% &;;tyy)=)CDEF GSWWZ%8%>B?@ A77+,- .77+,- .77;'( )SWW^%<%CDE FSWW]%;%BsCD ESWW-?%@%GCHI J77?@A BSWW-H%I%PSQR S	

< @A	 	[[Z12 3[[]!345 6{{3s9~./0 1[[%>!?@A B{{3swwv4"567 8		H 	 89D 88I&," 	[[!1!7R89 :[[!4!:;< =[[!8!>B?@ A[[!8!?C@A$++VYV]V]^nVoVvsvJwIx y{{377#34;<= >{{377#<=DEF G{{3TWT[T[\bTc 52::;OPilmno p	I  WW\IZA[\\F99 $$$ 	$ 	#	$
 	Q$ 	E$ 	\$ 	$ 	$ 	?$ DKK(9:;74;;wW_O`CaBb  cF  GN  Ok  Gl  Fm  mP  QX  Yu  Qv  Pw  wN  OV  Wh  Oi  Nj  jJ  KR  Sd  Ke  Jf  fr  	s$ H  QC  ID  HE  Ew  x  @k  xl  wm  m\  ]d  eN  ]O  \P  PB  CJ  KH  CI  BJ  Jp  qx  yW  qX  pY  YN	  O	V	  W	|	  O	}	  N	~	  ~	h
  i
m
  i
t
  i
t
  u
|
  }
m  u
n  i
o  h
p  pW  X_  `B  XC  WD  D^  _f  g}  _~  ^  D  	E$ 19o1p0q  rc  dk  lf  dg  ch  hR  SZ  [P  SQ  RR  RW  	X$ 2':n2o1p  qL  MT  UE  MF  LG  G_  `g  hV  `W  _X  Xu  v}  ~j  vk  ul  lm  nu  vb  nc  md  dA  BI  Jy  Bz  A{  {@  	A$ GL12348$  	"!$" 	~#$$ 
%$& 	'$( 	!)$* 	z+$, 
>=>-$. 	/$0 #4;;tyyAs9t/u/|y|#}"~  C  	D1$2 	*3$4 	R  	R
  	RDKK(<(CDE  	REV  	RW[W_W_`lWmVn  	R  oA  	R  BF  BJ  BJ  K^  B_  A`  	R  `g  	R  hl  hp  hp  qH  hI  gJ  	R  JQ  	R  RV  RZ  RZ  [r  Rs  Qt  	R  t|  	R  }A  }E  }E  F^  }_  |`  	R  `@  	R  AE  AI  AI  Jh  Ai  @j  	R  jq  	R  rv  rz  rz  {U  rV  qW  	R  WX  	R  Y]  Ya  Ya  bz  Y{  X|  	R  |}  	R  ~B  ~F  ~F  G]  ~^  }_  	R  _`  	R  ae  ai  ai  j@	  aA	  `B	  	R  B	`	  	R  a	e	  a	i	  a	i	  j	G
  a	H
  `	I
  	R  I
g
  	R  h
l
  h
p
  h
p
  q
J  h
K  g
L  	R  Le  	R  fj  fn  fn  oH  fI  eJ  	R  Jg  	R  hl  hp  hp  qJ  hK  gL  	R  LQ  	R5$6 .dkk$))  D^hlhphp  rM  iN  iT  RT  h[  h[  h]  D^  ;^  ;e  be  /f  .g  gk  	l7$8 	9$: 
?>?;$< 	=$> 	&?$@ A$B 	C$D 	E$F 	G$ $ $1	s    B)\"'E?\'c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_ok.save_selector_address_predecessor_context.jsonF),r&   )ensure_ascii
separatorsr  r   r   )mkdir
write_textr   dumps)r  out_dirs     r   write_outputsr  E  sD    MM$M.??KK

7:FM L r   c                 F   t        j                  t              } | j                  dt        t
        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  d	t        t               | j                         }t        |j                  j                         t        |j                  g       t        |j                  i             }t        ||j                         t!        d
|j                  dz          y )N)descriptionz--exezHwanse2.exe)typedefaultz--selectorszsave_scene_selectors.jsonz--secondary-fill-rootsz'save_selector_secondary_fill_roots.jsonz	--out-dirz3wrote save selector address predecessor context -> r  )argparseArgumentParser__doc__add_argumentr   ROOTOUT
parse_argsr  rK   
read_bytesr#   r.   r   r  r  print)parserargsr  s      r   mainr  M  s    $$9F
dD=4HI
D#@[:[\
0tSKtEtu
$<D$.."%$++R0G
 '4<<(	?O@  @A  B  Cr   __main__)r   r4   returnrC   )r!   r   r"   r   r  r   )r*   r   r  rC   )r.   
list[dict]r/   rC   r  r   )r   
str | Noner  
int | None)r;   r  r7   r4   r  r  )r;   r  r7   r4   r  r  )rK   bytesr;   r  r7   r4   r  r  )r.   r  r  	list[int])r.   r  rU   r4   r  r  )r.   r  rU   r4   r  ztuple[int, int | None])rK   r  r;   r  rc   r4   rd   r  re   r4   r  r  )rj   r  rt   r   r  r  )i   @   )rK   r  r;   r  r7   r4   r   r4   r   r4   r  r  )rK   r  r;   r  r7   r4   r   r4   r   r4   r  z	list[str])r   rC   r   dict | Noner  r   )r   r  r=   r4   r  r4   )r   r   r  zlist[int] | None)r   r  r  r   )r   r4   r  r  )r   r4   r   r4   r   r  r  r  )rK   r  r;   r  r   r  r   r  r   r4   r   r  r  r   )
r.   r  rU   r4   r%  r  r   r  r  r   )N)rK   r  r.   r  r   r  r  r   )r  r   r  rC   )r  r   r  r   r  None)r  r  )Cr  
__future__r   r  r  r   rI   syspathlibr   typingr   r!   insertrC   __file__resolveparentprobe_exe_scene_tablesr   summarize_script_handler_tabler   r  r  r  r#  r$  rv  rw  ru  r   r   r   r   r   r   r   r   r   r#   r+   r0   r5   r?   rD   rM   rS   rV   rY   rm   ry   r   r   r   r   r   r   r   r   r  r,  r  r  r  r  r  __name__r   r   r   <module>r     sh   O "     
   3tH~--/667 8 0 = H~''*
Ul		$   832-4	  	
  B* !	!! 	! 	!
 ! !> 
	

 	
 	

 
 

	>!H( 0G	GG G 	G
 G G 
GT:hV_DTnC  zF r   