
    xKg                        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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mZ d dlmZmZmZmZ d dlmZmZmZmZ d d	lmZ  ej>                         Z  G d
 de!      Z" e"dd d       Z#e G d de!             Z$e G d de!             Z% G d de!      Z& G d de!      Z' G d de%e'      Z( G d de(      Z) G d de)      Z* G d de(      Z+ G d de)      Z, G d d e)      Z- G d! d"e)      Z. G d# d$e)      Z/ G d% d&e)      Z0 G d' d(e)      Z1 G d) d*e)      Z2 G d+ d,e*      Z3 G d- d.e*      Z4 G d/ d0e*      Z5 G d1 d2e)      Z6 G d3 d4e)      Z7 G d5 d6e)      Z8 G d7 d8e*      Z9 G d9 d:e*      Z: G d; d<e*      Z; G d= d>e)      Z< G d? d@e)      Z= G dA dBe(      Z> G dC dDe)      Z? G dE dFe)      Z@ G dG dHe%e'      ZA G dI dJe%e'      ZB G dK dLe%e'      ZC G dM dNe%e'      ZD G dO dPe%e'      ZE G dQ dRe%      ZF G dS dTe%      ZG G dU dVe$      ZH G dW dXe$      ZI G dY dZe!      ZJ G d[ d\e%      ZK eK       ZLy)]    )defaultdictN)FunctionTypeBuiltinFunctionType)total_ordering)StringIO)errorsconfig)BINOPS_TO_OPERATORSINPLACE_BINOPS_TO_OPERATORSUNARY_BUITINS_TO_OPERATORSOPERATORS_TO_BUILTINS)NotDefinedErrorRedefinedErrorVerificationErrorConstantInferenceError)constsc                       e Zd ZdZ ej
                  d      ZddZd Zd Z	e
d        Zd Zd	 Zd
 Zd Zd Zd ZddZddZd Zy)LoczSource location

    zdef\s+(\w+)Nc                 J    || _         || _        || _        d| _        || _        y)z Arguments:
        filename - name of the file
        line - line in file
        col - column
        maybe_decorator - Set to True if location is likely a jit decorator
        N)filenamelinecollinesmaybe_decorator)selfr   r   r   r   s        Q/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/ir.py__init__zLoc.__init__   s(     !	
.    c                     t        |       t        |      ury| j                  |j                  k7  ry| j                  |j                  k7  ry| j                  |j                  k7  ryyNFT)typer   r   r   r   others     r   __eq__z
Loc.__eq__,   sM    :T%[(==ENN*599

"588uyy r   c                 &    | j                  |       S Nr$   r"   s     r   __ne__z
Loc.__ne__4       ;;u%%%r   c                 @     | |j                   |j                  d      S )NT)r   )r   firstlineno)clsfunc_ids     r   from_function_idzLoc.from_function_id7   s    7##W%8%8$OOr   c                 V    d| j                   d| j                  d| j                  dS )NzLoc(filename=z, line=z, col=))r   r   r   r   s    r   __repr__zLoc.__repr__;   s"    6:mm6:iiK 	Kr   c                     | j                   )| j                  d| j                  d| j                   dS | j                  d| j                  dS )Nz (:r0   )r   r   r   r1   s    r   __str__zLoc.__str__?   s8    88#'==$))TXXFF $tyy99r   c                     d }| j                         }t        |d | j                  dz
         D ]&  }|j                         j	                  d      s#|} |S  |S )N   def )	get_linesreversedr   strip
startswith)r   fn_namer   xs       r   _find_definitionzLoc._find_definitionE   s[     %Q/0A wwy##F+ 1 r   c                     | j                         }|r>| j                  j                  |j                               }|r|j	                         d   S y Nr   )r?   _defmatchermatchr;   groups)r   defnms      r   _raw_function_namezLoc._raw_function_nameR   sE    $$&  &&tzz|4Axxz!}$r   c                     | j                   (t        j                  | j                               | _         | j                   S r&   )r   	linecachegetlines	_get_pathr1   s    r   r9   zLoc.get_lines[   s/    ::"++DNN,<=DJzzr   c                     d }	 t         j                  j                  | j                        }|S # t        $ r- t         j                  j                  | j                        }Y |S w xY wr&   )ospathrelpathr   
ValueErrorabspath)r   rN   s     r   rK   zLoc._get_pathb   sY    	2 77??4==1D   	2 77??4==1D	2s   )/ 2A%$A%c                    | j                         }| j                  }| j                  rIdg|z   }|rA|r?d||   vr8t        d|      }|dz   }||| }d}t	        |      D ]  \  }	}
d|
v s|	} n ||z   }g }|r|dkD  rd }|t        d||z
        | }d}|D ]	  }
d|
v sd} |sUd }t        |d |dz
         D ]
  }
d|
v s|
} n |r3|j                  |        |
      }|j                  d	d
|z   z  dz          |rp|j                  |d d        |j                  t        j                  |d                 ||d         }|j                  d	|z  t        j                  d      z          |s|sd}n|dk  rd}t        j                  d      dz   }|| j                         |t        j                  dj                  |            fz  }|S )N r8   r   
   c                 x    d}t        j                  t        j                  t        |             D ]  }|dz  }	 |S )Nr   r7   )	itertools	takewhilestrisspace)stringspacesr>   s      r   count_spacesz#Loc.strformat.<locals>.count_spaces   s5    ",,S[[#f+FAaKF Gr   FTr7       z<source elided>
^z#<source missing, REPL/exec in use?>z<source line number missing>z
File "%s", line %d:z
%s)r9   r   r   max	enumerater:   appendextend
_termcolor	highlightindicater   rK   codejoin)r   	nlines_upr   use_linetmplinesmin_linemax_lineselectedindexidxr>   retr\   	def_foundr=   r[   errtmps                     r   	strformatzLoc.strformatp   s    99 te|HfHX4F&F q(+#b=#Hx8'1FC{ # 2 $e+ X\ SHy$89(CH IQ; $I 
 !%A"67A{"# 8 JJw')!_FJJsAJ/2EEF

8CR=)

://=> &hrl3

3<**=*=c*BBC ;Q4 !!"9:6AT^^%x1NOO
r   c                 <     t        |       | j                  ||      S )z9
        Return a new Loc with this line number.
        )r!   r   )r   r   r   s      r   with_linenozLoc.with_lineno   s     tDz$--s33r   c                 v    t         j                  j                  | j                        }|d| j                  S )z(
        Returns a short string
        r4   )rM   rN   basenamer   r   )r   shortfilenames     r   shortz	Loc.short   s+     ((7'33r   NF)   r&   )__name__
__module____qualname____doc__recompilerB   r   r$   r(   classmethodr.   r2   r5   r?   rG   r9   rK   rv   rx   r|    r   r   r   r      sn     "**^,K/& P PK:Qf44r   r   zunknown locationc                   ,    e Zd Z e       Zd Zd Zd Zy)SlotEqualityCheckMixinc                     t        |       t        |      u r-| j                  D ]  }t        | |      t        ||      k7  s y yyr    )r!   	__slots__getattr)r   r#   names      r   r$   zSlotEqualityCheckMixin.__eq__   sA    :e$4&'%*>>  ' r   c                 0    t        |       t        |      k  S r&   rX   r"   s     r   __le__zSlotEqualityCheckMixin.__le__   s    4yCJ&&r   c                     t        |       S r&   idr1   s    r   __hash__zSlotEqualityCheckMixin.__hash__       $xr   N)r   r   r   tupler   r$   r   r   r   r   r   r   r      s     I'r   r   c                   "    e Zd ZdZd Zd Zd Zy)EqualityCheckMixinz# Mixin for basic equality checking c                     t        |       t        |      u r-d } || j                        } ||j                        }||k(  ryy)Nc                 R    d}t        |       }|D ]  }|j                  |d         |S )N)locscope)dictpop)adictbaddr>   s       r   fixupz(EqualityCheckMixin.__eq__.<locals>.fixup   s,    &KAEE!TN r   TF)r!   __dict__)r   r#   r   d1d2s        r   r$   zEqualityCheckMixin.__eq__   sB    :e$ t}}%Bu~~&BRxr   c                 0    t        |       t        |      k  S r&   r   r"   s     r   r   zEqualityCheckMixin.__le__   s    4y3u:%%r   c                     t        |       S r&   r   r1   s    r   r   zEqualityCheckMixin.__hash__   r   r   N)r   r   r   r   r$   r   r   r   r   r   r   r      s    -&r   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)VarMapc                     i | _         y r&   _conr1   s    r   r   zVarMap.__init__  s	    	r   c                 T    || j                   v rt        |      || j                   |<   y r&   )r   r   )r   r   vars      r   definezVarMap.define  s&    499 &&!DIIdOr   c                 R    	 | j                   |   S # t        $ r t        |      w xY wr&   )r   KeyErrorr   r   r   s     r   getz
VarMap.get  s/    	(99T?" 	(!$''	(s    &c                     || j                   v S r&   r   r   s     r   __contains__zVarMap.__contains__  s    tyy  r   c                 ,    t        | j                        S r&   )lenr   r1   s    r   __len__zVarMap.__len__  s    499~r   c                 @    t        j                  | j                        S r&   )pprintpformatr   r1   s    r   r2   zVarMap.__repr__  s    ~~dii((r   c                 ,    t        | j                        S r&   )hashr   r1   s    r   r   zVarMap.__hash__  s    DIIr   c                 6    | j                   j                         S r&   )r   iterkeysr1   s    r   __iter__zVarMap.__iter__   s    yy!!##r   c                     t        |       t        |      u r5| j                  j                         |j                  j                         k(  S yr}   )r!   r   keysr"   s     r   r$   zVarMap.__eq__#  s6    :e$99>>#uzz'888r   c                 &    | j                  |       S r&   r'   r"   s     r   r(   zVarMap.__ne__)  r)   r   N)r   r   r   r   r   r   r   r   r2   r   r   r$   r(   r   r   r   r   r     s4    "(!)$&r   r   c                       e Zd ZdZy)AbstractRHSz{Abstract base class for anything that can be the RHS of an assignment.
    This class **does not** define any methods.
    N)r   r   r   r   r   r   r   r   r   -  s    r   r   c                       e Zd ZdZd Zd Zy)Instz-
    Base class for all IR instructions.
    c                     t         )zO
        List the variables used (read or written) by the instruction.
        )NotImplementedErrorr1   s    r   	list_varszInst.list_vars8  s
     "!r   c                    t        |t              r|gS t        |t              r|j                         S t        |t        t
        f      r+g }|D ]"  }|j                  | j                  |             $ |S t        |t              r9g }|j                         D ]"  }|j                  | j                  |             $ |S g S )zQ
        A recursive helper used to implement list_vars() in subclasses.
        )

isinstanceVarr   r   listr   rd   _rec_list_varsr   values)r   vallstvs       r   r   zInst._rec_list_vars>  s     c35LT"==?"dE]+C

4..q12 JT"CZZ\

4..q12 "JIr   N)r   r   r   r   r   r   r   r   r   r   r   3  s    "r   r   c                       e Zd ZdZdZdZd Zy)Stmtzc
    Base class for IR statements (instructions which can appear on their
    own in a Block).
    Fc                 8    | j                  | j                        S r&   )r   r   r1   s    r   r   zStmt.list_vars_  s    ""4==11r   N)r   r   r   r   is_terminatoris_exitr   r   r   r   r   r   T  s     MG2r   r   c                       e Zd ZdZdZd Zy)
Terminatorz
    IR statements that are terminators: the last statement in a block.
    A terminator must either:
    - exit the function
    - jump to a block

    All subclass of Terminator must override `.get_targets()` to return a list
    of jump targets.
    Tc                 *    t        t        |             r&   )r   r!   r1   s    r   get_targetszTerminator.get_targetso  s    !$t*--r   N)r   r   r   r   r   r   r   r   r   r   r   c  s     M.r   r   c                      e Zd ZdZd Zd Zd Zed        Zed        Z	ed        Z
ed d	       Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zd Zd Z d Z!y)!Exprz]
    An IR expression (an instruction which can only be part of a larger
    statement).
    c                 v    t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   rX   r   opr   _kws)r   r   r   kwss       r   r   zExpr.__init__y  s7    "c"""#s###	r   c                 n    |j                  d      rt        j                  | |      S | j                  |   S )N_)r<   r   __getattr__r   r   s     r   r   zExpr.__getattr__  s/    ??3##D$//yyr   c                 J    |dv r|| j                   |<   y || j                  |<   y )N)r   r   r   )r   r   )r   r   values      r   __setattr__zExpr.__setattr__  s&    (("'DMM$#DIIdOr   c           	          t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ d} | |||||t        t              S )Nbinop)r   r   fnlhsrhs
static_lhs
static_rhsr   r   r   r   	UNDEFINED)r,   r   r   r   r   r   s         r   r   z
Expr.binop  sd    "1222#s####s####s###bcbcs'I? 	?r   c           
          t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ d} | ||||||t        t              S )Ninplace_binop)r   r   r   immutable_fnr   r   r   r   r   )r,   r   r   r   r   r   r   s          r   r   zExpr.inplace_binop  sx    "1222,(;<<<#s####s####s###bcb|'I? 	?r   c                     t        |t        t        t        f      sJ t        |t              sJ d}t        j                  ||      } | ||||      S )Nunary)r   r   r   r   )r   rX   r   r   r   r   r   )r,   r   r   r   r   s        r   r   z
Expr.unary  sQ    %#sL!9:::#s###'++B3bcb66r   Nc           
      n    t        |t              sJ t        |t              sJ d} | ||||||||      S )Ncall)r   r   funcargsr   varargvarkwargtargetr   r   r   )	r,   r   r   r   r   r   r   r   r   s	            r   r   z	Expr.call  sG    $$$$#s###bc4S 8FD 	Dr   c                 @    t        |t              sJ d} | |||      S )Nbuild_tupler   r   itemsr   r   r,   r  r   r   s       r   r   zExpr.build_tuple  s&    #s###bc//r   c                 @    t        |t              sJ d} | |||      S )N
build_listr   r  r  s       r   r  zExpr.build_list  s&    #s###bc//r   c                 @    t        |t              sJ d} | |||      S )N	build_setr   r  r  s       r   r  zExpr.build_set  s&    #s###bc//r   c                 F    t        |t              sJ d} | ||||||      S )N	build_map)r   r   r  sizeliteral_valuevalue_indexesr  )r,   r  r
  r  r  r   r   s          r   r	  zExpr.build_map  s3    #s###bcT!.mM 	Mr   c                 @    t        |t              sJ d} | |||      S )N
pair_firstr   r   r   r   r   r,   r   r   r   s       r   r  zExpr.pair_first  s&    %%%%bc//r   c                 d    t        |t              sJ t        |t              sJ d} | |||      S )Npair_secondr  r   r  s       r   r  zExpr.pair_second  s6    %%%%#s###bc//r   c                 d    t        |t              sJ t        |t              sJ d} | |||      S )Ngetiterr  r   r  s       r   r  zExpr.getiter  s6    %%%%#s###bc//r   c                 d    t        |t              sJ t        |t              sJ d} | |||      S )Niternextr  r   r  s       r   r  zExpr.iternext  s6    %%%%#s###bc//r   c                     t        |t              sJ t        |t              sJ t        |t              sJ d} | ||||      S )Nexhaust_iter)r   r   r   count)r   r   intr   )r,   r   r  r   r   s        r   r  zExpr.exhaust_iter  sH    %%%%%%%%#s###bce<<r   c                     t        |t              sJ t        |t              sJ t        |t              sJ d} | ||||      S )Nr   )r   r   r   attr)r   r   rX   r   )r,   r   r  r   r   s        r   r   zExpr.getattr  sH    %%%%$$$$#s###bcT::r   c                     t        |t              sJ t        |t              sJ t        |t              sJ d}t        j                  } | |||||      S )Ngetitem)r   r   r   rp   r   r   r   r   operatorr  )r,   r   rp   r   r   r   s         r   r  zExpr.getitem  sU    %%%%%%%%#s###bceCCr   c                 h    t        |t              sJ t        |t              sJ d} | |||||      S )Ntyped_getitem)r   r   r   dtyperp   r   )r,   r   r$  rp   r   r   s         r   r#  zExpr.typed_getitem  s?    %%%%#s###bce  	 r   c                     t        |t              sJ |t        |t              sJ t        |t              sJ d}t        j                  } | ||||||      S )Nstatic_getitem)r   r   r   rp   	index_varr   r   )r,   r   rp   r'  r   r   r   s          r   r&  zExpr.static_getitem  sa    %%%% Jy#$>>>#s###bce&2/ 	/r   c                 d    t        |t              sJ t        |t              sJ d} | |||      S )zE
        A node for implicit casting at the return statement
        cast)r   r   r   r   r  s       r   r)  z	Expr.cast  s8    
 %%%%#s###b3//r   c                 >    t        |t              sJ  | dg g |      S )zPhi node
        phi)r   incoming_valuesincoming_blocksr   r  )r,   r   s     r   r+  zExpr.phi  s%     #s###eRMMr   c                 F    t        |t              sJ d} | ||||||      S )z6
        A node for making a function object.
        make_function)r   r   rh   closuredefaultsr   r  )r,   r   rh   r0  r1  r   r   s          r   r/  zExpr.make_function!  s/    
 #s###bt$(X[\\r   c                 >    t        |t              sJ d} | ||      S )z
        A node for null value.

        This node is not handled by type inference. It is only added by
        post-typing passes.
        nullr   r   r  r,   r   r   s      r   r3  z	Expr.null*  s&     #s###bc""r   c                 >    t        |t              sJ d} | ||      S )zZ
        A node for undefined value specifically from LOAD_FAST_AND_CLEAR opcode.
        undefr4  r  r5  s      r   r7  z
Expr.undef6  s&    
 #s###bc""r   c                 `    t        |t              sJ t        |t              sJ  | |||      S )a8  
        A node for a dummy value.

        This node is a place holder for carrying information through to a point
        where it is rewritten into something valid. This node is not handled
        by type inference or lowering. It's presence outside of the interpreter
        renders IR as illegal.
        )r   infor   )r   r   rX   )r,   r   r9  r   s       r   dummyz
Expr.dummy?  s3     #s###"c"""bt--r   c                    | j                   dk(  rdj                  d | j                  D              }t        j                  dk(  r| j
                  j                         n"t        | j
                  j                               }dj                  d |D              }| j                  d| j                  nd}dj                  t        d |||g            }d| j                  d	|d
S | j                   dk(  rm| j                  | j                  }}| j                  t        j                  k(  r||}}t!        j"                  | j                  | j                        }|d|d|S t        j                  dk(  r| j
                  j                         n"t        | j
                  j                               }d |D        }| j                   d	dj                  |      d
S )Nr   , c              3   2   K   | ]  }t        |        y wr&   r   ).0as     r   	<genexpr>z Expr.__repr__.<locals>.<genexpr>O  s     7YSVY   r   c              3   0   K   | ]  \  }}|d |  yw=Nr   r>  kr   s      r   r@  z Expr.__repr__.<locals>.<genexpr>Q  s     DAq!,   *rS   zcall (r0   r   r]   c              3   0   K   | ]  \  }}|d |  ywrC  r   rE  s      r   r@  z Expr.__repr__.<locals>.<genexpr>]  s     <Aq!$rG  )r   ri   r   r	   DIFF_IRr   r  sortedr   filterr   r   r   r   r!  containsr   r   )	r   r   
pres_orderr   r   arglistr   r   r   s	            r   r2   zExpr.__repr__M  sV   77f997TYY77D.4nn.A*vdiiooN_G`J))DDDC/3{{/Fdkk+BFiitdFC-@ ABG$(IIw77WWxxCww(+++S&**477DGG<B!$b#...4nn.A*vdiiooN_G`J<<D#ww		$88r   c                 8    | j                  | j                        S r&   )r   r   r1   s    r   r   zExpr.list_vars`  s    ""499--r   c                 6    t        d| z  | j                        Nz%sr   r   r   r1   s    r   infer_constantzExpr.infer_constantc      $TD[dhh??r   )NNN)"r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r   r  r#  r&  r)  r+  r/  r3  r7  r:  r2   r   rV  r   r   r   r   r   s  s   

$ ? ? 	? 	? 7 7 D D 0 0
 0 0
 0 0
 M M 0 0
 0 0 0 0 0 0 = = ; ; D D     / / 0 0 N N ] ] 	# 	# # # . .9&.@r   r   c                       e Zd ZdZd Zd Zy)SetItemz
    target[index] = value
    c                     t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        || _        y r&   )r   r   r   r   rp   r   r   )r   r   rp   r   r   s        r   r   zSetItem.__init__l  s^    &#&&&%%%%%%%%#s###

r   c                 R    | j                   d| j                  d| j                  S N[z] = r   rp   r   r1   s    r   r2   zSetItem.__repr__v       $TZZDDr   Nr   r   r   r   r   r2   r   r   r   rY  rY  g  s    Er   rY  c                       e Zd ZdZd Zd Zy)StaticSetItemz(
    target[constant index] = value
    c                     t        |t              sJ t        |t              rJ t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        || _        || _        y r&   )r   r   r   r   rp   r'  r   r   )r   r   rp   r'  r   r   s         r   r   zStaticSetItem.__init__  su    &#&&&eS))))S)))%%%%#s###
"
r   c                 R    | j                   d| j                  d| j                  S r\  r^  r1   s    r   r2   zStaticSetItem.__repr__  r_  r   Nr`  r   r   r   rb  rb  z  s    
Er   rb  c                       e Zd ZdZd Zd Zy)DelItemz
    del target[index]
    c                     t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   r   r   r   rp   r   )r   r   rp   r   s       r   r   zDelItem.__init__  sG    &#&&&%%%%#s###
r   c                 <    d| j                   d| j                  dS )Nzdel r]  ])r   rp   r1   s    r   r2   zDelItem.__repr__  s    #{{DJJ77r   Nr`  r   r   r   rf  rf    s    8r   rf  c                       e Zd Zd Zd Zy)SetAttrc                     t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        || _        y r&   )r   r   rX   r   r   r  r   r   )r   r   r  r   r   s        r   r   zSetAttr.__init__  s^    &#&&&$$$$%%%%#s###	
r   c                 T    d| j                   d| j                  d| j                  S )NrI  ). = )r   r  r   r1   s    r   r2   zSetAttr.__repr__  s    !%diiDDr   Nr   r   r   r   r2   r   r   r   rk  rk    s    Er   rk  c                       e Zd Zd Zd Zy)DelAttrc                     t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   r   rX   r   r   r  r   )r   r   r  r   s       r   r   zDelAttr.__init__  sG    &#&&&$$$$#s###	r   c                 :    d| j                   d| j                  S )Nzdel (rn  )r   r  r1   s    r   r2   zDelAttr.__repr__  s     $TYY77r   Nrp  r   r   r   rr  rr    s    8r   rr  c                       e Zd Zd Zd Zy)StoreMapc                     t        |t              sJ t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        || _        y r&   )r   r   r   dctkeyr   r   )r   rx  ry  r   r   s        r   r   zStoreMap.__init__  s^    #s####s###%%%%#s###
r   c                 R    | j                   d| j                  d| j                  S r\  )rx  ry  r   r1   s    r   r2   zStoreMap.__repr__  s     $$((DJJ??r   Nrp  r   r   r   rv  rv    s    @r   rv  c                       e Zd Zd Zd Zy)Delc                 h    t        |t              sJ t        |t              sJ || _        || _        y r&   )r   rX   r   r   r   r   r   r   s      r   r   zDel.__init__  s0    %%%%#s###
r   c                      d| j                   z  S )Nzdel %sr   r1   s    r   r5   zDel.__str__  s    $**$$r   N)r   r   r   r   r5   r   r   r   r|  r|    s    %r   r|  c                   "    e Zd ZdZd Zd Zd Zy)RaiseTc                 l    |t        |t              sJ t        |t              sJ || _        || _        y r&   r   r   r   	exceptionr   r   r  r   s      r   r   zRaise.__init__  5     Jy#$>>>#s###"r   c                      d| j                   z  S )Nzraise %sr  r1   s    r   r5   zRaise.__str__  s    DNN**r   c                     g S r&   r   r1   s    r   r   zRaise.get_targets      	r   N)r   r   r   r   r   r5   r   r   r   r   r  r    s    G+r   r  c                   &    e Zd ZdZdZd Zd Zd Zy)StaticRaisez
    Raise an exception class and arguments known at compile-time.
    Note that if *exc_class* is None, a bare "raise" statement is implied
    (i.e. re-raise the current exception).
    Tc                     |t        |t              sJ t        |t              sJ |t        |t              sJ || _        || _        || _        y r&   r   r!   r   r   	exc_classexc_argsr   r   r  r  r   s       r   r   zStaticRaise.__init__  Q     Jy$$???#s###:h#>>>" r   c           	          | j                   y| j                  d| j                   S d| j                   ddj                  t        t        | j                              dS )Nz<static> raisez<static> raise rI  r<  r0   r  r  ri   mapreprr1   s    r   r5   zStaticRaise.__str__  sW    >>!#]]"*...:: # /3nn%)YYs4/G%HJ Jr   c                     g S r&   r   r1   s    r   r   zStaticRaise.get_targets  r  r   Nr   r   r   r   r   r   r5   r   r   r   r   r  r        
 GJr   r  c                   &    e Zd ZdZdZd Zd Zd Zy)DynamicRaisez
    Raise an exception class and some argument *values* unknown at compile-time.
    Note that if *exc_class* is None, a bare "raise" statement is implied
    (i.e. re-raise the current exception).
    Tc                     |t        |t              sJ t        |t              sJ |t        |t              sJ || _        || _        || _        y r&   r  r  s       r   r   zDynamicRaise.__init__  r  r   c           	          | j                   y| j                  d| j                   S d| j                   ddj                  t        t        | j                              dS )Nz<dynamic> raisez<dynamic> raise rI  r<  r0   r  r1   s    r   r5   zDynamicRaise.__str__  sW    >>!$]]"+/>>;; # 04~~%)YYs4/G%HJ Jr   c                     g S r&   r   r1   s    r   r   zDynamicRaise.get_targets  r  r   Nr  r   r   r   r  r    r  r   r  c                       e Zd ZdZd Zd Zy)TryRaisezZA raise statement inside a try-block
    Similar to ``Raise`` but does not terminate.
    c                 l    |t        |t              sJ t        |t              sJ || _        || _        y r&   r  r  s      r   r   zTryRaise.__init__$  r  r   c                      d| j                   z  S )Nztry_raise %sr  r1   s    r   r5   zTryRaise.__str__*  s    ..r   Nr   r   r   r   r   r5   r   r   r   r  r     s    /r   r  c                       e Zd ZdZd Zd Zy)StaticTryRaisezaA raise statement inside a try-block.
    Similar to ``StaticRaise`` but does not terminate.
    c                     |t        |t              sJ t        |t              sJ |t        |t              sJ || _        || _        || _        y r&   r  r  s       r   r   zStaticTryRaise.__init__2  r  r   c                     | j                   y| j                  d| j                    S dj                  t        t        | j                              }d| j                    d| dS )Nstatic_try_raisezstatic_try_raise r<  rI  r0   r  r   r   s     r   r5   zStaticTryRaise.__str__:  s^    >>!&]]"&t~~&67799St}}56D&t~~&6avQ??r   Nr  r   r   r   r  r  .  s    @r   r  c                       e Zd ZdZd Zd Zy)DynamicTryRaisezbA raise statement inside a try-block.
    Similar to ``DynamicRaise`` but does not terminate.
    c                     |t        |t              sJ t        |t              sJ |t        |t              sJ || _        || _        || _        y r&   r  r  s       r   r   zDynamicTryRaise.__init__H  r  r   c                     | j                   y| j                  d| j                    S dj                  t        t        | j                              }d| j                    d| dS )Ndynamic_try_raisezdynamic_try_raise r<  rI  r0   r  r  s     r   r5   zDynamicTryRaise.__str__P  s^    >>!']]"''78899St}}56D''7qa@@r   Nr  r   r   r   r  r  D  s    Ar   r  c                   &    e Zd ZdZdZd Zd Zd Zy)Returnz
    Return to caller.
    Tc                     t        |t              sJ t        |             t        |t              sJ || _        || _        y r&   )r   r   r!   r   r   r   r~  s      r   r   zReturn.__init__`  s9    %%2tE{2%#s###
r   c                      d| j                   z  S )Nz	return %sr  r1   s    r   r5   zReturn.__str__f  s    TZZ''r   c                     g S r&   r   r1   s    r   r   zReturn.get_targetsi  r  r   Nr  r   r   r   r  r  Z  s     G(r   r  c                   "    e Zd ZdZd Zd Zd Zy)Jumpz
    Unconditional branch.
    c                 D    t        |t              sJ || _        || _        y r&   )r   r   r   r   )r   r   r   s      r   r   zJump.__init__r  s     #s###r   c                      d| j                   z  S )Nzjump %sr   r1   s    r   r5   zJump.__str__w  s    4;;&&r   c                     | j                   gS r&   r  r1   s    r   r   zJump.get_targetsz  s    }r   Nr   r   r   r   r   r5   r   r   r   r   r  r  m  s    
'r   r  c                   "    e Zd ZdZd Zd Zd Zy)Branchz
    Conditional branch.
    c                     t        |t              sJ t        |t              sJ || _        || _        || _        || _        y r&   )r   r   r   condtruebrfalsebrr   )r   r  r  r  r   s        r   r   zBranch.__init__  s>    $$$$#s###	r   c                 T    d| j                   d| j                  d| j                  S )Nzbranch r<  )r  r  r  r1   s    r   r5   zBranch.__str__  s    &*iidllKKr   c                 2    | j                   | j                  gS r&   )r  r  r1   s    r   r   zBranch.get_targets  s    T\\**r   Nr  r   r   r   r  r  ~  s    L+r   r  c                       e Zd ZdZd Zd Zy)Assignz
    Assign to a variable.
    c                     t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   r   r   r   r   r   r   )r   r   r   r   s       r   r   zAssign.__init__  sG    %---&#&&&#s###
r   c                 8    | j                   d| j                  S )Nro  )r   r   r1   s    r   r5   zAssign.__str__  s     KK44r   Nr  r   r   r   r  r    s    5r   r  c                       e Zd ZdZd Zd Zy)Printz
    Print some values.
    c                     t        d |D              sJ |t        |t              sJ t        |t              sJ t	        |      | _        || _        i | _        || _        y )Nc              3   <   K   | ]  }t        |t                y wr&   r  )r>  r>   s     r   r@  z!Print.__init__.<locals>.<genexpr>  s     4t!:a%ts   )	allr   r   r   r   r   r   r   r   )r   r   r   r   s       r   r   zPrint.__init__  sZ    4t4444~FC!888#s###$K	r   c                 L    ddj                  d | j                  D              z  S )Nz	print(%s)r<  c              3   2   K   | ]  }t        |        y wr&   r   r>  r   s     r   r@  z Print.__str__.<locals>.<genexpr>  s     &Ay!s1vyrA  )ri   r   r1   s    r   r5   zPrint.__str__  s     TYY&Atyy&AAAAr   Nr  r   r   r   r  r    s    Br   r  c                       e Zd Zd Zd Zd Zy)Yieldc                 v    t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   r   r   r   r   rp   )r   r   r   rp   s       r   r   zYield.__init__  s7    %%%%#s###

r   c                      d| j                   S )Nzyield r  r1   s    r   r5   zYield.__str__  s    !ZZ))r   c                     | j                   gS r&   r  r1   s    r   r   zYield.list_vars  s    

|r   N)r   r   r   r   r5   r   r   r   r   r  r    s    *r   r  c                   "    e Zd ZdZd Zd Zd Zy)	EnterWithzEnter a "with" context
    c                     t        |t              sJ t        |t              sJ || _        || _        || _        || _        y)z
        Parameters
        ----------
        contextmanager : IR value
        begin, end : int
            The beginning and the ending offset of the with-body.
        loc : ir.Loc instance
            Source location
        N)r   r   r   contextmanagerbeginendr   )r   r  r  r  r   s        r   r   zEnterWith.__init__  sA     .#...#s###,
r   c                 8    dj                  | j                        S )Nzenter_with {})formatr  r1   s    r   r5   zEnterWith.__str__  s    %%d&9&9::r   c                     | j                   gS r&   )r  r1   s    r   r   zEnterWith.list_vars  s    ##$$r   N)r   r   r   r   r   r5   r   r   r   r   r  r    s    ";%r   r  c                       e Zd ZdZd Zd Zy)PopBlockz(Marker statement for a pop block op codec                 6    t        |t              sJ || _        y r&   )r   r   r   )r   r   s     r   r   zPopBlock.__init__  s    #s###r   c                      y)N	pop_blockr   r1   s    r   r5   zPopBlock.__str__      r   Nr  r   r   r   r  r    s    2r   r  c                       e Zd Zd Zd Zd Zy)Argc                     t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   rX   r  r   r   rp   r   )r   r   rp   r   s       r   r   zArg.__init__  sG    $$$$%%%%#s###	
r   c                 8    d| j                   | j                  fz  S )Nzarg(%d, name=%s))rp   r   r1   s    r   r2   zArg.__repr__  s    !TZZ$;;;r   c                 6    t        d| z  | j                        rS  rU  r1   s    r   rV  zArg.infer_constant  rW  r   N)r   r   r   r   r2   rV  r   r   r   r  r    s    <@r   r  c                   &    e Zd ZddZd Zd Zd Zy)Constc                 R    t        |t              sJ || _        || _        || _        y r&   )r   r   r   r   use_literal_type)r   r   r   r  s       r   r   zConst.__init__  s(    #s###
 0r   c                 b    dt        | j                        j                  d| j                  dS )Nzconst(r<  r0   )r!   r   r   r1   s    r   r2   zConst.__repr__   s     "&tzz"2";";TZZHHr   c                     | j                   S r&   r  r1   s    r   rV  zConst.infer_constant      zzr   c                 Z    t        | j                  | j                  | j                        S )N)r   r   r  )r  r   r   r  r   memos     r   __deepcopy__zConst.__deepcopy__  s%    **$((!22
 	
r   NT)r   r   r   r   r2   rV  r  r   r   r   r  r    s    1I
r   r  c                   $    e Zd Zd Zd Zd Zd Zy)Globalc                 R    t        |t              sJ || _        || _        || _        y r&   )r   r   r   r   r   )r   r   r   r   s       r   r   zGlobal.__init__  s'    #s###	
r   c                 <    d| j                   d| j                  dS )Nzglobal(: r0   r   r   r1   s    r   r5   zGlobal.__str__  s    #'99djj99r   c                     | j                   S r&   r  r1   s    r   rV  zGlobal.infer_constant  r  r   c                 ~    t        | j                  | j                  t        j                  | j
                              S r&   )r  r   r   copydeepcopyr   r  s     r   r  zGlobal.__deepcopy__  s(     diiT]]488-DEEr   N)r   r   r   r   r5   rV  r  r   r   r   r  r    s    :Fr   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)FreeVarzm
    A freevar, as loaded by LOAD_DECREF.
    (i.e. a variable defined in an enclosing non-global scope)
    c                     t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        || _        y r&   )r   r  rX   r   rp   r   r   r   )r   rp   r   r   r   s        r   r   zFreeVar.__init__'  sN    %%%%$$$$#s###
	
r   c                 <    d| j                   d| j                  dS )Nzfreevar(r  r0   r  r1   s    r   r5   zFreeVar.__str__3  s    $(IItzz::r   c                     | j                   S r&   r  r1   s    r   rV  zFreeVar.infer_constant6  r  r   c                 p    t        | j                  | j                  | j                  | j                        S )N)rp   r   r   r   )r   rp   r   r   r   r  s     r   r  zFreeVar.__deepcopy__9  s(    TZZdiitzz88% 	%r   N)r   r   r   r   r   r5   rV  r  r   r   r   r   r   !  s    

;%r   r   c                   h    e Zd ZdZd Zd Zd Zed        Zed        Z	ed        Z
ed        Zd	 Zy
)r   zt
    Attributes
    -----------
    - scope: Scope

    - name: str

    - loc: Loc
        Definition location
    c                     |t        |t              sJ t        |t              sJ t        |t              sJ || _        || _        || _        y r&   )r   ScoperX   r   r   r   r   )r   r   r   r   s       r   r   zVar.__init__L  sK    }
5% 888$$$$#s###
	r   c                 X    d| j                   d| j                  j                         dS )NzVar(r<  r0   )r   r   r|   r1   s    r   r2   zVar.__repr__U  s     $		488>>+;<<r   c                     | j                   S r&   )r   r1   s    r   r5   zVar.__str__X  s    yyr   c                 8    | j                   j                  d      S )N$)r   r<   r1   s    r   is_tempzVar.is_temp[  s    yy##C((r   c                     | j                   j                  j                         D ]  \  }}| j                  |v s|c S  | j                  S )zIThe unversioned name of this variable, i.e. SSA renaming removed
        )r   var_redefinitionsr  r   )r   rF  	redef_sets      r   unversioned_namezVar.unversioned_name_  sC     !JJ88>>@LAyyyI% A yyr   c                 L    | j                   j                  | j                        S )zKnown versioned names for this variable, i.e. known variable names in
        the scope that have been formed from applying SSA to this variable
        )r   get_versions_ofr  r1   s    r   versioned_nameszVar.versioned_namesh  s    
 zz))$*?*?@@r   c                 6    | j                   | j                  hz  S )zDAll known versioned and unversioned names for this variable
        )r  r  r1   s    r   	all_nameszVar.all_nameso  s     ##t'<'<&>>>r   c                     t        t        j                  | j                  |      | j                  | j
                        }||t        |       <   |S r&   )r   r  r  r   r   r   r   )r   r  outs      r   r  zVar.__deepcopy__u  s9    $--

D1499dhhGRX
r   N)r   r   r   r   r   r2   r5   propertyr  r  r  r  r  r   r   r   r   r   @  sm    	= ) )   A A ? ?
r   r   c                   X    e Zd ZdZd Zd Zd Zd Zd ZddZ	d Z
d	 Zed
        Zd Zy)r  z
    Attributes
    -----------
    - parent: Scope
        Parent scope

    - localvars: VarMap
        Scope-local variable map

    - loc: Loc
        Start of scope location

    c                     |t        |t              sJ t        |t              sJ || _        t	               | _        || _        t        t              | _	        t        t              | _        y r&   )r   r  r   parentr   	localvarsr   r   r  	redefinedsetr  )r   r  r   s      r   r   zScope.__init__  sV    ~FE!:::#s###$S)!,S!1r   c                 n    t        | ||      }| j                  j                  |j                  |       |S )z#
        Define a variable
        r   r   r   )r   r  r   r   )r   r   r   r   s       r   r   zScope.define  s/     d3/affa(r   c                 h    || j                   v rd|| j                   |   fz  }| j                  |      S )zC
        Refer to a variable.  Returns the latest version.
        %s.%d)r  	get_exactr   s     r   r   z	Scope.get  s7     4>>!dDNN4$899D~~d##r   c                     	 | j                   j                  |      S # t        $ r+ | j                  r| j                  j                  |      cY S  w xY w)zr
        Refer to a variable.  The returned variable has the exact
        name (exact variable version).
        )r  r   r   
has_parentr  r   s     r   r#  zScope.get_exact  sH    
	>>%%d++ 	{{t,,		s    0AAc                     || j                   v rd|| j                   |   fz  }|| j                  vr| j                  ||      S | j                  j                  |      S )Nr"  )r  r  r   r   )r   r   r   s      r   get_or_definezScope.get_or_define  sX    4>>!dDNN4$899Dt~~%;;tS))>>%%d++r   c                 X   || j                   vr| j                  ||      S |s| j                   j                  |      S 	 | j                  |   }|dz   | j                  |<   d||dz   fz  }	 | j                  ||      }| j                  |   j                  |       |S # t        $ r Y jw xY w)z9
        Redefine if the name is already defined
        r7   r"  )r  r   r   r  r  addr   )r   r   r   renamectnewnameress          r   redefinezScope.redefine  s     t~~%;;tS)) >>%%d++^^D)')Avt$!T26N2>++gs3C **4044W=
	 & s   +B 	B)(B)c                 >     t                fd |       S )z9
        Gets all known versions of a given name
        c                     j                   j                  | d       }|r!|D ]  }j                  |        |        y y r&   )r  r   r)  )thenameredefsr   r   verswalks      r   r4  z#Scope.get_versions_of.<locals>.walk  s?    ++//>FAHHQKG   r   )r  )r   r   r3  r4  s   ` @@r   r  zScope.get_versions_of  s     u	 	T
r   c                     t        | j                        }t        | d|z  |      }| j                  j                  |j                  |       |S )Nz$%dr   )r   r  r   r   r   )r   r   nr   s       r   	make_tempzScope.make_temp  s?    d4affa(r   c                     | j                   d uS r&   )r  r1   s    r   r%  zScope.has_parent  s    {{$&&r   c                 `    d| j                   t        | j                        | j                  fz  S )Nz%Scope(has_parent=%r, num_vars=%d, %s))r%  r   r  r   r1   s    r   r2   zScope.__repr__  s0    6$//:=dnn:M:>((:D D 	Dr   Nr  )r   r   r   r   r   r   r   r#  r'  r.  r  r7  r  r%  r2   r   r   r   r  r  {  sI    2$,. ' 'Dr   r  c                       e Zd ZdZd Zd ZddZddZd Zd Z	d	 Z
d
 Zd ZddZed        Zed        Zd Zd Zd Zd Zy)BlockzA code block

    c                 v    t        |t              sJ t        |t              sJ || _        g | _        || _        y r&   )r   r  r   r   bodyr   )r   r   r   s      r   r   zBlock.__init__  s7    %'''#s###
	r   c                 n    t        | j                  | j                        }| j                  d d  |_        |S r&   )r;  r   r   r=  r   blocks     r   r  z
Block.copy  s*    djj$((+YYq\
r   Nc              #      K   | j                   D ]F  }t        |t              s|j                  }t        |t              s1||j
                  |k(  sC| H yw)zE
        Iterate over exprs of the given *op* in this block.
        N)r=  r   r  r   r   r   )r   r   instexprs       r   
find_exprszBlock.find_exprs  sG      IID$'zzdD)zTWW]"
 s    AA AAc              #   P   K   | j                   D ]  }t        ||      s|  yw)zF
        Iterate over insts of the given class in this block.
        N)r=  r   )r   r,   rB  s      r   
find_instszBlock.find_insts
  s%      IID$$
 s   &&c                 t    | j                  t              D ]  }|j                  j                  |k(  s|c S  y)zr
        Returns the assignment inst associated with variable "name", None if
        it cannot be found.
        )r,   N)rF  r  r   r   )r   r   r>   s      r   find_variable_assignmentzBlock.find_variable_assignment  s3    
 V,Axx}}$ - r   c                 `    t        |t              sJ | j                  j                  d|       y rA   )r   r   r=  insertr   rB  s     r   prependzBlock.prepend  s&    $%%%		D!r   c                 ^    t        |t              sJ | j                  j                  |       y r&   )r   r   r=  rc   rK  s     r   rc   zBlock.append   s$    $%%%		r   c                 t    t        |t              sJ | j                  | j                  j                  |      = y r&   )r   r   r=  rp   rK  s     r   removezBlock.remove$  s+    $%%%IIdiiood+,r   c                 "    | j                   d d = y r&   r=  r1   s    r   clearzBlock.clear(  s    IIaLr   c                     |xs t         j                  }| j                  D ]T  }t        |d      r|j	                  |       !t        d |j                         D              }t        d|dd||       V y )Ndumpc              3   2   K   | ]  }t        |        y wr&   r   r  s     r   r@  zBlock.dump.<locals>.<genexpr>2  s     "D3Ca3q63CrA  z    40r]   file)sysstdoutr=  hasattrrT  rL  r   print)r   rX  rB  	inst_varss       r   rT  z
Block.dump+  sY    !szzIIDtV$		$""D4>>3C"DD	i8tD r   c                      | j                   d   S Nr_   rQ  r1   s    r   
terminatorzBlock.terminator5  s    yy}r   c                 P    | j                   xr | j                   d   j                  S r_  )r=  r   r1   s    r   is_terminatedzBlock.is_terminated9  s    yy8TYYr]888r   c                     | j                   st        d      | j                  d d D ]  }|j                  st        d       y )NzMissing block terminatorr_   z&Terminator before the last instruction)rb  r   r=  r   rK  s     r   verifyzBlock.verify=  sF    !!#$>??IIcrND!!' )6 7 7 #r   c                 x    | j                   j                  |      }| j                   j                  |dz   |       y)z.
        Insert *stmt* after *other*.
        r7   N)r=  rp   rJ  )r   stmtr#   rp   s       r   insert_afterzBlock.insert_afterF  s.     		&		D)r   c                 |    t        |t              sJ | j                  sJ | j                  j	                  d|       y r_  )r   r   rb  r=  rJ  )r   rf  s     r   insert_before_terminatorzBlock.insert_before_terminatorM  s5    $%%%!!!!		T"r   c                 "    d| j                   dS )Nz<ir.Block at >rT  r1   s    r   r2   zBlock.__repr__R  s    %)XX//r   r&   )r   r   r   r   r   r  rD  rF  rH  rL  rc   rO  rR  rT  r  r`  rb  rd  rg  ri  r2   r   r   r   r;  r;    sv    
	#"-E   9 97*#
0r   r;  c                        e Zd ZdZdZd Zd Zy)LoopzDescribes a loop-block
    entryexitc                      || _         || _        y r&   rn  r   ro  rp  s      r   r   zLoop.__init__[      
	r   c                 <    | j                   | j                  f}d|z  S )NzLoop(entry=%s, exit=%s)rn  r  s     r   r2   zLoop.__repr___      zz499$(4//r   Nr   r   r   r   r   r   r2   r   r   r   rm  rm  V      I0r   rm  c                        e Zd ZdZdZd Zd Zy)WithzDescribes a with-block
    rn  c                      || _         || _        y r&   rn  rr  s      r   r   zWith.__init__i  rs  r   c                 <    | j                   | j                  f}d|z  S )NzWith(entry=%s, exit=%s)rn  r  s     r   r2   zWith.__repr__m  ru  r   Nrv  r   r   r   ry  ry  d  rw  r   ry  c                   p    e Zd Zd Zd Zd Zd Z	 	 ddZd Zd Z	d	 Z
dd
ZddZddZd ZddZddZy)
FunctionIRc                     || _         || _        || _        || _        || _        || _        || _        | j                          y r&   )blocksis_generatorr-   r   	arg_count	arg_names_definitions_reset_analysis_variables)r   r  r  r-   r   definitionsr  r  s           r   r   zFunctionIR.__init__t  sA    (""'&&(r   c                 b    t        |       t        |      u r| j                  |j                  k(  S y)aD   Checks that the IR contained within is equal to the IR in other.
        Equality is defined by being equal in fundamental structure (blocks,
        labels, IR node type and the order in which they are defined) and the
        IR nodes being equal. IR node equality essentially comes down to
        ensuring a node's `.__dict__` or `.__slots__` is equal, with the
        exception of ignoring 'loc' and 'scope' entries. The upshot is that the
        comparison is essentially location and scope invariant, but otherwise
        behaves as unsurprisingly as possible.
        F)r!   r  r"   s     r   equal_irzFunctionIR.equal_ir  s*     :e$;;%,,..r   c                 0   g }| j                   j                         D ]  \  }}|j                   j                  |d      }|&||k7  s,|j                  d|z  j	                  dd             |j
                  D cg c]  }t        |t              s| }}|j
                  D cg c]  }t        |t              s| }}||k7  r+t        |      t        |      k(  r|j                  d|z         t        |j
                        t        |j
                        kD  r|j                  d       n<t        |j
                        t        |j
                        k  r|j                  d       g t        t        |j
                  |j
                              D ]!  \  }	}
|
\  }}||k7  sj                  |	       # fd}t        t        |j
                        t        |j
                              }t               5 }d	|fd
|fg}|D ]  \  }}|j                  d       |j                  |       |j!                         j#                         }
 ||j
                  |      }|d|}|j                  |j	                  dd             |j%                  t        ||
      D cg c]  \  }}dj'                  ||       c}}        	 ddd        |g k(  r|j                  d       dj)                  |      S c c}w c c}w c c}}w # 1 sw Y   xY w)zw
        Compute a human readable difference in the IR, returns a formatted
        string ready for printing.
        NzBlock %s differsP   -z<Block %s contains the same dels but their order is differentz#This block contains more statementsz$Other block contains more statementsc                     d}t        |      dz  }g }t        |       }t        |      D ]$  }|v r|}n
||k\  r|}n|}|j                  |       & |S )Nz-> r]   )r   rangerc   )	ablocklpointersppadnstmtiitemru   s	           r   get_padz$FunctionIR.diff_str.<locals>.get_pad  sb    "' \C/  #F!&uA Cx'.!"a'.')JJt, ".  #
r   r   r#   r   rW  z: block z{0}{1}zIR is considered equivalent.
)r  r  r   rc   centerr=  r   r|  rL  r   rb   zipminr   truncaterT  getvalue
splitlinesrd   r  ri   )r   r#   msglabelr@  	other_blkr>   	block_deloth_delrq   stmtsb_so_sr  min_stmt_lenbufitr   _blockr  titler?  bru   s                          @r   diff_strzFunctionIR.diff_str  s   
  KK--/LE5((5I$I%JJ 2U :BB2sKL,1JJ MJq*Q:LJI M*3..O.QJq#<Nq.GO G+ "),w?JJ )CFK(L M5::Y^^)<<

#HIUZZ3y~~+>>

#IJ C&/EJJ4=NN1D 'E
U#(S#:JJsO	'E# $'s5::INN8K#LL!s%uo/CD,.LD&LLO"KKSK1$'LLN$=$=$?E")&++|"DC7;U%CEJJu||B'<=JJ(+C(9(7 CG!Q1(=(7(9 : -/ $Y 0n "9JJ56yy~g !NO\(9 $s7   <K;K;&L <L ;B'L"L>
LLL	c                 b    t        j                  |       | _        d | _        d | _        i | _        y r&   )r   ConstantInference_constsgenerator_infovariable_lifetimeblock_entry_varsr1   s    r   r  z$FunctionIR._reset_analysis_variables  s.    //5 #!% "r   Nc                    |t        |         }t        j                  |       }||_        |j                  |_        |rd|_        |||_        |||_        |j                          |j                  j                         |_        |S )z
        Derive a new function IR from this one, using the given blocks,
        and possibly modifying the argument count and generator flag.

        Post-processing will have to be run again on the new IR.
        F)
r  r  r  r   r  r  r  r  r-   derive)r   r  r  r  force_non_generator
firstblocknew_irs          r   r  zFunctionIR.derive  s}     CK(
4^^
"'F (F (F((*..0r   c                    t        j                   |       }i }i }| j                  j                         D ];  \  }}|j                         }|||<   || j                  v s*| j                  |   ||<   = ||_        ||_        |S r&   )r  r  r  r  )r   r  r  r  r  r@  	new_blocks          r   r  zFunctionIR.copy  s    4 KK--/LE5

I%F5M---.2.C.CE.J +	 0
 "2r   c                      | j                   |   S )zf
        Return a set of variable names possibly alive at the beginning of
        the block.
        )r  r?  s     r   get_block_entry_varszFunctionIR.get_block_entry_vars  s    
 $$U++r   c                 p    t        |t              r|j                  }| j                  j	                  |      S )zF
        Try to infer the constant value of a given variable.
        )r   r   r   r  rV  r   s     r   rV  zFunctionIR.infer_constant  s,     dC 99D||**400r   c                    |}	 t        |t              r|}|j                  }nt        |t              r|}|}n|r|S |S | j                  |   }t        |      dk(  rt        d|      t        |      dkD  rt        d|      |d   })z
        Get the definition site for the given variable name or instance.
        A Expr instance is returned by default, but if lhs_only is set
        to True, the left-hand-side variable is returned instead.
        r   zno definition for r7   zmore than one definition for )r   r   r   rX   r  r   r   )r   r   lhs_onlyr   r   defss         r   get_definitionzFunctionIR.get_definition  s     %%zzE3'&s1E1$$T*D4yA~"& ) * *4y1}"& ) * *GE! r   c                    || j                   j                         }nFt        |t              r| j                   |   g}n%t	        |      D cg c]  }| j                   |    }}t        |t
              sJ |D ];  }|j                  t              D ]!  }|j                  |k(  s|j                  c c S  = t        d|z        c c}w )z
        Finds the assignee for a given RHS value. If in_blocks is given the
        search will be limited to the specified blocks.
        z!Could not find an assignee for %s)r  r   r   r  r   r   rF  r  r   r   rP   )r   	rhs_value	in_blocksr  blkassigns         r   get_assigneezFunctionIR.get_assignee'  s    
 [['')F	3'kk),-F26y/B/3dkk#&/FB)[111C..0<<9,!==( 1 
 <yHII Cs   Cc           
         |d u }|xs
 t               }t        | j                  j                               D ](  \  }}t	        d|d|       |j                  |       * |rn|j                         }t        j                  rB	 dd l	}ddl	m
} ddlm} ddlm}	 ddlm}
 t	         || |        |
 |	       	                   y t	        |       y y # t         $ r d
}t#        |      w xY w)Nzlabel r4   rW  r   )rf   )NumbaIRLexer)by_colorscheme)Terminal256Formatter)stylez0Please install pygments to see highlighted dumps)r   rL  r  r  r\  rT  r  r	   HIGHLIGHT_DUMPSpygmentsrf   numba.misc.dump_styler  r  pygments.formattersr  ImportErrorrP   )r   rX  nofileoffsetr@  textr  rf   lexerr  r  r  s               r   rT  zFunctionIR.dump=  s    !xz#DKK$5$5$78MFE)5JJDJ! 9 ==?D%%2#
 3KDH)D%'3G,.40 1 2 d! 
 # *LC$S/)*s   C C)c                     t               5 }| j                  |       |j                         cd d d        S # 1 sw Y   y xY w)NrW  )r   rT  r  )r   sbs     r   dump_to_stringzFunctionIR.dump_to_stringW  s*    Z2II2I;;= ZZs	   "7A c           	      N   |xs t         j                  }| j                  }t        dt	        |j
                        |       t	        |j                  j                               D ]>  \  }}t        d|t	        |j                        t	        |j                        fz  |       @ y )Nzgenerator state variables:rW  z>yield point #%d: live variables = %s, weak live variables = %s)
rY  rZ  r  r\  rL  
state_varsyield_pointsr  	live_varsweak_live_vars)r   rX  girp   yps        r   dump_generator_infozFunctionIR.dump_generator_info\  s    !szz  *F2==,AM 5 5 78IE2RF2<<0&9J9J2KLM 9r   c           	         	 ddl }|j                  dj                  || j                  j
                              }| j                  j                         D ]  \  }}t               5 }|j                  |       |j                         }ddd       |rndj                  j                         D 	cg c]  }	dj                  |	       c}	      }dj                  |      |z   }|j                  t        |      |d	
       dj                  |      }|j                  t        |      |d
        | j                  j                         D ]H  \  }
}|j                  j!                         D ]&  }|j#                  t        |
      t        |             ( J |S # t        $ r t        d      w xY w# 1 sw Y   )xY wc c}	w )zRender the CFG of the IR with GraphViz DOT via the
        ``graphviz`` python binding.

        Returns
        -------
        g : graphviz.Digraph
            Use `g.view()` to open the graph in the default PDF application.
        r   NzcThe feature requires `graphviz` but it is not available. Please install with `pip install graphviz`z{}{}.dot)r   rS   z  {}\lz
block {}\lrect)r  shapez{}\lcircle)graphvizr  Digraphr  r-   unique_namer  r  r   rT  r  ri   r  noderX   r`  r   edge)r   filename_prefix
include_irgvgrF  r  r  r  r>   srcdsts               r   
render_dotzFunctionIR.render_dote  s   	! JJ&&((  
 kk'')FAsr  272B2B2DE2DQY%%a(2DE &,,Q/%7s1vU&9q)s1vU(; * ))+HC~~113s3xS* 4 , ;  	= 	 
 Fs   F &"F//F<
F,/F9	)NNF)Fr&   )numba_irT)r   r   r   r   r  r  r  r  r  r  rV  r  r  rT  r  r  r  r   r   r   r}  r}  r  sR    )?B# 8<#(0,12J,4!
)r   r}  c                       e Zd ZdZd Zd Zy)UndefinedTypeNc                 ^    | j                   }||S t        j                  |       }|| _         |S r&   )
_singletonobject__new__)r,   objs     r   r  zUndefinedType.__new__  s/    nn?J..%C CN
r   c                      y)N	Undefinedr   r1   s    r   r2   zUndefinedType.__repr__  r  r   )r   r   r   r  r  r2   r   r   r   r  r    s    Jr   r  )Mcollectionsr   r  rV   rM   rI   r   r   rY  r!  typesr   r   	functoolsr   ior   
numba.corer   r	   numba.core.utilsr
   r   r   r   numba.core.errorsr   r   r   r   r   	termcolorre   r  r   unknown_locr   r   r   r   r   r   r   r   rY  rb  rf  rk  rr  rv  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r;  rm  ry  r}  r  r   r   r   r   <module>r     s   #   	   	 
  3 $  %Q QJ J  V
u4& u4r $a+ V  *   0&&V &&R& { B24 2. . q@4 q@hEd E&ED E*8d 8"Ed E
8d 
8@t @%$ %J  * :: :/t /@T @,Ad A,Z &: "+Z +(5T 5 BD B$D % %6t @
k @ 
 
,F F&% + %>8
k 8vpD pDfe0 e0P0! 00! 0\ \@	& " O	r   