a
    xþd¨  ã                   @   sP   d dl Z d dlZd dlZe d¡Ze d¡ZG dd„ deƒZG dd„ deƒZ	dS )é    Nz^(\\)?((\| )?)\W+b(\S+)\\b\W*$z(\W*)(\b[^\b]+\b)c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFindToolc                 C   s
   || _ d S ©N)Úname)Úselfr   © r   úW/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/llvm/subst.pyÚ__init__   s    zFindTool.__init__c                 C   sV   |j j | j¡}|d u r0tj | j|¡}|s0d S | jdkrRtj d¡dkrR|d7 }|S )NZllcZLLVM_ENABLE_MACHINE_VERIFIERÚ1z -verify-machineinstrs)	Ú
lit_configÚparamsÚgetr   ÚlitÚutilÚwhichÚosÚenviron)r   ÚconfigÚdirsÚcommandr   r   r   Úresolve   s    zFindTool.resolveN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   
   s   r   c                   @   s"   e Zd ZdZddd„Zd	d
„ ZdS )Ú	ToolSubstzÓString-like class used to build regex substitution patterns for llvm
    tools.

    Handles things like adding word-boundary patterns, and filtering
    characters from the beginning an end of a tool name

    Nú.-^/\<ú-.FÚwarnc           
      C   sn   || _ || _|| _|dur|nt|ƒ| _d| _|r<|| _dS d	dd„}dd„ }	||dƒ|	|ƒ ||ƒ | _dS )
au  Construct a ToolSubst.

        key: The text which is to be substituted.

        command: The command to substitute when the key is matched.  By default,
        this will treat `key` as a tool name and search for it.  If it is
        a string, it is intereprted as an exact path.  If it is an instance of
        FindTool, the specified tool name is searched for on disk.

        pre: If specified, the substitution will not find matches where
        the character immediately preceding the word-boundary that begins
        `key` is any of the characters in the string `pre`.

        post: If specified, the substitution will not find matches where
        the character immediately after the word-boundary that ends `key`
        is any of the characters specified in the string `post`.

        verbatim: If True, `key` is an exact regex that is passed to the
        underlying substitution

        unresolved: Action to take if the tool substitution cannot be
        resolved.  Valid values:
            'warn' - log a warning but add the substitution anyway.
            'fatal' - Exit the test suite and log a fatal error.
            'break' - Don't add any of the substitutions from the current
                      group, and return a value indicating a failure.
            'ignore' - Don't add the substitution, and don't log an error

        extra_args: If specified, represents a list of arguments that will be
        appended to the tool's substitution.

        explicit_path: If specified, the exact path will be used as a substitution.
        Otherwise, the tool will be searched for as if by calling which(tool)

        NFÚ c                 S   s(   | sdS d  dd„ | D ƒ¡}d ||¡S )Nr   ú|c                 s   s   | ]}t  |¡V  qd S r   )ÚreÚescape)Ú.0Úxr   r   r   Ú	<genexpr>W   ó    z5ToolSubst.__init__.<locals>.not_in.<locals>.<genexpr>z
(?{}!({})))ÚjoinÚformat)ÚcharsÚwhereZpattern_strr   r   r   Únot_inT   s    z"ToolSubst.__init__.<locals>.not_inc                 S   s.   t  | ¡}| d¡}| d¡} |d |  d S )Né   é   z\b)Ú	wordifierÚmatchÚgroup)Úwordr-   Z
introducerr   r   r   ÚwordifyZ   s    


z#ToolSubst.__init__.<locals>.wordifyú<)r   )Ú
unresolvedÚ
extra_argsÚkeyr   r   Úwas_resolvedÚregex)
r   r4   r   ÚpreÚpostZverbatimr2   r3   r)   r0   r   r   r   r   &   s    %
zToolSubst.__init__c                 C   sú   t  | j¡}|sd S | d¡}| d¡}t| jtƒrD| j ||¡}n
t| jƒ}|rl| j	räd 
|g| j	 ¡}nx| jdkr¢|j d| d|  ¡ tj 
|jj|¡}nB| jdkrÆ|j d| d|  ¡ n| jdkrÒn| jd	kràd S d
‚|rîd| _| j||fS )Nr+   é   ú r   zDid not find z in %sÚfatalÚbreakÚignorez)Unexpected value for ToolSubst.unresolvedT)Úexprr-   r6   r.   Ú
isinstancer   r   r   Ústrr3   r%   r2   r
   Znoter   Úpathr   Zllvm_tools_dirr;   r5   )r   r   Zsearch_dirsZ
tool_matchZ	tool_pipeZ	tool_nameZcommand_strr   r   r   r   b   s<    



ÿÿ
ÿ

zToolSubst.resolve)Nr   r   Fr   N)r   r   r   Ú__doc__r   r   r   r   r   r   r      s
     ÿ
<r   )
r   r   Zlit.utilr   Úcompiler>   r,   Úobjectr   r   r   r   r   r   Ú<module>   s   

