
    `i\                     ,   d dl 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mZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ  e
ddd	      Zej$                  j'                  e      Zej$                  j-                  ed
      Z G d de      Zd Zdi efdZd Zd Zy)    N)	ASTSourcemake_backend)	GPUTarget)GluonASTSource)create_function_from_signature)ircudad       	FileCheckc                   (     e Zd Z fdZ fdZ xZS )
MatchErrorc                 2    t         |   |       || _        y N)super__init__
module_str)selfmessager   	__class__s      K/var/www/html/engine/venv/lib/python3.12/site-packages/triton/_filecheck.pyr   zMatchError.__init__   s    !$    c                 >    t         |           d| j                   S )N
)r   __str__r   )r   r   s    r   r   zMatchError.__str__   s!    '/#$Bt&788r   )__name__
__module____qualname__r   r   __classcell__)r   s   @r   r   r      s    %9 9r   r   c                    t        j                         5 }t        j                  j	                  |d      }t        |d      5 }|j                  |       d d d        t        j                  j	                  |d      }t        |d      5 }|j                  |       d d d        	 t        j                  t        |d|dgt        j                         	 d d d        y # 1 sw Y   xY w# 1 sw Y   NxY w# t        j                  $ r+}|j                  j                  d      }t        |      d }~ww xY w# 1 sw Y   y xY w)Nmodulewexpectedz--input-filez--dump-input-context=50)stderrunicode_escape)tempfileTemporaryDirectoryospathjoinopenwrite
subprocesscheck_outputfilecheck_pathSTDOUTCalledProcessErroroutputdecode
ValueError)	namer   check_templatetempdirtemp_moduletemptemp_expectederrordecodeds	            r   run_filecheckr=   #   s   		$	$	& &'ggll7H5+s# 	#tJJz"	# Wj9-% 	'JJ~&	'	&##Mfg!((*& &	# 	#	' 	' ,, 	&ll))*:;GW%%	&& &sY   -D4C4D4C'D4#.C3C$	 D4'C0	,D43D1&D,,D11D44D= c                 $   d|vrt        |      }d|d<   t        |      }t        | j                  | j                  |      } ||i |\  }}}| j                  |||||      \  }}	}
}| j                         rt        nt        } || |	|
|      }t        j                         }t        j                  |       |j                  |       |j                  |      }|j                         }|j                  |||||      }|j                         sJ |S )Nsanitize_overflowF)dictr   r   	signatureparams
_pack_argsis_gluonr   r   r   contextload_dialectsget_codegen_implementationget_module_mapmake_irverify)	kernel_fnargskwargstargetbackendbinder
bound_argsspecializationoptionsrB   
constexprsattrs
source_clssrcrF   codegen_fns
module_mapr!   s                     r   
run_parserr[   6   s   &(f&+"#6"G+F +1$*A&*A'J,5,@,@&R\^lnu,v)GY
E#,#5#5#7YJ
Y	:u
=CjjlGW'"44W=K'')J[[+z7KF==??Mr   c                     t        | t        j                  j                        sJ t	        j
                  | j                        }|t        d      t        |       }t        d|j                         |       y )Nz=kernel function must have a docstring with FileCheck templateplaceholder)
isinstancetritonruntimeJITFunctioninspect	getsourcefnr4   r[   r=   str_nodebug)rL   r6   mlir_modules      r   run_filecheck_testrg   Q   sa    i!;!;<<<&&y||4NXYYY'K-!8!8!:NKr   c                 B     t        j                          fd       }|S )Nc                      t                y r   )rg   )rd   s   r   test_fnzfilecheck_test.<locals>.test_fn]   s    2r   )	functoolswraps)rd   rj   s   ` r   filecheck_testrm   [   s%    __R  Nr   )rk   r(   rb   r-   r&   r_   triton.compilerr   r   triton.backends.compilerr   "triton.experimental.gluon._runtimer   triton.runtime.jitr   triton._C.libtritonr   stub_targetr)   dirname__file__
triton_dirr*   r/   r4   r   r=   r[   rg   rm   r>   r   r   <module>rw      s     	     3 . = = " R(WW__X&
j+69 9&&  ""[ 6Lr   