
    7,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 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g dddg dddg ddgZ!dddddZ"d6dZ#d7dZ$d8dZ%d9d Z&d9d!Z'd9d"Z(d9d#Z)d9d$Z*d:d%Z+d;d&Z,d<d'Z-d=d(Z.d>d)Z/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d?d*Z0d@d+Z1dAd,Z2dBd-Z3dCd.Z4dDdEd/Z5dFd0Z6dGd1Z7dGd2Z8efdHd3Z9dId4Z:e;d5k(  r e:        yy)JzOSummarize direct entry-pointer source refs for current route-pair leaf entries.    )annotationsN)Path)Any)read_sectionsva_to_offset)handler_for_opcode   outmap1_01amap2_02dz2:0iT i)T i)T i*T z0out/save_selector_leaf_table_global_context.json)currentSelectorRouteRowscurrentSelectorRoutePairIndices(currentSelectorNegativeRoutePairRowCount+currentSelectorNonNegativeRoutePairRowCountcurrentFrontierLeafOnlyNegative)pathfieldszout/script_handler_table.json)handlerTableVaHexopcodeCountcodeHandlerCountdefaultHandlerCountentriesz0out/save_selector_opcode07_indexed_pointers.json)	opcode07IndexModerowCountvalidTableRowCount selectedLeafTableWindowSlotCount"selectedNegativeRootEntrySlotCount!selectedCurrentRootEntrySlotCountselectedWrapperEntrySlotCountdirectFrontierTargetCountpromotionStatuszWcode-backed direct entry-pointer source for route-pair entries 6/8 or wrapper entry -12zNmodeled encoded entry-anchor control-flow candidate for route-pair entries 6/8zLnon-direct higher-level selector/table index source selecting entries 6 or 8z6normal runtime selection of negative -12 wrapper entry)direct-entry-pointer-source!encoded-entry-anchor-control-flownonnegative-entry-index-sourcenegative-wrapper-index-sourcec                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     P/home/exedev/hwanse/tools/summarize_save_selector_route_pair_index_source_gap.py	load_jsonr0   S   s*    ;;=::dnngn677    c                2    t        | t              rd| dS d S )N0x08x)
isinstanceintvalues    r/   hex32r9   Y   s    )%5Rc{?4?r1   c                "    | rt        | d      S d S )N   )r6   r7   s    r/   	parse_hexr<   ]   s    "3ub>,,r1   c                    t        |t              sy t        ||      }||dz   t        |       kD  ry t	        j
                  d| |      d   S )N   <Ir   r5   r6   r   lenstructunpack_fromexesectionsvaoffsets       r/   dword_atrI   a   L    b#(B'F~!c#h.dC033r1   c                    t        |t              sy t        ||      }||dz   t        |       kD  ry t	        j
                  d| |      d   S )N   z<Hr   r@   rD   s       r/   u16_atrM   j   rJ   r1   c                    t        |t              sy t        ||      }||dz   t        |       kD  ry t	        j
                  d| |      d   S )NrL   z<hr   r@   rD   s       r/   s16_atrO   s   rJ   r1   c                    t        |t              sy t        ||      }||dz   t        |       kD  ry t	        j
                  d| |      d   S )Nr>   z<ir   r@   rD   s       r/   s32_atrQ   |   rJ   r1   c                h    t        |t              sy t        ||      }||t        |       k\  ry | |   S N)r5   r6   r   rA   rD   s       r/   byte_atrT      s8    b#(B'F~3s8+v;r1   c                   g }| D ]R  }t        |d         }|t        |d         z   }t        ||      }t        ||      }||k  s@|j                  ||f       T g }	|D ]   \  }}|	j	                  t        ||             " |	S )NrG   raw_size)r6   maxminappendextendrange)
rF   start_vaend_vaspanssectionsection_startsection_endstartendvaluess
             r/   readable_vasre      s    #%E 'GDM*#c'**=&>>Hm,&+&3;LL%&' F )
seE3'()Mr1   c                T    | D ]#  }|d   |cxk  r|d   |d   z   k  sn |d   c S  y )NrG   sizename )rF   rG   r_   s      r/   section_for_varj      s>     #4=B@!@@6?"# r1   c                B   t        |t              sg S t        j                  d|      }g }|D ]o  }|d   }||d   z   }| || }|j	                  |      }	|	dk\  s,|d   |	z   }
|j                  |d   |
t        |
      d       |j	                  ||	dz         }	|	dk\  rDq |S )	Nr?   rawrV   r   rG   rh   )r_   refVarefVaHexr	   )r5   r6   rB   packfindrY   r9   )rE   rF   r8   needlerefsr_   rb   rc   dataposref_vas              r/   refs_to_valuerv      s    eS!	[[u%FD -gj))5~iiQhT]S(FKK"6?!&M 
 ))FC!G,C Qh- Kr1   c                    t        | j                  d      xs i j                  d      xs g D ch c]$  }|j                  d      r|j                  d      & c}      S c c}w )NstreamEffectfixedAdvancesbytes)sortedget)handleritems     r/   fixed_advance_bytesr      s^    [[06B;;OLRPR88G 	   s   )A c                N    | j                  d      xs i j                  d      du S )Nrx   canJumpToDwordAtPlus4Tr|   )r}   s    r/   can_jump_to_plus4r      s'    KK'-2223JKtSSr1   c                  |d   }|dz
  }t        | ||      }	|	|	dz  nd }
|	|	dz	  dz  nd }|
t        | ||
      ni }|dz  }t        | ||      }t        |      }t        |      }t        |      }t        |cxk  xr	 t
        k  nc }t        |cxk  xr	 t
        k  nc }t        |cxk  xr	 t
        k  nc }|dk(  xr ||k(  }|dk(  xr ||xs ddz   k(  }d}d	}|
d
k(  r|dk(  r|dgk(  r|sd}n)|rd}n$|rd}n|j                  d      dk(  rd}d}n|rd}d}|j                  d      du }|dk(  r|rd}i |i d|dt        |      dt        |      dt        |	      d|
d|
dnd d|d|j                  d      d|j                  d      d |d!|d"d|dd#|j                  d$      d%|j                  d      d&|j                  d      d'|d(|d)|||||d*S )+Nrm   r>         descriptor-pointerchild-pointerr   z	data-wordFZ   "opcode-0x5a-mode0-fallthrough-wordleaf-table-entry-celldescriptor-child-wordr_   .textztext-immediate-referenceTz#possible-stream-plus4-branch-targetisCodeHandler
targetKindvalueHexpreviousVaHexpreviousValueHexpreviousOpcodeHexr3   02xpreviousOpcodeModepreviousHandlerHexhandlerVaHexpreviousHandlerSectionhandlerSectionpreviousHandlerFixedAdvances$previousHandlerCanJumpToDwordAtPlus4fallthroughWordOpcodeHexfallthroughWordHandlerEntryHex
entryVaHexfallthroughWordHandlerHexfallthroughWordHandlerSectionfallthroughWordHandlerIsCode$fallthroughWordCanJumpToDwordAtPlus4insideCurrentRootRange)insideCurrentRootEntryRuninsideLeafTableWindowreferenceRolepromotesEntrySelection)
rI   r   r   r   CURRENT_ROOTROOT_TABLE_END_EXCLUSIVEROOT_TABLE_POINTERTABLE_WINDOW_STARTr|   r9   )rE   rF   reftarget_kindr8   entry_vadescriptor_varu   previous_vaprevious_valueprevious_opcodeprevious_modeprevious_handlerfallthrough_opcodefallthrough_handlerprevious_fixedprevious_can_jumpfallthrough_can_jumpinside_current_root_rangeinside_current_root_entry_runinside_leaf_table_windowis_table_cellis_descriptor_childrolepromotesfallthrough_is_codes                             r/   classify_refr      s    \F1*Kc8[9N/=/Int+tO4B4N^q(D0TXMM\Mh)#xInp,S(<NO()9:N)*:;,-@A , Q9Q Q$6&$[C[$[!1VV>VV#77NFh<NM%8_VHZYZ^_G_=_DH$=A#5.QC:OXi3	&	&		w	&)	4-11/BdJ338K
k 	E%L 	{+	
 	E.1 	?;Vr/#!67\` 	m 	.22>B 	!"2"6"67G"H 	' 	/0A 	#b);C(@$A 	)*=*A*A,*O 	$%8%<%<^%L 	()<)@)@AQ)R  	'(;!" 	/0D#$ 	!";%& &C!9"*- r1   c           	         | j                  d       d| j                  d       d| j                  d      xs d d| j                  d      xs d S )Nr   /r   z->r   -r   r   rows    r/   compact_handlerr     sZ    77:
q)C!D E
SWW018S9
CGG34;<	>r1   c                    | j                  d      xs g D cg c]  }|j                  d      t        k(  r| }}t        |d       S c c}w )Nr   selectorc                &    | j                  dd      S )N
entryIndexr   r   r   s    r/   <lambda>z"route_entry_rows.<locals>.<lambda>  s    a(@ r1   )key)r|   SELECTORr{   )leaf_table_global_contextr   rowss      r/   route_entry_rowsr     sW    0445OPVTV77:(* 	D  $@AA	s   !A	c                b    |D cg c]O  }|j                  d      r<|j                  d      t        |j                  d            |j                  d      dQ }}i }i }i }i }|D ]|  }|j                  d      }	t        |	t              s%|j	                  |	dz  g       j                  |       |	t        z
  }
d|
cxk  rdk  rn n|||
<   d|
cxk  rdk  rn n|||
<   |||	<   ~ g g g }dddddd}d$ fd	d% fd
}t        t        t              D ]3  }t         |      }||j                  |g       D ]  }|dxx   dz  cc<    |d|||d        |j                  |      }||dxx   dz  cc<    |d|||d       t         |      }|4|dz   |z   }	|j                  |	      }||dxx   dz  cc<    |d|||d       t         |      }||j                  |      }||dxx   dz  cc<    |d|||d       t         |      }||dz   |z   }	|j                  |	      }||dxx   dz  cc<    |d|||d       6 t        t        t        d      D ]  } |      }t        |      D ]x  }||z   }	|j                  |	      }||j                  t        |      ||j                  d      |j                  d      |j                  d      |j                  d      d       z  t!        |j#                               }t%              }t%        |      }|}|rd}n|rd}nd}t        t               dt        t               t%        |      |D cg c]%  }|j                  d      |j                  d      d' c}|||||||rd nd!|d d" d#S c c}w c c}w )&Nr   r   )r   entryVar   r   i  r   l    )abs16LowcurrentRootRelativeU16currentRootRelativeU32signedRel16SitePlus2signedRel32SitePlus4c                @    t        |       }|t        |      S i S rS   )rT   r   )row_vaopcoderE   rF   s     r/   handler_at_rowz1encoded_entry_anchor_scan.<locals>.handler_at_rowB  s,    h/<B<N!#x8VTVVr1   c                b   |dz  } |      }|j                  d      xs i }| t        |      t        |      d|d|dz  z  dz
  z  d|dz   d|j                  d	      |j                  d
      t        
|      dt        
|      dnd |j                  d      |j                  d      |j                  d      du t        |      |j                  d      du xr ||dz   k(  d}t	              dk  rj                  |       |d   r!t	        	      dk  r	j                  |       y y y )Nrx   r3   r	   r   0rL   xr   r   r   r   r   r   Tr>   )kind	siteVaHexrowVaHexr   targetEntryIndextargetEntryVaHexrowOpcodeHexr   r   handlerCanJumpToDwordAtPlus4handlerFixedAdvancesstartsAtBranchTargetField    r   )r|   r9   rT   r   rA   rY   )r   site_var8   
target_rowwidthr   r}   stream_effectr   branch_attached_rowsrE   r   raw_rowsrF   s            r/   recordz)encoded_entry_anchor_scan.<locals>.recordF  sQ   2 (N39rwfUqUQY'71&<=a	{!^LM *| < *| <sHf-9 !h!? DE#KK7%kk*:;,9,=,=>U,VZ^,^$7$@!!"9:dB\wRX[\R\G\
$ x=2OOC *+4H0IB0N '', 1O+r1   r   r	   z	abs16-lowrL   r   zcurrent-root-relative-u16r   zsigned-rel16-site-plus2r   zcurrent-root-relative-u32r>   r   zsigned-rel32-site-plus4r   r   )r   advancer   r   r   r   z+encoded-entry-anchor-control-flow-candidatez-raw-encoded-entry-anchor-scalars-nonpromotingz"no-encoded-entry-anchor-candidates..)r   r   zready-for-reviewblockedr   )scanRangeHextargetEntryCounttargetEntriesrawScalarCandidateCountsrawScalarCandidateCountbranchAttachedEncodedFieldCount modeledControlFlowCandidateCountpromotingCandidateCountclassificationr!   rawScalarCandidateRowsbranchAttachedEncodedRowsmodeledControlFlowRows)r   r6   returndict)r   strr   r6   r8   r6   r   r  r   r6   r  None)r|   r<   r5   r6   
setdefaultrY   r   re   r   rM   rO   rI   rQ   r[   r   r9   sumrd   rA   )rE   rF   r   r   target_rowslow16_targetsroot_rel16_targetsroot_rel32_targetsexact_targetstargetrelmodeled_rowscountsr   r   value16r   rel16value32rel32r   r}   r   	raw_countbranch_attached_countmodeled_countpromoting_countr   r   r   r   s   ``                          @@@r/   encoded_entry_anchor_scanr    se     77<  '',/ !67'',/	
K  ,.M*,*,%'M 
$#&#&  &"5<<SA|#v&)s#!z!&)s# #f
$ H')!L"#"# ! !FW- -6  ,8PQ Uh0+//< E
z"a'"{GWj!DE ,//8J%/0A502GWjRST3'2E  1u,*..v6
)12a724gujRST3'2+//8J%/0A502GWjRST3'2E  1u,*..v6
)12a724gujRST;U> &>B  (*73 	Gg%F&**62J!"6]"$.NN<$@$.NN<$@ 'N ;")++.>"?! 	  FMMO$I 45%M#OF	H= ./r%8P2Q1RS, #
 77<0@UV
 %+#,+@,9#2(1@-i"*%9".s"3! y~
s   AN''*N,c                   t        |j                  d            }t        |j                  d            }t        |j                  d            }t        | ||      D cg c]  }t        | ||d|||       }}t        | ||      D cg c]  }t        | ||d|||       }}t        | ||      D cg c]  }t        | ||d|||       }	}i d|j                  d      d	|j                  d	      d|j                  d      d|j                  d      d
|j                  d
      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|d|d|	dt	        |      dt        d |D              dt        d |D              dt        d |D              t        d |D              t        d |D              t        d |D              |D cg c]!  }|j                  d      dk(  rt        |      # c}t	        |      t        d |D              t        d |D              t        |      xr t        d  |D              t	        |	      t        d! |	D              t        d" |	D              |"t        |	      xr t        d# |	D              d$S d d$S c c}w c c}w c c}w c c}w )%Nr   descriptorHexchildPointerHexzentry-pointer)r   r8   r   r   r   r   r   entryIsNonNegativedescriptorMarkerHexdescriptorIsMarkerShapedescriptorHasRoutePairchildHasRoutePairisFrontierLeafChildentryPointerRefsdescriptorPointerRefschildPointerRefsentryPointerRefCountentryPointerTextRefCountc              3  J   K   | ]  }|j                  d       dk(  sd  ywr_   r   r	   Nr   .0r   s     r/   	<genexpr>z&build_entry_summary.<locals>.<genexpr>  !     'ac3779CUY`C`'a   ##entryPointerPromotingRefCountc              3  D   K   | ]  }|j                  d       sd  ywr   r	   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>       ,j3PhHiQ,j     'entryPointerOpcode5aFallthroughRefCountc              3  J   K   | ]  }|j                  d       dk(  sd  ywr   r   r	   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s&      7
sww'?Cg'gA7
r.  c              3     K   | ]@  }|j                  d       dk(  r*|j                  d      du r|j                  d      du rd B ywr   r   r   Fr   r	   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  sN      6
ww'+OO675@>?5H	 6
   AAc              3  D   K   | ]  }|j                  d       sd  yw)r   r	   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s!      4
sww/G'HA4
r3  c              3  D   K   | ]  }|j                  d       sd  yw)r   r	   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s!      7
sww/J'KA7
r3  r   r   c              3  J   K   | ]  }|j                  d       dk(  sd  ywr)  r   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s"     ,k3SWWU^M_cjMjQ,kr.  c              3  D   K   | ]  }|j                  d       sd  ywr1  r   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s!      2
CGG4L,MA2
r3  c              3  D   K   | ]  }|j                  d       dk(    ywr   r   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  s     cCCGGO,0GGc    c              3  J   K   | ]  }|j                  d       dk(  sd  ywr)  r   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  r-  r.  c              3  D   K   | ]  }|j                  d       sd  ywr1  r   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>  r2  r3  c              3  D   K   | ]  }|j                  d       dk(    ywr   r   Nr   r*  s     r/   r,  z&build_entry_summary.<locals>.<genexpr>
  s     ^CCGGO,0GG^r@  )&entryPointerFallthroughNonCodeRefCount$entryPointerCurrentRootRangeRefCount'entryPointerCurrentRootEntryRunRefCount'entryPointerFallthroughHandlerSummariesdescriptorPointerRefCountdescriptorPointerTextRefCount"descriptorPointerPromotingRefCountdescriptorPointerOnlyTableCellchildPointerRefCountchildPointerTextRefCountchildPointerPromotingRefCount#childPointerOnlyDescriptorChildWord)	r<   r|   rv   r   rA   r  r   boolall)
rE   rF   r   r   r   child_var   
entry_refsdescriptor_refs
child_refss
             r/   build_entry_summaryrW    s   ./Hcggo67M!234H !h9  	''	
J , !h>  	,'	
O , !h9  	''	
J 8cggl+8cgg&:;8 	cggl+8 	1	8
 	sww'<=8 	"377+D#E8 	377#458 	!#''*B"C8 	SWW%898 	sww'<=8 	J8 	 8 	J8 	J8 	#C'aZ'a$a8  	(,j*,j)j!8" 	23 7
#7
 4
#8( 36 6
!6
 3
 14 4
#4
 1
 47 7
#7
 4

 "4
ww'+OO C 4

 &)%9),,k/,k)k.1 2
(2
 /
 ! dcSbcc #J$''aZ'a$a),,j*,j)j
   _^S]^^i8 8n o8 8IZ4
s   KK2K&Kc           	        t        |       }|xs i }t        |      D cg c]  }t        | ||       }}|D cg c]  }|j                  d      dv s| }}|D cg c]  }|j                  d      s| }}|D cg c]  }|j                  d      xs g D ]  }|   }	}}|D cg c]  }|j                  d      xs g D ]  }|   }
}}|D cg c]  }|j                  d      xs g D ]  }|   }}}t	        d |	D              }t	        d |
D              }t	        d	 |D              }t	        d
 |D              }t	        d |D              }t	        d |	D              }t	        d |	D              }t	        d |	D              }t        | ||      }|j                  d      xs d}|j                  d      xs d}|j                  d      xs d}|j                  d      xs d}|j                  d      xs d}|dk(  xr |dk(  xr |dk(  xr |dk(  xr |dk(  }t        |
      xr t        d |
D              }t        |      xr t        d |D              }|dkD  xs( |dkD  xs! |dkD  xs |j                  dd      dkD  xs | }g }|dk(  r|j                  d       |j                  dd      dk(  r|j                  d       |dk(  r|j                  d       |dk(  r|j                  d       |D cg c]  }t        j                  ||       } }d}!i dt        dt        dt        d t        t              d!t        t              d"t        t                d#t        t"        d$z
         d%|D cg c]  }|j                  d       c}d&|D cg c]  }|j                  d       c}d'|D cg c]  }|j                  d       c}d(t%        |	      d)|d*|d+|d,|j                  d-      d.|j                  d/      d0|j                  d1      d2|j                  d      i d3|j                  d4      d5|d6|d7|d8|d9|j                  d9      d:|j                  d;      d<|j                  d=      d>|d?|d@|dA|dB|dC|dD|	D cg c]!  }|j                  dE      dFk(  rt'        |      # c}dGt%        |
      dHt	        dI |
D              i dJ|dK|dLt%        |      dMt	        dN |D              dO|dP|dQ|dR|dS|dT|dU| dVdWdX|dYt(        dZt%        t(              d[g d\d]|!S c c}w c c}w c c}w c c}}w c c}}w c c}}w c c}w c c}w c c}w c c}w c c}w )^Nr   >      r   r"  r#  r$  r%  c              3  D   K   | ]  }|j                  d       sd  ywr1  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>       +m#377SkKlA+mr3  c              3  D   K   | ]  }|j                  d       sd  ywr1  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>  s!      1CGG4L,M1r3  c              3  D   K   | ]  }|j                  d       sd  ywr1  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>  r[  r3  c              3  F   K   | ]  }|j                  d       xs d  ywr/  r   Nr   r+  r   s     r/   r,  z build_summary.<locals>.<genexpr>  s'      8:=/05A58   !c              3  F   K   | ]  }|j                  d       xs d  ywr_  r   r`  s     r/   r,  z build_summary.<locals>.<genexpr>"  s'      <:=/05A5<ra  c              3  J   K   | ]  }|j                  d       dk(  sd  ywr6  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>%  s&      7sww'?Cg'g7r.  c              3     K   | ]@  }|j                  d       dk(  r*|j                  d      du r|j                  d      du rd B ywr8  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>(  sN      777?#'KKGG23u<GG:;uD	 	
7r9  c              3  J   K   | ]  }|j                  d       dk(  sd  ywr)  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>/  s!     &dScggiFX\cFcq&dr.  r   r   r   r   r   r    c              3  D   K   | ]  }|j                  d       dk(    ywr?  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>E  s&      I@C $;;Ir@  c              3  D   K   | ]  }|j                  d       dk(    ywrD  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>H  s&      D@C $;;Dr@  r   r"   r#   r$   r%   a  The current selector's route-pair entries have no code-backed direct source refs. Entry -13 has no direct entry-pointer ref at all; entries -12, 6, and 8 each have one direct entry-pointer ref, but all three are opcode 0x5a mode 0 fallthrough words whose low-byte handlers are not executable code. The descriptor refs are only the leaf-table cells and child refs are only descriptor child words. The encoded entry-anchor scan adds no modeled control-flow candidate; raw scalar matches stay non-promoting. The opcode 0x07 zero-extended indexer also selects no leaf-table window, negative entry, current-root entry, wrapper entry, or direct frontier target. This removes the direct/encoded/opcode07 path as proof that a higher-level index selects entries 6/8 or the negative -12 wrapper; normal-route promotion still needs runtime selected-root execution, a decoded index source, or a strict source hotspot.sourcer  r   currentRootHexrootTablePointerHextableWindowHexr   r>   routeEntryIndicesroutePairEntryIndicesnegativeReaderEntryIndicesr&  r'  r/  encodedEntryAnchorScan)encodedEntryAnchorRawScalarCandidateCountr   1encodedEntryAnchorBranchAttachedEncodedFieldCountr   2encodedEntryAnchorModeledControlFlowCandidateCountr   )encodedEntryAnchorPromotingCandidateCount encodedEntryAnchorClassificationr   r4  rE  (nonNegativeEntryPointerPromotingRefCount+negativeReaderEntryPointerPromotingRefCountr   opcode07RowCountr   opcode07ValidTableRowCountr   (opcode07SelectedLeafTableWindowSlotCount*opcode07SelectedNegativeRootEntrySlotCount)opcode07SelectedCurrentRootEntrySlotCount%opcode07SelectedWrapperEntrySlotCount!opcode07DirectFrontierTargetCount"opcode07DirectEntrySelectionAbsentrH  r   r   rI  rJ  c              3  J   K   | ]  }|j                  d       dk(  sd  ywr)  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>  s%     ,o3QTQXQXYbQcgnQnQ,or.  rK  descriptorRefsOnlyTableCellsrM  rN  c              3  J   K   | ]  }|j                  d       dk(  sd  ywr)  r   r*  s     r/   r,  z build_summary.<locals>.<genexpr>  s!     'ecswwyGY]dGd'er.  rO  !childRefsOnlyDescriptorChildWordshigherLevelIndexSourceProvendirectPointerRefPromotesRoute
proofFound!failedRoutePairIndexSourceGateIdsmissingEvidencer!   r   r   evidenceRefsevidenceRefCountremainingProofs)zOdecode a non-direct higher-level selector/table index source for entries 6 or 8z@prove normal runtime selection of the negative -12 wrapper entryzKprove selected-root execution reaches selector 2:0 on the normal route pathzFfind a strict map1_01a source coordinate or hotspot linked to map2_02d
conclusion)r   r   rW  r|   r  r  rQ  rR  rY   0ROUTE_PAIR_INDEX_SOURCE_MISSING_EVIDENCE_BY_GATESOURCETARGETr   r9   r   r   r   r   rA   r   EVIDENCE_REFS)"rE   r   opcode07_indexedrF   r   r   route_pair_entriesnegative_reader_entriesr   all_entry_refsall_descriptor_refsall_child_refs!entry_pointer_promoting_ref_count&descriptor_pointer_promoting_ref_count!child_pointer_promoting_ref_count-nonnegative_entry_pointer_promoting_ref_count1negative_reader_entry_pointer_promoting_ref_count,entry_pointer_opcode5a_fallthrough_ref_count,entry_pointer_fallthrough_non_code_ref_countentry_pointer_text_ref_countencoded_anchor_scan.opcode07_selected_leaf_table_window_slot_count0opcode07_selected_negative_root_entry_slot_count/opcode07_selected_current_root_entry_slot_count*opcode07_selected_wrapper_entry_slot_count%opcode07_direct_frontier_target_count&opcode07_direct_entry_selection_absent descriptor_refs_only_table_cells child_refs_only_descriptor_words higher_level_index_source_provenfailed_index_source_gate_idsgate_idmissing_evidencer  s"                                     r/   build_summaryr    s'   S!H'-2BRSlBmn3"3#6nGn)0T#CGGL4IV4S#TT.5XsAV9WsXX%,Zc@R8S8YWYZcZcZNZ*1d3SWWE\=]=cacdc3d3dd%,Zc@R8S8YWYZcZcZNZ(++m+m(m%-0 1(1 .* ),+m+m(m%47 8AS8 51 9< <AX< 95 47 7#7 40 47 7!7 40 $'&dN&d#d 3C7K?@EA 3 	ABGa 5 	@AFQ 4 	<=B / -=,@,@A\,],bab)6!; 	7<A	7;q@	7 7!;	7 2Q6 + (,,?'@ (S IGZI F$ (,N'; ( DGUD A$ 	*A- 	681<	6<q@	6 ""#<a@1D	6 65 % $& (A-$++,IJ8!<A$++,OP49$++,LM8A=$++,KL 4 	9<<WgN 
		4 A&A&A 	HA 	%-	A
 	u%78A 	U#567r%@X[\@\:]9^_A 	wGcggl3GA 	 CU!VC#'',"7!VA 	%H_&`sww|'<&`A 	N 3A 	#$@A 	()JA 	!"5A 	45H5L5LMf5gA 	<=P=T=T->
A$ 	=>Q>U>U.?
%A* 	45H5L5LMf5g+A, 	+,?,C,CDT,U-A. 	23_/A0 	12^1A2 	34a3A4 	67h5A6 	-112EF7A8 	,00<9A: 	%&6&:&:;O&P;A< 	34b=A> 	56f?A@ 	45dAAB 	01[CAD 	,-REAF 	-.TGAH 	2%4
ww'+OO C 4
IAR 	$S)<%=SAT 	(,o:M,o)oUAV 	-.TWAX 	'(HYAZ 	N 3[A\ 	#C'e^'e$e]A^ 	()J_A` 	,-MaAb 	'(HcAd 	()IeAf 	6gAh 	,-IiAj 	+kAl 	9mAn 	7oAp 	qAr 	C.sAt 	 
uA@ 	jAA Ao oTXZdZD. H!V&`64
sL   UUUU3U>#U)#U!#U'<U-=U2U7=U<!&V
c                B    dj                  d | xs g D              xs dS )N,c              3  2   K   | ]  }t        |        y wrS   )r  )r+  r8   s     r/   r,  zcsv.<locals>.<genexpr>  s     95CJ9s   r   )join)rd   s    r/   csvr    s     889FLb99@S@r1   c                	   g dd| d   dd| d    d| d    dd	| d
    d| d    dd| d    ddt        | d          ddt        | d          ddt        | 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    d| d2    d| d3    d| d4    d	d5t        | d6          dd7| d8    dd9| d:    dd;| d<    dd=| d>    dd?t        | j                  d@             ddAt        | j                  dB      xs g        ddC| dD    ddE| dF    dddGd| j                  dB      xs g D cg c]  }dH| 	 c}ddIddJdK}| dL   D ]  }|j                  dM|j                  dN       dO|j                  dP       dQ|j                  dR       dQ|j                  dS      xs dT dU|j                  d       dV|j                  d       dV|j                  d       dV|j                  d!       dV|j                  d#       dVt        |j                  d6             dV|j                  dW       dV|j                  dX       dY        |j	                  ddZdd[d\dM| d    dV| d    dV| d    dV| d    dV| d    dYdd]dd^d_g       | dL   D ]  }|j                  d`      xs g D ]  }|j                  dM|j                  dN       dO|j                  da       dU|j                  db       dV|j                  dc       dO|j                  dd       d|j                  de       dQ|j                  df       dg|j                  dh      xs dT dV|j                  di       dV|j                  dj       dV|j                  dk       dY         |j	                  g dl       | j                  dm      xs g D ]@  }dnj                  |j                  do      xs g       }|j                  dp|dq    dr|        B |j	                  g ds       |j	                  dt | du   D               |j                  d       dvj                  |      S c c}w )wNz+# Save Selector Route-Pair Index Source Gap r  z
- route: `rh  z -> r  `z- selector/root: `r   z` / `ri  z- root table pointer: `rj  z- route entry indices: `rl  z- route-pair entry indices: `rm  z"- negative reader entry indices: `rn  z&- entry pointer refs/text/promoting: `r&  r'  r/  z6- encoded entry-anchor raw/branch/modeled/promoting: `rp  rq  rr  rs  z(- encoded entry-anchor classification: `rt  z,- entry pointer opcode5a fallthrough refs: `r4  z,- entry pointer fallthrough non-code refs: `rE  z.- non-negative entry pointer promoting refs: `ru  z1- negative reader entry pointer promoting refs: `rv  z- opcode07 index mode: `r   z+- opcode07 direct entry selection absent: `r~  z(- opcode07 rows/valid/direct frontier: `rw  rx  r}  z:- opcode07 selected leaf/negative/current/wrapper slots: `ry  rz  r{  r|  z'- entry pointer fallthrough handlers: `rH  z%- descriptor refs only table cells: `r  z+- child refs only descriptor child words: `r  z%- higher-level index source proven: `r  z- proof found: `r  z)- failed route-pair index-source gates: `r  z- missing evidence count: `r  z- evidence refs: `r  z- promotion status: `r!   z## Missing Evidence- z
## Entriesz| index | entry | descriptor | child | entry refs | text refs | promoting refs | opcode5a refs | non-code refs | handlers | desc table-only | child word-only |zO| ---: | --- | --- | --- | ---: | ---: | ---: | ---: | ---: | --- | --- | --- |r   z| r   z | `r   z` | `r  r  r   z` | z | rL  rP  z |z## Encoded Entry AnchorszU| classification | raw scalars | branch-attached | modeled control-flow | promoting |z#| --- | ---: | ---: | ---: | ---: |z## Entry Pointer Refszm| index | ref | section | role | previous | fallthrough handler | current root range | entry run | promotes |z8| ---: | --- | --- | --- | --- | --- | --- | --- | --- |r#  rn   r_   r   r   r   r   z` / r   r   r   r   )r  z## Evidence Refsr  r  , r   z- `r   z`: )r  z## Remaining Proofsr  c              3  &   K   | ]	  }d |   yw)r  Nri   r+  r~   s     r/   r,  zmarkdown.<locals>.<genexpr>  s     D2dVDs   r  
)r  r|   rA   rY   rZ   r  )summaryr~   linesr   r   r   s         r/   markdownr    sP   (5(
( 	( 		(
 WX&'tGH,=+>a@( WZ01w?O7P6QQRS( "'*?"@!AC( #3w/B'C#D"EQG( (G4K,L(M'NaP( -S9U1V-W,XXYZ( 19O1P0QQVW^_yWzV{  |A  BI  Ji  Bj  Ak  kl  	m( AItAu@vv{  }D  Ex  }y  |z  z  @G  H|  @}  ~  ~C  DK  Lw  Dx  Cy  yz  	{( 37;]3^2__`a( 7w?h7i6jjkl( 7w?g7h6iijk(  9Ak9l8mmno!(" <GDq<r;sstu#($ #7+>#?"@B%(& 6g>b6c5ddef'(( 37;M3N2OuU\]yUzT{  |A  BI  Jm  Bn  Ao  op  	q)(* EWMwExDyy~  @G  Ht  @u  v  v{  |C  Do  |p  {q  qv  w~  f  wg  vh  hi  	j+(, 2#g>g6h2i1jjkl-(. 08V0W/XXYZ/(0 6g>a6b5ccde1(2 08V0W/XXYZ3(4 7<0135(6 4CDg8h4i3jjkl7(8 &c'++6G*H*NB&O%PPQR9(: W%789;;(<  (9 :;1==(> 	?(@ 	A(B 	C(D #*++.?"@"FB	G$Btf+	GE(F 	G(H 	I(J 	K(L 	jM(N 	ZO(ER y! 	
&'tCGGL,A+B%P_H`Ga b)*1c2$sww?U7V6WWZww1233sww?^7_6``cww@AB#ww?@A377DEFGsww789SWWEj=k<llnp	
	
 
LL
"
_-;<=SBCDCJKLCKLMSBCDB	H 	
wB# & y! 77-.4" 	CLLSWW\*+4
0C/DDQZI[H\\_77?+,D9K1L0MUSVSZSZ[nSoRp qGG789cggFe>f>mjm=nnq77345SA\9]8^^a77345R	9	 
LL-.{{>*0b 53778,23s3v;-s6(345 
LL01	LLD1B)CDD	LL99Ui 
Hs   .R?c                   g }| d   D ]N  }|j                  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|j                  d       d|j                  d       d|j                  d       d|j                  d       dt        j                  t	        |j                  d                   d|j                  d       d|j                  d       d       Q g }| d   D ]  }|j                  d      xs g D ]|  }|j                  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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|j                  d       d|j                  d        d|j                  d!       d         d"j                  d# | d$   D              }d"j                  d% | j                  d&      xs g D              }d"j                  d' | j                  d(      xs g D              }d)j                  g d*d+d,d-d.d/d0d1d2d3d4t        j                  | d5          d6d7t        j                  | d8          d9t        j                  | d:          d;t        j                  | d<          d=t        j                  | d>          d?t        j                  | d@          dAd"j                  g dB| d    dC| d    dC| d    dD| dE    dC| dF    dC| dG    dC| dH    dI| dJ    dC| dK    dC| dL    dC| dM    dC| dN    dC| dO    dC| dP    dQ| dR    dS| d    dC| d    dT| dU    dV| dW    dXt        j                  t	        | j                  dY                   dZt        | j                  d&      xs g        d[      d\| d]    d[d^d_| d`dadbdcd"j                  |       dddedfdgt        j                  t        | dh                d| dE    d| dF    d| dG    d| dH    didjdkdcd"j                  |       dddld_| d`dmd_| d`dndod"      S )pNr   z<tr><td>r   z</td><td><code>r   r   z</code></td><td><code>r  r  z</code></td><td>r&  z	</td><td>r'  r/  r4  rE  rH  rL  rP  z
</td></tr>r#  rn   r_   r   r   z</code> / <code>r   r   z
</code> / r   r   r   r   r  c              3  N   K   | ]  }d t        j                  |       d  ywz<li></li>Nhtmlescaper  s     r/   r,  zhtml_page.<locals>.<genexpr>2  s#     adDT!2 359a   #%r  c              3  N   K   | ]  }d t        j                  |       d  ywr  r  r  s     r/   r,  zhtml_page.<locals>.<genexpr>3  s(      ,0$t{{4 !'r  r  c              3     K   | ]h  }d t        j                  |j                  d      xs d       dt        j                  dj                  |j                  d      xs g              d j yw)z
<li><code>r   r  z	</code>: r  r   r  N)r  r  r|   r  r*  s     r/   r,  zhtml_page.<locals>.<genexpr>6  sf      !
 		SWWV_234I;;tyy!2!8b9:
;	!s   A.A0r  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 Route-Pair Index Source Gap</title>a    <style>body{margin:24px;background:#111;color:#eee;font:14px system-ui,sans-serif;line-height:1.45}table{border-collapse:collapse;width:100%;margin:18px 0}td,th{border:1px solid #333;padding:6px 8px;text-align:left;vertical-align:top}th{background:#202020}code{color:#9bd4ff}</style>z</head>z<body>z4  <h1>Save Selector Route-Pair Index Source Gap</h1>z  <p>r  z</p>z  <p><b>Route:</b> <code>rh  z -&gt; r  z</code>; selector <code>r   z</code>; root <code>ri  z </code>; promotion status <code>r!   z</code>.</p>z(  <p>entry pointer refs/text/promoting: r   z(; encoded raw/branch/modeled/promoting: rp  rq  rr  rs  z<; opcode07 rows/valid/leaf/negative/current/wrapper/direct: rw  rx  ry  rz  r{  r|  r}  z*; opcode07 direct entry selection absent: r~  z!; opcode5a fallthrough/non-code: z$; higher-level index source proven: r  z; proofFound=r  z(; failedRoutePairIndexSourceGates=<code>r  z</code>; missingEvidenceCount=z.</p>z  <p><b>Evidence refs:</b> r  z  <h2>Missing Evidence</h2>z  <ul>z</ul>z  <h2>Entries</h2>a    <table><thead><tr><th>index</th><th>entry</th><th>descriptor</th><th>child</th><th>entry refs</th><th>text refs</th><th>promoting refs</th><th>opcode5a refs</th><th>non-code refs</th><th>handlers</th><th>desc table-only</th><th>child word-only</th></tr></thead>z	  <tbody>z</tbody></table>z   <h2>Encoded Entry Anchors</h2>z  <table><thead><tr><th>classification</th><th>raw scalars</th><th>branch-attached</th><th>modeled control-flow</th><th>promoting</th></tr></thead><tbody>z
  <tr><td>rt  z</td></tr></tbody></table>z  <h2>Entry Pointer Refs</h2>z  <table><thead><tr><th>index</th><th>ref</th><th>section</th><th>role</th><th>previous</th><th>fallthrough handler</th><th>current root range</th><th>entry run</th><th>promotes</th></tr></thead>z  <h2>Evidence Refs</h2>z  <h2>Remaining Proofs</h2>z</body>z</html>)rY   r|   r  r  r  r  rA   r  )r  
entry_rowsr   ref_rowsr   proof_itemsmissing_itemsevidence_ref_itemss           r/   	html_pager    s?	   Jy! 
77<() *SWW\%:%AcBC DSWW_%=%DEF GSWW->%?%F3GH I77123 477567 877:;< =77DEF G77CDE F;;s377+T#UVWX Y77;<= >77@AB C	

" Hy! 77-.4" 	COOww|,- .![[)<)CDE F{{3779#5#<=> ?{{377?#;#BsCD E![[1C)D)KLM NSWW-@%A%HSIJ K![[1L)M)TQTUVV`;;sww'FGN3OP Qww789 :ww:;< =ww789 :	" ''agN_F`aaKGG 4;KK@Q4R4XVX M  !
 ;;~.4"!  99 JJJ 	J 	#	J
 	QJ 	EJ 	hJ 	J 	J 	?J GL12348J[[!234GDKKPXHY<Z;[ \"kk'**=>? @++g.>&?@A B&&*kk':K2L&M%Nl	\J(U U6 U-./U/0U123U34U 678U95U
 BCDU
 EFU JKLU MNU KLMU NOU BCDUEIU )*+U ,-U 345U 67U ABCU DEU CDEU FGU BCDU EFU >?@U ABU  :;<!U =7!U$ ;<=%U$>.%U( @AB)U( CD)U* ?@A+U*B1+U. 567/U.8/U0 ",/01U011U4 [[W[[1T%U!VWX5U4Y$5U6 %(4E(F(L"$M#N7U6 OT7U)Jb &g.@&A%B%HcJd 	&eJf u%gJh 	iJj 	RkJl BGGJ'((89mJn 	+oJp 	eqJr	{{3w'IJKLM NBCD EJKL MKLM NBCD E 	 sJ@ 	(AJB 	NCJD BGGH%&&67EJF 	#GJH #$E*IJJ 	&KJL U#MJN 	OJP 	QJR 	SJ J Jr1   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz.save_selector_route_pair_index_source_gap.jsonFrL   )ensure_asciiindentr  r'   r(   .save_selector_route_pair_index_source_gap.html)mkdir
write_textr+   dumpsr  )r  out_dirs     r/   write_outputsr    sk    MM$M.??KK

7q9D@ L  ??KK' L r1   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                  i       t        |j                  i             }t        ||j                         t!        d
|j                  dz          y )N)descriptionz--exezHwanse2.exe)typedefaultz--leaf-table-globalz,save_selector_leaf_table_global_context.jsonz--opcode07-indexedz,save_selector_opcode07_indexed_pointers.jsonz	--out-dirz%wrote route-pair index source gap -> r  )argparseArgumentParser__doc__add_argumentr   ROOTOUT
parse_argsr  rE   
read_bytesr0   leaf_table_globalr  r  r  print)parserargsr  s      r/   mainr    s    $$9F
dD=4HI
-D#HvBvw
,4GuAuv
$<D$(("-$'',G
 '4<<(	/<<JJ
K	Mr1   __main__)r   r   r.   r   r  r   )r8   
int | Noner  
str | None)r8   r  r  r  )rE   rz   rF   
list[dict]rG   r  r  r  )rF   r  r\   r6   r]   r6   r  	list[int])rF   r  rG   r6   r  r  )rE   rz   rF   r  r8   r  r  r  )r}   r  r  r  )r}   r  r  rQ  )rE   rz   rF   r  r   r  r   r  r8   r6   r   r  r   r  r  r  )r   r  r  r  )r   r  r  r  )rE   rz   rF   r  r   r  r  r  )rE   rz   rF   r  r   r  r  r  rS   )rE   rz   r   r  r  zdict | Noner  r  )rd   zlist[Any] | Noner  r  )r  r  r  r  )r  r  r  r   r  r  )r  r  )<r  
__future__r   r  r  r+   rB   syspathlibr   typingr   r   insertr  __file__resolveparentprobe_exe_scene_tablesr   r   summarize_script_handler_tabler   r  r  r  r  r  r   r   r   r   r   r  r  r0   r9   r<   rI   rM   rO   rQ   rT   re   rj   rv   r   r   r   r   r   r  rW  r  r  r  r  r  r  __name__ri   r1   r/   <module>r     s   U "     
   3tH~--/667 8 > = H~''*
Ul		  %  C
	 0
	 C

+#N 	b 	Y 	W 	A4 0 8@-4444*TE	EE 
E
 E E E E 
EPBNb`F[|AWtzz 25 	& zF r1   