
    qh                        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        G/var/www/html/engine/venv/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/0 	A wwy##F+	 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                   3| j                         }|dk(  rg nt        j                  |      }|| _         | j                   S )Nz<string>)r   	_get_path	linecachegetlines)r   pathlnss      r   r9   zLoc.get_lines[   sD    ::>>#D 
*"	0B0B40HCDJzzr   c                     d }	 t         j                  j                  | j                        }|S # t        $ r- t         j                  j                  | j                        }Y |S w xY wr&   )osrL   relpathr   
ValueErrorabspath)r   rL   s     r   rI   zLoc._get_pathe   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   s9    ",,S[[#f+F  AaKF 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   rI   codejoin)r   	nlines_upr   use_linetmplinesmin_linemax_lineselectedindexidxr>   retr]   	def_foundr=   r\   errtmps                     r   	strformatzLoc.strformats   s    99 te|HfHX4F&F q(+#b=#Hx8'1 FC{ # $e+ X\ SHy$89(CH I %Q; $I%
 !%A"67 A{"# 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   )rO   rL   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   rI   rw   ry   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__   sF    :e$ 4&'%*>>  r   c                 0    t        |       t        |      k  S r&   rY   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   s1    &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   0  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_vars;  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   re   _rec_list_varsr   values)r   vallstvs       r   r   zInst._rec_list_varsA  s     c35LT"==?"dE]+C 3

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

4..q123JIr   N)r   r   r   r   r   r   r   r   r   r   r   6  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_varsb  s    ""4==11r   N)r   r   r   r   is_terminatoris_exitr   r   r   r   r   r   W  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_targetsr  s    !$t*--r   N)r   r   r   r   r   r   r   r   r   r   r   f  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   rY   r   opr   _kws)r   r   r   kwss       r   r   zExpr.__init__|  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   rY   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   rY   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   rq   r   r   r   r   operatorr   )r,   r   rq   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   dtyperq   r   )r,   r   r%  rq   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   rq   	index_varr   r!  )r,   r   rq   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   ri   closuredefaultsr   r  )r,   r   ri   r1  r2  r   r   s          r   r0  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   r4  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.
        undefr5  r  r6  s      r   r8  z
Expr.undef9  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   rY   )r,   r   r:  r   s       r   dummyz
Expr.dummyB  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>R  s     7SV7   r   c              3   0   K   | ]  \  }}|d |  yw=Nr   r?  kr   s      r   rA  z Expr.__repr__.<locals>.<genexpr>T  s     DAq!,D   *rT   zcall (r0   r   r^   c              3   0   K   | ]  \  }}|d |  ywrD  r   rF  s      r   rA  z Expr.__repr__.<locals>.<genexpr>`  s     <Aq!$<rH  )r   rj   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__P  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_varsc  s    ""499--r   c                 6    t        d| z  | j                        Nz%sr   r   r   r1   s    r   infer_constantzExpr.infer_constantf      $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,  r0  r4  r8  r;  r2   r   rW  r   r   r   r   r   v  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   rq   r   r   )r   r   rq   r   r   s        r   r   zSetItem.__init__o  s^    &#&&&%%%%%%%%#s###

r   c                 R    | j                   d| j                  d| j                  S N[z] = r   rq   r   r1   s    r   r2   zSetItem.__repr__y       $TZZDDr   Nr   r   r   r   r   r2   r   r   r   rZ  rZ  j  s    Er   rZ  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   rq   r(  r   r   )r   r   rq   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   Nra  r   r   r   rc  rc  }  s    
Er   rc  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   rq   r   )r   r   rq   r   s       r   r   zDelItem.__init__  sG    &#&&&%%%%#s###
r   c                 <    d| j                   d| j                  dS )Nzdel r^  ])r   rq   r1   s    r   r2   zDelItem.__repr__  s    #{{DJJ77r   Nra  r   r   r   rg  rg    s    8r   rg  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   rY   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 )NrJ  ). = )r   r  r   r1   s    r   r2   zSetAttr.__repr__  s    !%diiDDr   Nr   r   r   r   r2   r   r   r   rl  rl    s    Er   rl  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   rY   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 (ro  )r   r  r1   s    r   r2   zDelAttr.__repr__  s     $TYY77r   Nrq  r   r   r   rs  rs    s    8r   rs  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   ry  rz  r   r   s        r   r   zStoreMap.__init__  s^    #s####s###%%%%#s###
r   c                 R    | j                   d| j                  d| j                  S r]  )ry  rz  r   r1   s    r   r2   zStoreMap.__repr__  s     $$((DJJ??r   Nrq  r   r   r   rw  rw    s    @r   rw  c                       e Zd Zd Zd Zy)Delc                 h    t        |t              sJ t        |t              sJ || _        || _        y r&   )r   rY   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 rJ  r=  r0   r  r  rj   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 rJ  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__5  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=  rJ  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  1  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__K  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=  rJ  r0   r  r  s     r   r5   zDynamicTryRaise.__str__S  s^    >>!']]"''78899St}}56D''7qa@@r   Nr  r   r   r   r  r  G  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__c  s9    %%2tE{2%#s###
r   c                      d| j                   z  S )Nz	return %sr  r1   s    r   r5   zReturn.__str__i  s    TZZ''r   c                     g S r&   r   r1   s    r   r   zReturn.get_targetsl  r  r   Nr  r   r   r   r  r  ]  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__u  s     #s###r   c                      d| j                   z  S )Nzjump %sr   r1   s    r   r5   zJump.__str__z  s    4;;&&r   c                     | j                   gS r&   r  r1   s    r   r   zJump.get_targets}  s    }r   Nr   r   r   r   r   r5   r   r   r   r   r  r  p  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 )Nrp  )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   rA  z!Print.__init__.<locals>.<genexpr>  s     4!:a%4s   )	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   rA  z Print.__str__.<locals>.<genexpr>  s     &A!s1v&ArB  )rj   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   rq   )r   r   r   rq   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   rY   r  r   r   rq   r   )r   r   rq   r   s       r   r   zArg.__init__  sG    $$$$%%%%#s###	
r   c                 8    d| j                   | j                  fz  S )Nzarg(%d, name=%s))rq   r   r1   s    r   r2   zArg.__repr__  s    !TZZ$;;;r   c                 6    t        d| z  | j                        rT  rV  r1   s    r   rW  zArg.infer_constant  rX  r   N)r   r   r   r   r2   rW  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   rW  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   rW  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   rW  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   rW  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  rY   r   rq   r   r   r   )r   rq   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__6  s    $(IItzz::r   c                     | j                   S r&   r  r1   s    r   rW  zFreeVar.infer_constant9  r  r   c                 p    t        | j                  | j                  | j                  | j                        S )N)rq   r   r   r   )r  rq   r   r   r   r  s     r   r  zFreeVar.__deepcopy__<  s(    TZZdiitzz88% 	%r   N)r   r   r   r   r   r5   rW  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   ScoperY   r   r   r   r   )r   r   r   r   s       r   r   zVar.__init__O  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__X  s     $		488>>+;<<r   c                     | j                   S r&   )r   r1   s    r   r5   zVar.__str__[  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   rG  	redef_sets      r   unversioned_namezVar.unversioned_nameb  sG     !JJ88>>@ 	LAyyyI%	 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_namesk  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_namesr  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__x  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   C  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   r5  z#Scope.get_versions_of.<locals>.walk  sD    ++//>F AHHQKG r   )r  )r   r   r4  r5  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  r8  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  sL      II 	#D$'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,   rC  s      r   
find_instszBlock.find_insts  s*      II 	D$$
	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)rG  r  r   r   )r   r   r>   s      r   find_variable_assignmentzBlock.find_variable_assignment  s8    
 V, 	Axx}}$	 r   c                 `    t        |t              sJ | j                  j                  d|       y rA   )r   r   r>  insertr   rC  s     r   prependzBlock.prepend  s&    $%%%		D!r   c                 ^    t        |t              sJ | j                  j                  |       y r&   )r   r   r>  rd   rL  s     r   rd   zBlock.append#  s$    $%%%		r   c                 t    t        |t              sJ | j                  | j                  j                  |      = y r&   )r   r   r>  rq   rL  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   rA  zBlock.dump.<locals>.<genexpr>5  s     "Da3q6"DrB  z    40r^   file)sysstdoutr>  hasattrrU  rM  r   print)r   rY  rC  	inst_varss       r   rU  z
Block.dump.  s`    !szzII 	EDtV$		$""D4>>3C"DD	i8tD	Er   c                      | j                   d   S Nr`   rR  r1   s    r   
terminatorzBlock.terminator8  s    yy}r   c                 P    | j                   xr | j                   d   j                  S r`  )r>  r   r1   s    r   is_terminatedzBlock.is_terminated<  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)rc  r   r>  r   rL  s     r   verifyzBlock.verify@  sK    !!#$>??IIcrN 	7D!!' )6 7 7	7r   c                 x    | j                   j                  |      }| j                   j                  |dz   |       y)z.
        Insert *stmt* after *other*.
        r7   N)r>  rq   rK  )r   stmtr#   rq   s       r   insert_afterzBlock.insert_afterI  s.     		&		D)r   c                 |    t        |t              sJ | j                  sJ | j                  j	                  d|       y r`  )r   r   rc  r>  rK  )r   rg  s     r   insert_before_terminatorzBlock.insert_before_terminatorP  s5    $%%%!!!!		T"r   c                 "    d| j                   dS )Nz<ir.Block at >rU  r1   s    r   r2   zBlock.__repr__U  s    %)XX//r   r&   )r   r   r   r   r   r  rE  rG  rI  rM  rd   rP  rS  rU  r  ra  rc  re  rh  rj  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&   ro  r   rp  rq  s      r   r   zLoop.__init__^      
	r   c                 <    | j                   | j                  f}d|z  S )NzLoop(entry=%s, exit=%s)ro  r  s     r   r2   zLoop.__repr__b      zz499$(4//r   Nr   r   r   r   r   r   r2   r   r   r   rn  rn  Y      I0r   rn  c                        e Zd ZdZdZd Zd Zy)WithzDescribes a with-block
    ro  c                      || _         || _        y r&   ro  rs  s      r   r   zWith.__init__l  rt  r   c                 <    | j                   | j                  f}d|z  S )NzWith(entry=%s, exit=%s)ro  r  s     r   r2   zWith.__repr__p  rv  r   Nrw  r   r   r   rz  rz  g  rx  r   rz  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__w  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   rangerd   )	ablocklpointersppadnstmtiitemrv   s	           r   get_padz$FunctionIR.diff_str.<locals>.get_pad  sg    "' \C/  #F!&u -A Cx'.!"a'.')JJt,-  #
r   r   r#   r   rX  z: block z{0}{1}zIR is considered equivalent.
)r  r  r   rd   centerr>  r   r}  rM  r   rc   zipminr   truncaterU  getvalue
splitlinesre   r  rj   )r   r#   msglabelrA  	other_blkr>   	block_deloth_delrr   stmtsb_so_sr  min_stmt_lenbufitr   _blockr  titler@  brv   s                          @r   diff_strzFunctionIR.diff_str  s   
  KK--/ 6	:LE5((5I$I%JJ 2U :BB2sKL,1JJ Mq*Q:L MI M*3..OQJq#<NqOGO G+ "),w?JJ )CFK(L M5::Y^^)<<

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

#IJ C&/EJJ4=NN1D 'E ,
U#(S#:JJsO	,# $'s5::INN8K#LL! 
:s%uo/CD,. :LD&LLO"KKSK1$'LLN$=$=$?E")&++|"DC7;U%CEJJu||B'<=JJ(+C(9$!Q1(= (9 ::
: 
:Y6	:n "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                  n||_        |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_generatorr   
firstblocknew_irs           r   r  zFunctionIR.derive  s     CK(
4'*{Z^^
"'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  rA  	new_blocks          r   r  zFunctionIR.copy  s    4 KK--/ 	KLE5

I%F5M---.2.C.CE.J +		K
 "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  rW  r   s     r   rW  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   rY   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   rG  r  r   r   rQ   )r   	rhs_value	in_blocksr  blkassigns         r   get_assigneezFunctionIR.get_assignee*  s    
 [['')F	3'kk),-F26y/B3dkk#&BFB)[111 	)C..0 )<<9,!==()	)
 <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   rX  r   )rg   )NumbaIRLexer)by_colorscheme)Terminal256Formatter)stylez0Please install pygments to see highlighted dumps)r   rM  r  r  r]  rU  r  r	   HIGHLIGHT_DUMPSpygmentsrg   numba.misc.dump_styler  r  pygments.formattersr  ImportErrorrQ   )r   rY  nofileoffsetrA  textr  rg   lexerr  r  r  s               r   rU  zFunctionIR.dump@  s    !xz#DKK$5$5$78 	"MFE)5JJDJ!	" ==?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)NrX  )r   rU  r  )r   sbs     r   dump_to_stringzFunctionIR.dump_to_stringZ  s5    Z 	!2II2I;;=	! 	! 	!s	   "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:rX  z>yield point #%d: live variables = %s, weak live variables = %s)
rZ  r[  r  r]  rM  
state_varsyield_pointsr  	live_varsweak_live_vars)r   rY  girq   yps        r   dump_generator_infozFunctionIR.dump_generator_info_  s    !szz  *F2==,AM 5 5 78 	IE2RF2<<0&9J9J2KLM	r   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   rT   z  {}\lz
block {}\lrect)r  shapez{}\lcircle)graphvizr  Digraphr  r-   unique_namer  r  r   rU  r  rj   r  noderY   ra  r   edge)r   filename_prefix
include_irgvgrG  r  r  r  r>   srcdsts               r   
render_dotzFunctionIR.render_doth  s   	! JJ&&((  
 kk'') 	<FAs &r& 272B2B2DEQY%%a(E &,,Q/%7s1vU&9q)s1vU(;	< ))+ 	+HC~~113 +s3xS*+	+ ;  	= 	& &
 Fs   F &"F//F<
F,/F9	)NNFN)Fr&   )numba_irT)r   r   r   r   r  r  r  r  r  r  rW  r  r  rU  r  r  r  r   r   r   r~  r~  u  sR    )?B# 8<.2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  rW   rO   rJ   r   r   rZ  r"  typesr   r   	functoolsr   ior   
numba.corer   r	   numba.core.utilsr
   r   r   r   numba.core.errorsr   r   r   r   r   	termcolorrf   r  r   unknown_locr   r   r   r   r   r   r   r   rZ  rc  rg  rl  rs  rw  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r<  rn  rz  r~  r  r   r   r   r   <module>r     s   #   	   	 
  3 $  %Q QJ J  V
x4& x4x $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   