
    J/Ph                        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            ZLdS )]    )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dS )LoczSource location

    zdef\s+(\w+)NFc                 L    || _         || _        || _        d| _        || _        dS )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        M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/ir.py__init__zLoc.__init__   s.     !	
.    c                     t          |           t          |          urdS | j        |j        k    rdS | j        |j        k    rdS | j        |j        k    rdS dS NFT)typer   r   r   r   others     r   __eq__z
Loc.__eq__,   s[    ::T%[[((=EN**559
""558uy  tr   c                 .    |                      |           S Nr$   r"   s     r   __ne__z
Loc.__ne__4       ;;u%%%%r   c                 2     | |j         |j        d          S )NT)r   )r   firstlineno)clsfunc_ids     r   from_function_idzLoc.from_function_id7   s    s7#W%8$OOOOr   c                 8    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:mmm6:iiiK 	Kr   c                 h    | 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__?   s@    8#'===$)))TXXXFF $tyyy99r   c                     d }|                                  }t          |d | j        dz
                     D ]-}|                                                    d          r|} n.|S )N   def )	get_linesreversedr   strip
startswith)r   fn_namer   xs       r   _find_definitionzLoc._find_definitionE   sr      %Q/00 	 	A wwyy##F++  r   c                     |                                  }|rH| j                            |                                          }|r|                                d         S d S Nr   )r?   _defmatchermatchr;   groups)r   defnms      r   _raw_function_namezLoc._raw_function_nameR   sX    $$&& 	% &&tzz||44A %xxzz!}$tr   c                     | j         7|                                 }|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[   sH    :>>##D 
**""	0B40H0HCDJzr   c                     d }	 t           j                            | j                  }n4# t          $ r' t           j                            | j                  }Y nw xY w|S r&   )osrL   relpathr   
ValueErrorabspath)r   rL   s     r   rI   zLoc._get_pathe   sb    	2 7??4=11DD 	2 	2 	2 7??4=11DDD		2
 s   $) .AA   c                 F   |                                  }| j        }| j        rWdg|z   }|rO|rMd||         vrCt          d|          }|dz   }|||         }d}t	          |          D ]\  }	}
d|
v r|	} n||z   }g }|r1|dk    r*d }|t          d||z
            |         }d}|D ]}
d|
v rd}	|sgd }t          |d |dz
                     D ]
}
d|
v r|
} n|r>|                    |            ||
          }|                    d	d
|z   z  dz              |r|                    |d d                    |                    t          	                    |d                               ||d                   }|                    d	|z  t          
                    d          z              |s|sd}n|dk    rd}t                              d          dz   }||                                 |t                              d                    |                    fz  }|S )N r8   r   
   c                 r    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   s;    ",S[#f++FF    AaKFF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     9 	, te|H , ,fHX4F&F&F q(++#b=#Hx$78'11  FC{{ # # $e+  '	DX\\   SHy$899(BCH I % %Q;; $I  
G!%A"677  A{{"# #  GJJw''')\!__FJJsAJ/2EEFFF D

8CRC=)))

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

3<**=*=c*B*BBCCC  	5 5;Q4 !!"9::6AT^^%%x1N1N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      tDzz$-s333r   c                 b    t           j                            | j                  }|d| j        S )z(
        Returns a short string
        r4   )rO   rL   basenamer   r   )r   shortfilenames     r   shortz	Loc.short   s.     ((77'--33r   NF)rS   r&   )__name__
__module____qualname____doc__recompilerB   r   r$   r(   classmethodr.   r2   r5   r?   rG   r9   rI   rx   rz   r~    r   r   r   r      s         "*^,,K/ / / /  & & & P P [PK K K: : :        Q Q Q Qf4 4 4 44 4 4 4 4r   r   zunknown locationc                   4    e Zd Z e            Zd Zd Zd ZdS )SlotEqualityCheckMixinc                     t          |           t          |          u r1| j        D ]'}t          | |          t          ||          k    r dS (dS dS r    )r!   	__slots__getattr)r   r#   names      r   r$   zSlotEqualityCheckMixin.__eq__   sa    ::e$$  4&&'%*>*>>> 55 ? tur   c                 B    t          |           t          |          k    S r&   rZ   r"   s     r   __le__zSlotEqualityCheckMixin.__le__   s    4yyCJJ&&r   c                      t          |           S r&   idr1   s    r   __hash__zSlotEqualityCheckMixin.__hash__       $xxr   N)r   r   r   tupler   r$   r   r   r   r   r   r   r      sN         I  ' ' '    r   r   c                   $    e Zd ZdZd Zd Zd ZdS )EqualityCheckMixinz# Mixin for basic equality checking c                     t          |           t          |          u r+d } || j                  } ||j                  }||k    rdS dS )Nc                 ^    d}t          |           }|D ]}|                    |d            |S )N)locscope)dictpop)adictbaddr>   s       r   fixupz(EqualityCheckMixin.__eq__.<locals>.fixup   s9    &KK # #AEE!TNNNNr   TF)r!   __dict__)r   r#   r   d1d2s        r   r$   zEqualityCheckMixin.__eq__   s_    ::e$$   t}%%Bu~&&BRxxtur   c                 B    t          |           t          |          k     S r&   r   r"   s     r   r   zEqualityCheckMixin.__le__   s    4yy3u::%%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      sG        --  & & &    r   r   c                   J    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )VarMapc                     i | _         d S r&   _conr1   s    r   r   zVarMap.__init__  s    			r   c                 J    || j         v rt          |          || j         |<   d S r&   )r   r   )r   r   vars      r   definezVarMap.define  s,    49 &&&!DIdOOOr   c                 X    	 | j         |         S # t          $ r t          |          w xY wr&   )r   KeyErrorr   r   r   s     r   getz
VarMap.get  s<    	(9T?" 	( 	( 	(!$'''	(s    )c                     || j         v S r&   r   r   s     r   __contains__zVarMap.__contains__  s    ty  r   c                 *    t          | j                  S r&   )lenr   r1   s    r   __len__zVarMap.__len__  s    49~~r   c                 4    t          j        | j                  S r&   )pprintpformatr   r1   s    r   r2   zVarMap.__repr__  s    ~di(((r   c                 *    t          | j                  S r&   )hashr   r1   s    r   r   zVarMap.__hash__   s    DIr   c                 4    | j                                         S r&   )r   iterkeysr1   s    r   __iter__zVarMap.__iter__#  s    y!!###r   c                     t          |           t          |          u r4| j                                        |j                                        k    S dS r   )r!   r   keysr"   s     r   r$   zVarMap.__eq__&  sA    ::e$$9>>##uz'8'888ur   c                 .    |                      |           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     s          " " "( ( (! ! !  ) ) )  $ $ $  & & & & &r   r   c                       e Zd ZdZdS )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dS )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|                                S t          |t          t
          f          r1g }|D ]*}|                    |                     |                     +|S t          |t                    rCg }|	                                D ]*}|                    |                     |                     +|S g S )zQ
        A recursive helper used to implement list_vars() in subclasses.
        )

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

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

4..q112222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dS )Stmtzc
    Base class for IR statements (instructions which can appear on their
    own in a Block).
    Fc                 6    |                      | j                  S r&   )r   r   r1   s    r   r   zStmt.list_varsb  s    ""4=111r   N)r   r   r   r   is_terminatoris_exitr   r   r   r   r   r   W  s9          MG2 2 2 2 2r   r   c                       e Zd ZdZdZd ZdS )
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  s4          M. . . . .r   r   c                   2   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!dS )!Exprz]
    An IR expression (an instruction which can only be part of a larger
    statement).
    c                     t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   rZ   r   opr   _kws)r   r   r   kwss       r   r   zExpr.__init__|  sG    "c"""""#s#####			r   c                 |    |                     d          rt                              | |          S | j        |         S )N_)r<   r   __getattr__r   r   s     r   r   zExpr.__getattr__  s8    ??3 	0##D$///yr   c                 :    |dv r|| j         |<   d S || j        |<   d S )N)r   r   r   )r   r   )r   r   values      r   __setattr__zExpr.__setattr__  s/    ((("'DM$#DIdOOOr   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  s    "122222#s######s######s#####sbcbcs'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  s    "122222,(;<<<<<#s######s######s#####sbcb|'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   rZ   r   r   r   r   r   )r,   r   r   r   r   s        r   r   z
Expr.unary  se    %#sL!9:::::#s#####'+B33sbcb6666r   Nc           
          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  sa    $$$$$$#s#####sbc4S 8FD D D 	Dr   c                 P    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  s4    #s#####sbc////r   c                 P    t          |t                    sJ d} | |||          S )N
build_listr  r  r  s       r   r  zExpr.build_list  s4    #s#####sbc////r   c                 P    t          |t                    sJ d} | |||          S )N	build_setr  r  r  s       r   r  zExpr.build_set  s4    #s#####sbc////r   c                 V    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  sG    #s#####sbcT!.mM M M 	Mr   c                 P    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  s4    %%%%%%sbc////r   c                 ~    t          |t                    sJ t          |t                    sJ d} | |||          S )Npair_secondr  r   r  s       r   r  zExpr.pair_second  sJ    %%%%%%#s#####sbc////r   c                 ~    t          |t                    sJ t          |t                    sJ d} | |||          S )Ngetiterr  r   r  s       r   r  zExpr.getiter  sJ    %%%%%%#s#####sbc////r   c                 ~    t          |t                    sJ t          |t                    sJ d} | |||          S )Niternextr  r   r  s       r   r  zExpr.iternext  sJ    %%%%%%#s#####sbc////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  sb    %%%%%%%%%%%%#s#####sbce<<<<r   c                     t          |t                    sJ t          |t                    sJ t          |t                    sJ d} | ||||          S )Nr   )r   r   r   attr)r   r   rZ   r   )r,   r   r  r   r   s        r   r   zExpr.getattr  sb    %%%%%%$$$$$$#s#####sbcT::::r   c                     t          |t                    sJ t          |t                    sJ t          |t                    sJ d}t          j        } | |||||          S )Ngetitem)r   r   r   rr   r   r   r   r   operatorr   )r,   r   rr   r   r   r   s         r   r   zExpr.getitem  sl    %%%%%%%%%%%%#s#####sbceCCCCr   c                     t          |t                    sJ t          |t                    sJ d} | |||||          S )Ntyped_getitem)r   r   r   dtyperr   r   )r,   r   r%  rr   r   r   s         r   r$  zExpr.typed_getitem  sW    %%%%%%#s#####sbc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   rr   	index_varr   r!  )r,   r   rr   r(  r   r   r   s          r   r'  zExpr.static_getitem	  s|    %%%%%% Jy#$>$>   #s#####sbce&2/ / / 	/r   c                 ~    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  sL    
 %%%%%%#s#####sb3////r   c                 N    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  s3     #s#####seRMMMMr   c                 V    t          |t                    sJ d} | ||||||          S )z6
        A node for making a function object.
        make_function)r   r   rj   closuredefaultsr   r  )r,   r   rj   r1  r2  r   r   s          r   r0  zExpr.make_function$  s=    
 #s#####sbt$(X[\\\\r   c                 N    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-  s4     #s#####sbc""""r   c                 N    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  s4    
 #s#####sbc""""r   c                 z    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   rZ   )r,   r   r:  r   s       r   dummyz
Expr.dummyB  sG     #s#####"c"""""sbt----r   c                 v   | j         dk    rd                    d | j        D                       }t          j        dk    r| j                                        n%t          | j                                                  }d                    d |D                       }| j        
d| j        nd}d                    t          d |||g                    }d| j
        d	|d
S | j         dk    rP| j        | j        }}| j        t          j        k    r||}}t!          j        | j        | j                  }|d|d|S t          j        dk    r| j                                        n%t          | j                                                  }d |D             }| j         d	d                    |          d
S )Nr   , c              3   4   K   | ]}t          |          V  d S r&   r   ).0as     r   	<genexpr>z Expr.__repr__.<locals>.<genexpr>R  s(      77SVV777777r   r   c              3   *   K   | ]\  }}|d |V  dS =Nr   r?  kr   s      r   rA  z Expr.__repr__.<locals>.<genexpr>T  s1      DDAqqq!!,DDDDDDr   *rU   zcall (r0   r   r_   c              3   *   K   | ]\  }}|d |V  dS rC  r   rE  s      r   rA  z Expr.__repr__.<locals>.<genexpr>`  s1      <<Aqqq!!$<<<<<<r   )r   rk   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  s   7f9977TY77777D.4n.A.A***vdiooN_N_G`G`J))DDDDDDDC/3{/F/Fdkk++BFiitdFC-@ A ABBGG$(IIIwww77WxCw(+++S&*47DG<<B!$bbb##...4n.A.A***vdiooN_N_G`G`J<<<<<D#www		$88r   c                 6    |                      | j                  S r&   )r   r   r1   s    r   r   zExpr.list_varsc  s    ""49---r   c                 4    t          d| z  | j                  Nz%sr   r   r   r1   s    r   infer_constantzExpr.infer_constantf      $TD[dh????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   rU  r   r   r   r   r   v  s        
    
$ $ $ ? ? [? 	? 	? [	? 7 7 [7 D D D [D 0 0 [0
 0 0 [0
 0 0 [0
 M M [M 0 0 [0
 0 0 [0 0 0 [0 0 0 [0 = = [= ; ; [; D D [D     [  / / [/ 0 0 [0 N N [N ] ] [] 	# 	# [	# # # [# . . [.9 9 9&. . .@ @ @ @ @r   r   c                       e Zd ZdZd Zd ZdS )SetItemz
    target[index] = value
    c                     t          |t                    sJ t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        d S r&   )r   r   r   r   rr   r   r   )r   r   rr   r   r   s        r   r   zSetItem.__init__o  sz    &#&&&&&%%%%%%%%%%%%#s#####

r   c                 4    | j         d| j        d| j        S N[z] = r   rr   r   r1   s    r   r2   zSetItem.__repr__y       $TZZZDDr   Nr   r   r   r   r   r2   r   r   r   rX  rX  j  sA           E E E E Er   rX  c                       e Zd ZdZd Zd ZdS )StaticSetItemz(
    target[constant index] = value
    c                 2   t          |t                    sJ t          |t                    rJ t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        || _        d S r&   )r   r   r   r   rr   r(  r   r   )r   r   rr   r(  r   r   s         r   r   zStaticSetItem.__init__  s    &#&&&&&eS))))))S)))))%%%%%%#s#####
"
r   c                 4    | j         d| j        d| j        S r[  r]  r1   s    r   r2   zStaticSetItem.__repr__  r^  r   Nr_  r   r   r   ra  ra  }  sA         
 
 
E E E E Er   ra  c                       e Zd ZdZd Zd ZdS )DelItemz
    del target[index]
    c                     t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   r   r   r   rr   r   )r   r   rr   r   s       r   r   zDelItem.__init__  s]    &#&&&&&%%%%%%#s#####
r   c                 (    d| j         d| j        dS )Nzdel r\  ])r   rr   r1   s    r   r2   zDelItem.__repr__  s     #{{{DJJJ77r   Nr_  r   r   r   re  re    s<           8 8 8 8 8r   re  c                       e Zd Zd Zd ZdS )SetAttrc                     t          |t                    sJ t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        d S r&   )r   r   rZ   r   r   r  r   r   )r   r   r  r   r   s        r   r   zSetAttr.__init__  sz    &#&&&&&$$$$$$%%%%%%#s#####	
r   c                 6    d| j         d| j        d| j        S )NrH  ). = )r   r  r   r1   s    r   r2   zSetAttr.__repr__  s!     !%diiiDDr   Nr   r   r   r   r2   r   r   r   rj  rj    s7          E E E E Er   rj  c                       e Zd Zd Zd ZdS )DelAttrc                     t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   r   rZ   r   r   r  r   )r   r   r  r   s       r   r   zDelAttr.__init__  s]    &#&&&&&$$$$$$#s#####	r   c                 &    d| j         d| j        S )Nzdel (rm  )r   r  r1   s    r   r2   zDelAttr.__repr__  s      $TYY77r   Nro  r   r   r   rq  rq    s2          8 8 8 8 8r   rq  c                       e Zd Zd Zd ZdS )StoreMapc                     t          |t                    sJ t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        d S r&   )r   r   r   dctkeyr   r   )r   rw  rx  r   r   s        r   r   zStoreMap.__init__  sz    #s######s#####%%%%%%#s#####
r   c                 4    | j         d| j        d| j        S r[  )rw  rx  r   r1   s    r   r2   zStoreMap.__repr__  s     $$(((DJJ??r   Nro  r   r   r   ru  ru    s7          @ @ @ @ @r   ru  c                       e Zd Zd Zd ZdS )Delc                 ~    t          |t                    sJ t          |t                    sJ || _        || _        d S r&   )r   rZ   r   r   r   r   r   r   s      r   r   zDel.__init__  s@    %%%%%%#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{    s2          % % % % %r   r{  c                   $    e Zd ZdZd Zd Zd ZdS )RaiseTc                     |t          |t                    sJ t          |t                    sJ || _        || _        d S r&   r   r   r   	exceptionr   r   r  r   s      r   r   zRaise.__init__  E     Jy#$>$>   #s#####"r   c                     d| j         z  S )Nzraise %sr  r1   s    r   r5   zRaise.__str__  s    DN**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    sF        G  + + +    r   r  c                   (    e Zd ZdZdZd Zd Zd ZdS )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 || _        || _        || _        d S r&   r   r!   r   r   	exc_classexc_argsr   r   r  r  r   s       r   r   zStaticRaise.__init__  g     Jy$$?$?   #s#####:h#>#>" r   c           	          | j         dS | j        
d| j         S d| j         dd                    t          t          | j                            dS )Nz<static> raisez<static> raise rH  r=  r0   r  r  rk   mapreprr1   s    r   r5   zStaticRaise.__str__  se    >!##]""*...:: # /3nnn%)YYs4/G/G%H%H%H%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    U         
 G  J J J    r   r  c                   (    e Zd ZdZdZd Zd Zd ZdS )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 || _        || _        || _        d S r&   r  r  s       r   r   zDynamicRaise.__init__  r  r   c           	          | j         dS | j        
d| j         S d| j         dd                    t          t          | j                            dS )Nz<dynamic> raisez<dynamic> raise rH  r=  r0   r  r1   s    r   r5   zDynamicRaise.__str__  se    >!$$]""+/>>;; # 04~~~%)YYs4/G/G%H%H%H%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dS )TryRaisezZA raise statement inside a try-block
    Similar to ``Raise`` but does not terminate.
    c                     |t          |t                    sJ t          |t                    sJ || _        || _        d S 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dS )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 || _        || _        || _        d S r&   r  r  s       r   r   zStaticTryRaise.__init__5  r  r   c                     | j         dS | j        
d| j          S d                    t          t          | j                            }d| j          d| dS )Nstatic_try_raisezstatic_try_raise r=  rH  r0   r  r   r   s     r   r5   zStaticTryRaise.__str__=  s`    >!&&]"7t~77799St}5566D?t~??????r   Nr  r   r   r   r  r  1  sA           @ @ @ @ @r   r  c                       e Zd ZdZd Zd ZdS )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 || _        || _        || _        d S r&   r  r  s       r   r   zDynamicTryRaise.__init__K  r  r   c                     | j         dS | j        
d| j          S d                    t          t          | j                            }d| j          d| dS )Ndynamic_try_raisezdynamic_try_raise r=  rH  r0   r  r  s     r   r5   zDynamicTryRaise.__str__S  s`    >!'']"888899St}5566D@@@@@@@r   Nr  r   r   r   r  r  G  sA           A A A A Ar   r  c                   (    e Zd ZdZdZd Zd Zd ZdS )Returnz
    Return to caller.
    Tc                     t          |t                    sJ t          |                      t          |t                    sJ || _        || _        d S r&   )r   r   r!   r   r   r   r}  s      r   r   zReturn.__init__c  sN    %%%22tE{{222#s#####
r   c                     d| j         z  S )Nz	return %sr  r1   s    r   r5   zReturn.__str__i  s    TZ''r   c                     g S r&   r   r1   s    r   r   zReturn.get_targetsl  r  r   Nr  r   r   r   r  r  ]  sR          G  ( ( (    r   r  c                   $    e Zd ZdZd Zd Zd ZdS )Jumpz
    Unconditional branch.
    c                 P    t          |t                    sJ || _        || _        d S 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  sK           
' ' '    r   r  c                   $    e Zd ZdZd Zd Zd ZdS )Branchz
    Conditional branch.
    c                     t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        d S r&   )r   r   r   condtruebrfalsebrr   )r   r  r  r  r   s        r   r   zBranch.__init__  sN    $$$$$$#s#####	r   c                 6    d| j         d| j        d| j        S )Nzbranch r=  )r  r  r  r1   s    r   r5   zBranch.__str__  s!     &*iiidllKKr   c                     | j         | j        gS r&   )r  r  r1   s    r   r   zBranch.get_targets  s    T\**r   Nr  r   r   r   r  r    sN           L L L+ + + + +r   r  c                       e Zd ZdZd Zd ZdS )Assignz
    Assign to a variable.
    c                     t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   r   r   r   r   r   r   )r   r   r   r   s       r   r   zAssign.__init__  s]    %-----&#&&&&&#s#####
r   c                 $    | j         d| j        S )Nrn  )r   r   r1   s    r   r5   zAssign.__str__  s     KKK44r   Nr  r   r   r   r  r    s<           5 5 5 5 5r   r  c                       e Zd ZdZd Zd ZdS )Printz
    Print some values.
    c                     t          d |D                       sJ |t          |t                    sJ t          |t                    sJ t	          |          | _        || _        i | _        || _        d S )Nc              3   @   K   | ]}t          |t                    V  d S r&   r  r?  r>   s     r   rA  z!Print.__init__.<locals>.<genexpr>  s,      44!:a%%444444r   )	allr   r   r   r   r   r   r   r   )r   r   r   r   s       r   r   zPrint.__init__  sx    44t44444444~FC!8!8~~~#s#####$KK	r   c                 P    dd                     d | j        D                       z  S )Nz	print(%s)r=  c              3   4   K   | ]}t          |          V  d S r&   r   r?  r   s     r   rA  z Print.__str__.<locals>.<genexpr>  s(      &A&A!s1vv&A&A&A&A&A&Ar   )rk   r   r1   s    r   r5   zPrint.__str__  s*    TYY&A&Aty&A&A&AAAAAr   Nr  r   r   r   r  r    sA           B B B B Br   r  c                        e Zd Zd Zd Zd ZdS )Yieldc                     t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   r   r   r   r   rr   )r   r   r   rr   s       r   r   zYield.__init__  sG    %%%%%%#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    sA          * * *    r   r  c                   $    e Zd ZdZd Zd Zd ZdS )	EnterWithzEnter a "with" context
    c                     t          |t                    sJ t          |t                    sJ || _        || _        || _        || _        dS )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__  sQ     .#.....#s#####,
r   c                 6    d                     | j                  S )Nzenter_with {})formatr  r1   s    r   r5   zEnterWith.__str__  s    %%d&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    sK           "; ; ;% % % % %r   r  c                       e Zd ZdZd Zd ZdS )PopBlockz(Marker statement for a pop block op codec                 B    t          |t                    sJ || _        d S r&   )r   r   r   )r   r   s     r   r   zPopBlock.__init__  s#    #s#####r   c                     dS )N	pop_blockr   r1   s    r   r5   zPopBlock.__str__      {r   Nr  r   r   r   r  r    s8        22      r   r  c                        e Zd Zd Zd Zd ZdS )Argc                     t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   rZ   r  r   r   rr   r   )r   r   rr   r   s       r   r   zArg.__init__  s]    $$$$$$%%%%%%#s#####	
r   c                 $    d| j         | j        fz  S )Nzarg(%d, name=%s))rr   r   r1   s    r   r2   zArg.__repr__  s    !TZ$;;;r   c                 4    t          d| z  | j                  rR  rT  r1   s    r   rU  zArg.infer_constant  rV  r   N)r   r   r   r   r2   rU  r   r   r   r  r    sF          < < <@ @ @ @ @r   r  c                   (    e Zd ZddZd Zd Zd ZdS )ConstTc                 ^    t          |t                    sJ || _        || _        || _        d S r&   )r   r   r   r   use_literal_type)r   r   r   r  s       r   r   zConst.__init__  s4    #s#####
 0r   c                 L    dt          | j                  j        d| j        dS )Nzconst(r=  r0   )r!   r   r   r1   s    r   r2   zConst.__repr__  s(     "&tz"2"2";";";TZZZHHr   c                     | j         S r&   r  r1   s    r   rU  zConst.infer_constant  
    zr   c                 D    t          | j        | j        | j                  S )N)r   r   r  )r  r   r   r  r   memos     r   __deepcopy__zConst.__deepcopy__	  s(    *$(!2
 
 
 	
r   NT)r   r   r   r   r2   rU  r  r   r   r   r  r    sX        1 1 1 1I I I  
 
 
 
 
r   r  c                   &    e Zd Zd Zd Zd Zd ZdS )Globalc                 ^    t          |t                    sJ || _        || _        || _        d S r&   )r   r   r   r   r   )r   r   r   r   s       r   r   zGlobal.__init__  s1    #s#####	
r   c                 (    d| j         d| j        dS )Nzglobal(: r0   r   r   r1   s    r   r5   zGlobal.__str__  s     #'999djjj99r   c                     | j         S r&   r  r1   s    r   rU  zGlobal.infer_constant  r  r   c                 f    t          | j        | j        t          j        | j                            S r&   )r  r   r   copydeepcopyr   r  s     r   r  zGlobal.__deepcopy__  s&     diT]48-D-DEEEr   N)r   r   r   r   r5   rU  r  r   r   r   r  r    sU          : : :  F F F F Fr   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )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 || _        || _        || _        || _        d S r&   )r   r  rZ   r   rr   r   r   r   )r   rr   r   r   r   s        r   r   zFreeVar.__init__*  sd    %%%%%%$$$$$$#s#####
	
r   c                 (    d| j         d| j        dS )Nzfreevar(r  r0   r  r1   s    r   r5   zFreeVar.__str__6  s     $(IIItzzz::r   c                     | j         S r&   r  r1   s    r   rU  zFreeVar.infer_constant9  r  r   c                 P    t          | j        | j        | j        | j                  S )N)rr   r   r   r   )r   rr   r   r   r   r  s     r   r  zFreeVar.__deepcopy__<  s*    TZditz8% % % 	%r   N)r   r   r   r   r   r5   rU  r  r   r   r   r   r   $  sZ         

 
 
; ; ;  % % % % %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             Zd	 Zd
S )r   zt
    Attributes
    -----------
    - scope: Scope

    - name: str

    - loc: Loc
        Definition location
    c                     |t          |t                    sJ t          |t                    sJ t          |t                    sJ || _        || _        || _        d S r&   )r   ScoperZ   r   r   r   r   )r   r   r   r   s       r   r   zVar.__init__O  s^    }
5% 8 8}}}$$$$$$#s#####
	r   c                 L    d| j         d| j                                        dS )NzVar(r=  r0   )r   r   r~   r1   s    r   r2   zVar.__repr__X  s'      $			48>>+;+;+;+;<<r   c                     | j         S r&   )r   r1   s    r   r5   zVar.__str__[  s
    yr   c                 6    | j                             d          S )N$)r   r<   r1   s    r   is_tempzVar.is_temp^  s    y##C(((r   c                 r    | j         j                                        D ]\  }}| j        |v r|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_nameb  sK     !J8>>@@ 	 	LAyyI%% &yr   c                 @    | 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    
 z))$*?@@@r   c                 "    | 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1149dhGGRXX
r   N)r   r   r   r   r   r2   r5   propertyr  r  r  r  r  r   r   r   r   r   C  s        	 	  = = =   ) ) X)   X A A XA ? ? X?
    r   r   c                   `    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dS )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                    | _        d S r&   )r   r  r   parentr   	localvarsr   r   r  	redefinedsetr  )r   r  r   s      r   r   zScope.__init__  sm    ~FE!:!:~~~#s#####$S))!,S!1!1r   c                 j    t          | ||          }| j                            |j        |           |S )z#
        Define a variable
        r   r   r   )r   r  r   r   )r   r   r   r   s       r   r   zScope.define  s7     d3///afa(((r   c                 b    || j         v rd|| j         |         fz  }|                     |          S )zC
        Refer to a variable.  Returns the latest version.
        %s.%d)r  	get_exactr   s     r   r   z	Scope.get  s9     4>!!dDN4$899D~~d###r   c                     	 | j                             |          S # t          $ r% | j        r| 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  s_    
	>%%d+++ 	 	 	 {t,,,,,		s    +A	Ac                     || j         v rd|| j         |         fz  }|| j        vr|                     ||          S | j                            |          S )Nr"  )r  r  r   r   )r   r   r   s      r   get_or_definezScope.get_or_define  s\    4>!!dDN4$899Dt~%%;;tS)))>%%d+++r   Tc                 V   || j         vr|                     ||          S |s| j                             |          S 	 | j        |         }|dz   | j        |<   d||dz   fz  }	 |                     ||          }| j        |                             |           n# t          $ r Y iw xY w|S )z9
        Redefine if the name is already defined
        Tr7   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33C *4044W==== &   H 
s   "B 
B&%B&c                 L     t                       fd |           S )z9
        Gets all known versions of a given name
        c                     j                             | d           }|r%|D ]$}                    |            |           #d S d S r&   )r  r   r)  )thenameredefsr   r   verswalks      r   r4  z#Scope.get_versions_of.<locals>.walk  sd    +//>>F   AHHQKKKDGGGG  r   )r  )r   r   r3  r4  s   ` @@r   r  zScope.get_versions_of  sG     uu	 	 	 	 	 	 	 	T


r   c                     t          | j                  }t          | d|z  |          }| j                            |j        |           |S )Nz$%dr   )r   r  r   r   r   )r   r   nr   s       r   	make_tempzScope.make_temp  sH    d444afa(((r   c                     | j         d uS r&   )r  r1   s    r   r%  zScope.has_parent  s    {$&&r   c                 J    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__  s-    6$/:=dn:M: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  ~  s         2 2 2  $ $ $  , , ,   .     ' ' X'D D D D 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dS )BlockzA code block

    c                     t          |t                    sJ t          |t                    sJ || _        g | _        || _        d S r&   )r   r  r   r   bodyr   )r   r   r   s      r   r   zBlock.__init__  sG    %'''''#s#####
	r   c                 b    t          | j        | j                  }| j        d d          |_        |S r&   )r;  r   r   r=  r   blocks     r   r  z
Block.copy  s+    dj$(++Yqqq\
r   Nc              #      K   | j         D ]D}t          |t                    r-|j        }t          |t                    r||j        |k    r|V  EdS )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       I 	# 	#D$'' #zdD)) #zTW]]"


	# 	#r   c              #   F   K   | j         D ]}t          ||          r|V  dS )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?       I 	 	D$$$ 


	 	r   c                 j    |                      t                    D ]}|j        j        |k    r|c S dS )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  sC    
 V,, 	 	Ax}$$ %tr   c                 j    t          |t                    sJ | j                            d|           d S rA   )r   r   r=  insertr   rB  s     r   prependzBlock.prepend  s6    $%%%%%	D!!!!!r   c                 h    t          |t                    sJ | j                            |           d S r&   )r   r   r=  re   rK  s     r   re   zBlock.append#  s4    $%%%%%	r   c                 t    t          |t                    sJ | j        | j                            |          = d S r&   )r   r   r=  rr   rK  s     r   removezBlock.remove'  s6    $%%%%%Idiood++,,,r   c                     | j         d d = d S r&   r=  r1   s    r   clearzBlock.clear+  s    IaaaLLLr   c                    |pt           j        }| j        D ]k}t          |d          r|                    |           (t          d |                                D                       }t          d|dd||           ld S )Ndumpc              3   4   K   | ]}t          |          V  d S r&   r   r  s     r   rA  zBlock.dump.<locals>.<genexpr>5  s(      "D"Da3q66"D"D"D"D"D"Dr   z    40r_   file)sysstdoutr=  hasattrrT  rK  r   print)r   rX  rB  	inst_varss       r   rT  z
Block.dump.  s    !szI 	E 	EDtV$$ E		$""D"D4>>3C3C"D"D"DDD	ii8tDDDDD	E 	Er   c                     | j         d         S Nra   rQ  r1   s    r   
terminatorzBlock.terminator8  s    y}r   c                 4    | j         o| j         d         j        S r_  )r=  r   r1   s    r   is_terminatedzBlock.is_terminated<  s    y8TYr]88r   c                     | j         st          d          | j        d d         D ]}|j        rt          d          d S )NzMissing block terminatorra   z&Terminator before the last instruction)rb  r   r=  r   rK  s     r   verifyzBlock.verify@  sg    ! 	@#$>???IcrcN 	7 	7D! 7' )6 7 7 77	7 	7r   c                 v    | j                             |          }| j                             |dz   |           dS )z.
        Insert *stmt* after *other*.
        r7   N)r=  rr   rJ  )r   stmtr#   rr   s       r   insert_afterzBlock.insert_afterI  s9     	&&	D)))))r   c                 |    t          |t                    sJ | j        sJ | j                            d|           d S r_  )r   r   rb  r=  rJ  )r   rf  s     r   insert_before_terminatorzBlock.insert_before_terminatorP  sE    $%%%%%!!!!	T"""""r   c                     d| j         dS )Nz<ir.Block at >rS  r1   s    r   r2   zBlock.__repr__U  s     %)XXX//r   r&   )r   r   r   r   r   r  rD  rF  rH  rL  re   rO  rR  rT  r  r`  rb  rd  rg  ri  r2   r   r   r   r;  r;    s9            
	# 	# 	# 	#     " " "  - - -  E E E E   X 9 9 X97 7 7* * *# # #
0 0 0 0 0r   r;  c                   "    e Zd ZdZdZd Zd ZdS )LoopzDescribes a loop-block
    entryexitc                 "    || _         || _        d S 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__b      z49$(4//r   Nr   r   r   r   r   r   r2   r   r   r   rm  rm  Y  A         I  0 0 0 0 0r   rm  c                   "    e Zd ZdZdZd Zd ZdS )WithzDescribes a with-block
    rn  c                 "    || _         || _        d S r&   rn  rr  s      r   r   zWith.__init__l  rs  r   c                 (    | j         | j        f}d|z  S )NzWith(entry=%s, exit=%s)rn  r  s     r   r2   zWith.__repr__p  ru  r   Nrv  r   r   r   ry  ry  g  rw  r   ry  c                   r    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dS )
FunctionIRc                     || _         || _        || _        || _        || _        || _        || _        |                                  d S 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  sM    (""'&&(((((r   c                 b    t          |           t          |          u r| j        |j        k    S dS )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$$;%,..ur   c           
         g }| j                                         D ]\  }}|j                             |d          }|||k    r|                    d|z                      dd                     d |j        D             }d |j        D             }||k    r8t          |          t          |          k    r|                    d|z             t          |j                  t          |j                  k    r|                    d           n?t          |j                  t          |j                  k     r|                    d	           g t          t          |j        |j                            D ]%\  }}	|	\  }
}|
|k    r                    |           &fd
}t          t          |j                  t          |j                            }t                      5 }d|fd|fg}|D ]\  }}|                    d           |                    |           |                                                                }	 ||j        |          }|d|}|                    |                    dd                     |                    d t          ||	          D                        	 ddd           n# 1 swxY w Y   |g k    r|                    d           d                    |          S )zw
        Compute a human readable difference in the IR, returns a formatted
        string ready for printing.
        NzBlock %s differsP   -c                 <    g | ]}t          |t                    |S r   r   r{  r  s     r   
<listcomp>z'FunctionIR.diff_str.<locals>.<listcomp>  s'     M M Mq*Q:L:L M M M Mr   c                 <    g | ]}t          |t                    |S r   r  r  s     r   r  z'FunctionIR.diff_str.<locals>.<listcomp>  s'    OOOQJq#<N<NOqOOOr   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|}|                    |           *|S )Nz-> r_   )r   rangere   )	ablocklpointersppadnstmtiitemrw   s	           r   get_padz$FunctionIR.diff_str.<locals>.get_pad  s|    "' \\C/  #F!&u - -A Cxx'.!"a'.')JJt,,,,"
r   r   r#   r   rW  z: block c                 @    g | ]\  }}d                      ||          S )z{0}{1}r  )r?  r@  bs      r   r  z'FunctionIR.diff_str.<locals>.<listcomp>  s6     (9 (9 (9$!Q1(=(= (9 (9 (9r   zIR is considered equivalent.
)r  r  r   re   centerr=  rK  r   rd   zipminr   truncaterT  getvalue
splitlinesrf   rk   )r   r#   msglabelr@  	other_blk	block_deloth_delrs   stmtsb_so_sr  min_stmt_lenbufitr   _blockr  titlerw   s                       @r   diff_strzFunctionIR.diff_str  se   
  K--// 6	: 6	:LE5((55I$I%%JJ 2U :BB2sKKLLL M MEJ M M MIOO).OOOG G++ "),,w??JJ )CFK(L M M M5:Y^)<)<<<

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

#IJJJ C&/EJ4=N1D 1D 'E 'E , ,
U#(S#::JJsOOO# # # # # $'s5:IN8K8K#L#LL! 
:s%uo/CD,. : :LD&LLOOO"KKSK111$'LLNN$=$=$?$?E")'&+|"D"DC7;ttUU%CEJJu||B'<'<===JJ (9 (9(+C(9 (9 (9 : : : ::
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: "99JJ5666yy~~s   )CKK
	K
	c                 b    t          j        |           | _        d | _        d | _        i | _        d S r&   )r   ConstantInference_constsgenerator_infovariable_lifetimeblock_entry_varsr1   s    r   r  z$FunctionIR._reset_analysis_variables  s4    /55 #!% "r   NFc                     |t          |                   }t          j        |           }||_        ||j        n||_        |rd|_        |||_        |||_        |                                 |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.
        NF)
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KK(
4'*{Z^^
 	("'F (F (F((***..00r   c                     t          j         |           }i }i }| j                                        D ]7\  }}|                                 }|||<   || j        v r| j        |         ||<   8||_        ||_        |S r&   )r  r  r  r  )r   r  r  r  r  r@  	new_blocks          r   r  zFunctionIR.copy  s    4 K--// 	K 	KLE5

I%F5M---.2.CE.J +"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                 n    t          |t                    r|j        }| j                            |          S )zF
        Try to infer the constant value of a given variable.
        )r   r   r   r  rU  r   s     r   rU  zFunctionIR.infer_constant	  s3     dC   	9D|**4000r   c                 F   |}	 t          |t                    r
|}|j        }n t          |t                    r|}|}n|r|n|S | j        |         }t          |          dk    rt          d|          t          |          dk    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.
        Tr   zno definition for r7   zmore than one definition for )r   r   r   rZ   r  r   r   )r   r   lhs_onlyr   r   defss         r   get_definitionzFunctionIR.get_definition  s     	%%% 2zE3'' 2&1ssE1$T*D4yyA~~h"&$ ) * * *4yy1}}h"&$ ) * * *GE!	r   c                 |    | j                                         }n?t          |t                    r j         |         g}n fdt	          |          D             }t          |t
                    sJ |D ]5}|                    t                    D ]}|j        |k    r|j	        c c S 6t          d|z            )z
        Finds the assignee for a given RHS value. If in_blocks is given the
        search will be limited to the specified blocks.
        Nc                 *    g | ]}j         |         S r   )r  )r?  blkr   s     r   r  z+FunctionIR.get_assignee.<locals>.<listcomp>4  s     BBB3dk#&BBBr   z!Could not find an assignee for %s)r  r   r   r  r   r   rF  r  r   r   rQ   )r   	rhs_value	in_blocksr  r  assigns   `     r   get_assigneezFunctionIR.get_assignee*  s    
 [''))FF	3'' 	Ck),-FFBBBB$y//BBBF)[11111 	) 	)C..00 ) )<9,,!=((((( -) <yHIIIr   c           
      &   |d u }|pt                      }t          | j                                                  D ]0\  }}t	          d|d|           |                    |           1|r|                                }t          j        rr	 dd l	}ddl	m
} ddlm} ddlm}	 ddlm}
 t	           || |             |
 |	            	                               d S # t           $ r d
}t#          |          w xY wt	          |           d S d S )Nzlabel r4   rW  r   )rh   )NumbaIRLexer)by_colorscheme)Terminal256Formatter)stylez0Please install pygments to see highlighted dumps)r   rK  r  r  r\  rT  r  r	   HIGHLIGHT_DUMPSpygmentsrh   numba.misc.dump_styler  r  pygments.formattersr  ImportErrorrQ   )r   rX  nofileoffsetr@  textr  rh   lexerr  r  r  s               r   rT  zFunctionIR.dump@  s   !xzz#DK$5$5$7$788 	" 	"MFEE)5555JJDJ!!!! 	==??D% 2#OOO
 322222KKKKKKDDDDDDHHHHHH))D%%''3G3G,n..40 40 40 1 1 2 2 2 2 2 # * * *LC$S//)* d!	 	s   C! !C=c                     t                      5 }|                     |           |                                cd d d            S # 1 swxY w Y   d S )NrW  )r   rT  r  )r   sbs     r   dump_to_stringzFunctionIR.dump_to_stringZ  s    ZZ 	!2II2I;;==	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   *AA
A
c           	      F   |pt           j        }| j        }t          dt	          |j                  |           t	          |j                                                  D ]@\  }}t          d|t	          |j                  t	          |j	                  fz  |           Ad S )Nzgenerator state variables:rW  z>yield point #%d: live variables = %s, weak live variables = %s)
rY  rZ  r  r\  rK  
state_varsyield_pointsr  	live_varsweak_live_vars)r   rX  girr   yps        r   dump_generator_infozFunctionIR.dump_generator_info_  s    !sz *F2=,A,AMMMM 5 5 7 788 	 	IE2RF2<00&9J2K2KLM    	 	r   numba_irTc                    	 ddl }n# t          $ r t          d          w xY w|                    d                    || j        j                            }| j                                        D ] \  }}t                      5 }|	                    |           |
                                }ddd           n# 1 swxY w Y   |rod                    d |                                D                       }d                    |          |z   }|                    t          |          |d	
           d                    |          }|                    t          |          |d
           | j                                        D ]Q\  }	}|j                                        D ]2}
|                    t          |	          t          |
                     3R|S )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   rU   c                 8    g | ]}d                      |          S )z  {}\lr  r  s     r   r  z)FunctionIR.render_dot.<locals>.<listcomp>  s&    EEEQY%%a((EEEr   z
block {}\lrect)r  shapez{}\lcircle)graphvizr  Digraphr  r-   unique_namer  r  r   rT  r  rk   r  noderZ   r`  r   edge)r   filename_prefix
include_irgvgrF  r  r  r  srcdsts              r   
render_dotzFunctionIR.render_doth  s-   	!!!!! 	 	 	=  	
 JJ&&(   
 
 k'')) 	< 	<FAs &r& & & & & & & & & & & & & & &  <EE%2B2B2D2DEEE  &,,Q//%7s1vvU&9999q))s1vvU(;;;;))++ 	+ 	+HC~1133 + +s3xxS****+s    !*B;;B?	B?	)NNFN)Fr&   )r  T)r   r   r   r   r  r  r  r  r  r  rU  r  r  rT  r  r  r  r   r   r   r}  r}  u  s       ) ) )  ? ? ?B# # # 8<.2   0  , , ,1 1 1   2J J J J,   4! ! !
   ) ) ) ) ) )r   r}  c                       e Zd ZdZd Zd ZdS )UndefinedTypeNc                 ^    | j         }||S t                              |           }|| _         |S r&   )
_singletonobject__new__)r,   objs     r   r  zUndefinedType.__new__  s0    n?J..%%C CN
r   c                     dS )N	Undefinedr   r1   s    r   r2   zUndefinedType.__repr__  r  r   )r   r   r   r  r  r2   r   r   r   r  r    s7        J      r   r  )Mcollectionsr   r  rX   rO   rJ   r   r   rY  r"  typesr   r   	functoolsr   ior   
numba.corer   r	   numba.core.utilsr
   r   r   r   numba.core.errorsr   r   r   r   r   	termcolorrg   r  r   unknown_locr   r   r   r   r   r   r   r   rX  ra  re  rj  rq  ru  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 3 3 3 3 3 3 3 $ $ $ $ $ $       % % % % % % % %Q Q Q Q Q Q Q Q Q Q Q QJ J J J J J J J J J J J       V
x4 x4 x4 x4 x4& x4 x4 x4x c$a++     V   *        0&& && && && &&V && && &&R    &       {   B2 2 2 2 24 2 2 2. . . . . . . . q@ q@ q@ q@ q@4 q@ q@ q@hE E E E Ed E E E&E E E E ED E E E*8 8 8 8 8d 8 8 8"E E E E Ed E E E
8 
8 
8 
8 
8d 
8 
8 
8@ @ @ @ @t @ @ @% % % % %$ % % %    J        *   :    :   :/ / / / /t / / /@ @ @ @ @T @ @ @,A A A A Ad A A A,    Z   &    :   "+ + + + +Z + + +(5 5 5 5 5T 5 5 5 B B B B BD B B B$    D   % % % % % % % %6    t   @ @ @ @ @
k @ @ @ 
 
 
 
 
 
 
 
,F F F F F F F F&% % % % % + % % %>8 8 8 8 8
k 8 8 8vpD pD pD pD pD pD pD pDfe0 e0 e0 e0 e0 e0 e0 e0P0 0 0 0 0! 0 0 00 0 0 0 0! 0 0 0\ \ \ \ \ \ \ \@	    &   " MOO			r   