
    ukiN                     z   d Z ddlZddlZddlmZ ddlmZ  ej                  d      Z ej                  d      Z	 ej                  d      Z
 ej                  d      Z ej                  d	g d
      Z ej                  ddg      Zdedej                   fdZdee   deeeej,                  f   ee   f   fdZy)z;Utilities for generating source mappings for MLIR dialects.    N)cast)	sourcemapzloc\(#loc(?P<id>[0-9]+)\)z#loc(?P<id>[0-9]+) = loc\(\"(?P<file>.*)\":(?P<line>[0-9]+):(?P<col>[0-9]+)( to (?P<endlineno>[0-9]+)?:(?P<endcolno>[0-9]+))?\)zG#loc(?P<id>[0-9]+) = loc\(\"(?P<scope>.*)\"\(#loc(?P<tgt_id>[0-9]+)\)\)zX#loc(?P<id>[0-9]+) = loc\(callsite\(#loc(?P<callee>[0-9]+) at #loc(?P<caller>[0-9]+)\)\)LocationfilelinecolRedirecttgt_id	mlir_dumpreturnc                    t        j                         }| j                  d      }t        |      \  }}g }g }|D ]  }|j	                          t
        j                  |      }|s+t        |j                  d            }	|	|vrJt        ||	         }
|j                  |j                         d         }||
d<   |
d   }||vr%|j                  |       |j                  ||          |j                  |      |
d<    |j                  |
   |j	                          t        j                  d|dgt        |      z  |j!                         g       S )N
idr          )versionsourcessources_contentmappingsnames)r   MappingsGeneratorsplitparse_mlir_locations	new_group	LOC_REGEXsearchintgrouplistindexstripappendnew_segment	SourceMaplenr   )r   r   
dump_linessegment_dictr   used_sourcesused_sources_filenamesr   matchloc_idsegment	first_col
source_idxs                ^/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/experimental/source_mapper/mlir.pycreate_mlir_sourcemapr2   ,   sR   ((*(#//$/*.z:,, %dT"E5;;t$%f	|	#\&)*g**TZZ\!_-igaj 1:j	<	'J'%%gj&9:%%j1gajhG$'%( 			($%;!<<$$&
     c           	         i }g }| D ]1  }|j                  d      st        j                  |      }|r`|j                         }|d   }t	        |t        |d         t        |d               |t        |d         <   ||vr|j                  |       t        j                  |      }|r8|j                         }t        t        |d               |t        |d         <   t        j                  |      }|r9|j                         }t        t        |d	               |t        |d         <   ,d
|v s24 	 i }	d}
|j                         D ]/  \  }}t        |t              r||j                     |	|<   d}
+||	|<   1 |	}|
snLi }|j                         D ]N  \  }}t        t        |      }d|j                  |j                        |j                   dz
  |j"                  f||<   P ||fS )Nz#locr   r   r	   r   r   r   )r   calleezloc(unknown)TFr   r   )
startswith	SRC_REGEXr,   	groupdictr   r   r$   SCOPED_REGEXr
   CALLSITE_REGEXitems
isinstancer   r   r"   r   r   r	   )r   	locationssource_filesr   	src_match
match_dictfilenamescoped_matchcallsite_matchnew_locationsupdatedr-   locr)   id_s                  r1   r   r   R   s    /1), dv//$'i	((*
f%+3Z'(Ju%&,
	#j&'(
 <'


h
'!''-l	!++-
+3z(+,,
	#j&'( 	%++D1n	#--/
+3z(+,,
	#j&'( 		4	;> 	46MG ( $	C	" )#** 5f #f$ I 	 02,//# 	hc3 x
C	388$1	L		 
|	##r3   )__doc__collectionsretypingr   jax._srcr   compiler   r7   r9   r:   
namedtupler   r
   strr&   r2   r!   tupledictr   Segmentr    r3   r1   <module>rT      s    B  	   BJJ34	BJJ<	 rzzN #
 ";!!*.EF!;!!*xj9#S #Y-@-@ #L;$Cy;$
4Y&&&'c23;$r3   