B
      ›\]  ã               @   s\   d dl mZmZmZ d dlmZ d dlmZ G dd„ deƒZ	G dd„ deƒZ
e
ƒ ZejZdS )	é    )Úprint_functionÚdivisionÚabsolute_import)Údefaultdict)Úconfigc               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚRewritez8Defines the abstract base class for Numba rewrites.
    c             C   s
   || _ dS )z+Constructor for the Rewrite class.
        N)Úpipeline)Úselfr   © r
   ú6lib/python3.7/site-packages/numba/rewrites/registry.pyÚ__init__   s    zRewrite.__init__c             C   s   dS )z]Overload this method to check an IR block for matching terms in the
        rewrite.
        Fr
   )r	   Úfunc_irÚblockÚtypemapÚ	calltypesr
   r
   r   Úmatch   s    zRewrite.matchc             C   s   t dƒ‚dS )zgOverload this method to return a rewritten IR basic block when a
        match has been found.
        z Abstract Rewrite.apply() called!N)ÚNotImplementedError)r	   r
   r
   r   Úapply   s    zRewrite.applyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r
   r
   r
   r   r      s   r   c               @   s4   e Zd ZdZeddgƒZdd„ Zdd„ Zdd	„ Zd
S )ÚRewriteRegistryz+Defines a registry for Numba rewrites.
    zbefore-inferencezafter-inferencec             C   s   t tƒ| _dS )ziConstructor for the rewrite registry.  Initializes the rewrites
        member to an empty list.
        N)r   ÚlistÚrewrites)r	   r
   r
   r   r   #   s    zRewriteRegistry.__init__c                s*   ˆ ˆj krtdˆ f ƒ‚‡ ‡fdd„}|S )zf
        Decorator adding a subclass of Rewrite to the registry for
        the given *kind*.
        zinvalid kind %rc                s,   t | tƒstd | ¡ƒ‚ˆjˆ   | ¡ | S )Nz {0} is not a subclass of Rewrite)Ú
issubclassr   Ú	TypeErrorÚformatr   Úappend)Úrewrite_cls)Úkindr	   r
   r   Údo_register0   s
    
z-RewriteRegistry.register.<locals>.do_register)Ú_kindsÚKeyError)r	   r    r!   r
   )r    r	   r   Úregister)   s    
zRewriteRegistry.registerc             C   s  || j kst‚|j}| ¡ }xÀ| j| D ]²}||ƒ}t| ¡ ƒ}x˜|rØ| ¡ \}	}
| ||
|j	|j
¡}|rBtjsvtjrœtdƒ td|j ƒ |
 ¡  tdƒ | ¡ }|||	< | |	|f¡ tjsÆtjrB| ¡  tdƒ qBW q(W x(| ¡ D ]\}	}
|
||	 krè|
 ¡  qèW dS )zŽGiven a pipeline and a dictionary of basic blocks, exhaustively
        attempt to apply all registered rewrites to all basic blocks.
        ZF______________________________________________________________________zREWRITING (%s):Z<____________________________________________________________N)r"   ÚAssertionErrorÚblocksÚcopyr   r   ÚitemsÚpopr   r   r   r   ÚDEBUGZDUMP_IRÚprintr   Údumpr   r   Zverify)r	   r    r   r   r&   Z
old_blocksr   ZrewriteZ	work_listÚkeyr   ZmatchesZ	new_blockr
   r
   r   r   8   s2    zRewriteRegistry.applyN)	r   r   r   r   Ú	frozensetr"   r   r$   r   r
   r
   r
   r   r      s
   r   N)Z
__future__r   r   r   Úcollectionsr   Znumbar   Úobjectr   r   Zrewrite_registryr$   Zregister_rewriter
   r
   r
   r   Ú<module>   s   ;