U
    9%e	|                     @   s  d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ G dd deeZG dd deZed	d
dgZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deeZG dd deeZG dd deeZG d d! d!eZG d"d# d#eZG d$d% d%eZ G d&d' d'e Z!G d(d) d)e Z"G d*d+ d+eZ#G d,d- d-eZ$G d.d/ d/eZ%G d0d1 d1eZ&G d2d3 d3eZ'G d4d5 d5eZ(G d6d7 d7eZ)G d8d9 d9eZ*G d:d; d;eZ+G d<d= d=eZ,G d>d? d?eZ-G d@dA dAeZ.G dBdC dCeZ/G dDdE dEeZ0G dFdG dGe1Z2G dHdI dIeZ3G dJdK dKeZ4G dLdM dMe1Z5G dNdO dOe5Z6G dPdQ dQe5Z7G dRdS dSeZ8G dTdU dUeZ9G dVdW dWeZ:dXS )Yz)
Implementation of LLVM IR instructions.
    )types)
BlockFunctionValue
NamedValueConstantMetaDataArgumentMetaDataStringAttributeSet	UndefinedArgumentAttributes)_HasMetadatac                       sN   e Zd Zd fdd	Zedd Zedd Zd	d
 Zdd Zdd Z	  Z
S )Instruction  c                    sV   t t| j|||d t|ts$tt|ttfs6t|| _|| _	t|| _
i | _d S Nname)superr   __init__
isinstancer   AssertionErrortuplelistopnameoperandsflagsmetadata)selfparenttypr   r   r   r   	__class__r   W/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/llvmlite/ir/instructions.pyr      s    
zInstruction.__init__c                 C   s   | j jS N)r   functionr   r   r   r#   r%      s    zInstruction.functionc                 C   s
   | j jjS r$   )r   r%   moduler&   r   r   r#   r'      s    zInstruction.modulec                 C   s`   | j }| jrd|g| j }ddd | jD }| j}| jdd}|d|||| d S )N , c                 S   s   g | ]}|  qS r   )get_reference.0opr   r   r#   
<listcomp>"   s     z%Instruction.descr.<locals>.<listcomp>TZleading_comma{0} {1} {2}{3}
)r   r   joinr   type_stringify_metadataappendformat)r   bufr   r   r    r   r   r   r#   descr   s       zInstruction.descrc                 C   sF   || j krBg }| j D ]}|||kr(|n| qt|| _ |   d S r$   )r   r4   r   Z_clear_string_cache)r   oldnewZopsr-   r   r   r#   replace_usage(   s    


zInstruction.replace_usagec                 C   s   d| j j| j| j| j| jf S )Nz/<ir.%s %r of type '%s', opname %r, operands %r>)r"   __name__r   r2   r   r   r&   r   r   r#   __repr__0   s       zInstruction.__repr__)r   r   )r;   
__module____qualname__r   propertyr%   r'   r7   r:   r<   __classcell__r   r   r!   r#   r      s   	


r   c                   @   s    e Zd ZeddddddgZdS )CallInstrAttributesZnoreturnZnounwindreadonlyZreadnoneZnoinlineZalwaysinlineNr;   r=   r>   	frozensetZ_knownr   r   r   r#   rA   6   s   
 rA   tailZmusttailZnotailc                	   @   s$   e Zd ZeddddddddgZd	S )
FastMathFlagsfastnnanninfnszarcpcontractafnreassocNrC   r   r   r   r#   rF   >   s    rF   c                       sh   e Zd Zd fdd	Zedd Zejdd Zed	d
 Zdd Zedd Z	dd Z
dd Z  ZS )	CallInstrr   Nr   c
                    sX  |d krt |tr|jn|| _t |tr2|tkr2n|r<d}nd}|| _t|| _t	|| _
i | _|	r|	 D ]>\}
}d|
  krt|k sn td|
t|| j|
< qlt|}tt|jjD ]f}|| }|jj| }t |tjr|j|krt|}|j|kr"dd| ||j}t||||< qtt| j||jjd|gt| |d d S )	NrE   r   r   zInvalid argument index {}z%Type of #{0} arg mismatch: {1} != {2}   callr   )r   r   Zcalling_conventioncconvstrTailMarkerOptionsrE   rF   fastmathrA   
attributesarg_attributesitemslen
ValueErrorr5   r   r   rangefunction_typeargsr   ZMetaDataTyper2   r   	TypeErrorr   rO   r   return_type)r   r   funcr]   r   rR   rE   rU   attrs	arg_attrsidxiargexpected_typemsgr!   r   r#   r   D   sV    

  
  zCallInstr.__init__c                 C   s
   | j d S Nr   r   r&   r   r   r#   calleeo   s    zCallInstr.calleec                 C   s   || j d< d S rh   ri   )r   Z	newcalleer   r   r#   rj   s   s    c                 C   s   | j dd  S NrP   ri   r&   r   r   r#   r]   w   s    zCallInstr.argsc                 C   s    |j | jj krtd|| _d S )Nz"New function has incompatible type)r\   rj   r^   )r   Znewfuncr   r   r#   replace_callee{   s    zCallInstr.replace_calleec                 C   s   | j S )zThe callee function)rj   r&   r   r   r#   called_function   s    zCallInstr.called_functionc           
         s   fdd d  fddtjD }jj}|jr>|}n|j}d|j }j	rjdj	|}d}j
rdj
}jrd	d	 j|j nd}jrd	d	 j|j nd}	|d
j|j||	|||rjddndd d S )Nc                    s@   |  j kr(d j |  |jd }nd}d|j|| S )Nr(   r   
{0} {1}{2})rW   r1   _to_listr2   r5   r*   )rd   ara   r&   r   r#   	descr_arg   s    
z#CallInstr._descr.<locals>.descr_argr)   c                    s   g | ]\}} ||qS r   r   )r,   rd   rp   )rq   r   r#   r.      s     z$CallInstr._descr.<locals>.<listcomp>{0} {1}r   z{0} r(   z2{tail}{op}{fastmath} {callee}({args}){attr}{meta}
Tr/   )rE   r-   rj   rU   r]   attrmeta)r1   	enumerater]   rj   r\   Zvar_argr_   r5   r*   rR   rE   rV   ro   rU   r4   r   r3   )
r   r6   add_metadatar]   ZfntytyZ
callee_refZtail_markerZfn_attrsZfm_attrsr   )rq   r   r#   _descr   s>    zCallInstr._descrc                 C   s   | j |dd d S )NTrv   )rx   r   r6   r   r   r#   r7      s    zCallInstr.descr)r   NNr   r   N)r;   r=   r>   r   r?   rj   setterr]   rl   rm   rx   r7   r@   r   r   r!   r#   rO   C   s          +



*rO   c                       s*   e Zd Zd fdd	Z fddZ  ZS )	InvokeInstrr   Nr   c                    sT   t |tstt |tsttt| j|||||d||	|
d	 d| _|| _|| _d S )NF)rE   rU   ra   rb   Zinvoke)	r   r   r   r   r|   r   r   	normal_to	unwind_to)r   r   r`   r]   r}   r~   r   rR   rU   ra   rb   r!   r   r#   r      s      zInvokeInstr.__init__c                    sB   t t| j|dd |dj| j | j | jddd d S )NFry   z.      to label {0} unwind label {1}{metadata}
Tr/   )r   )	r   r|   rx   r4   r5   r}   r*   r~   r3   rz   r!   r   r#   r7      s    
zInvokeInstr.descr)r   Nr   r   Nr;   r=   r>   r   r7   r@   r   r   r!   r#   r|      s           r|   c                       s$   e Zd Z fddZdd Z  ZS )
Terminatorc                    s   t t| |t || d S r$   )r   r   r   r   VoidType)r   r   r   r   r!   r   r#   r      s    zTerminator.__init__c                 C   s@   | j }ddd | jD }| jdd}|d||| d S )Nr)   c                 S   s   g | ]}d  |j| qS rr   r5   r2   r*   r+   r   r   r#   r.      s   z$Terminator.descr.<locals>.<listcomp>Tr/   rn   )r   r1   r   r3   r4   r5   )r   r6   r   r   r   r   r   r#   r7      s    
zTerminator.descrr   r   r   r!   r#   r      s   r   c                   @   s   e Zd Zdd ZdS )PredictableInstrc                 C   sZ   t | jdg}|D ]*}|dk r&td|ttd| q| j|}| d| d S )NZbranch_weightsr   z(branch weight must be a positive integer    Zprof)	r	   r'   rZ   r4   r   r   IntTyperv   Zset_metadata)r   weightsr   wmdr   r   r#   set_weights   s    zPredictableInstr.set_weightsN)r;   r=   r>   r   r   r   r   r#   r      s   r   c                       s2   e Zd Zd fdd	Zedd Zdd Z  ZS )	RetNc                    s*   |d k	r|gng }t t| ||| d S r$   )r   r   r   )r   r   r   return_valuer   r!   r   r#   r      s    zRet.__init__c                 C   s   | j r| j d S d S d S rh   ri   r&   r   r   r#   r      s    
zRet.return_valuec                 C   sR   | j }| jdd}|d k	r:|d| j|j| | n|d| j| d S )NTr/   r0   z{0}{1}
)r   r3   r4   r5   r   r2   r*   )r   r6   r   r   r   r   r#   r7      s     z	Ret.descr)N)r;   r=   r>   r   r?   r   r7   r@   r   r   r!   r#   r      s   
r   c                   @   s   e Zd ZdS )BranchNr;   r=   r>   r   r   r   r#   r      s   r   c                   @   s   e Zd ZdS )ConditionalBranchNr   r   r   r   r#   r      s   r   c                       s8   e Zd Z fddZedd Zdd Zdd Z  ZS )	IndirectBranchc                    s    t t| |||g g | _d S r$   )r   r   r   destinations)r   r   r   addrr!   r   r#   r     s    zIndirectBranch.__init__c                 C   s
   | j d S rh   ri   r&   r   r   r#   address  s    zIndirectBranch.addressc                 C   s   t |tst| j| d S r$   )r   r   r   r   r4   )r   blockr   r   r#   add_destination
  s    zIndirectBranch.add_destinationc              
   C   sB   dd | j D }|d| jj| j d|| jdd d S )Nc                 S   s   g | ]}d  | qS )z	label {0}r5   r*   )r,   blkr   r   r#   r.     s   z(IndirectBranch.descr.<locals>.<listcomp>zindirectbr {0} {1}, [{2}]  {3}
r)   Tr/   )r   r4   r5   r   r2   r*   r1   r3   )r   r6   r   r   r   r#   r7     s    
zIndirectBranch.descr)	r;   r=   r>   r   r?   r   r   r7   r@   r   r   r!   r#   r     s
   
r   c                       s8   e Zd Z fddZedd Zdd Zdd Z  ZS )	SwitchInstrc                    s&   t t| |||g || _g | _d S r$   )r   r   r   defaultcases)r   r   r   valr   r!   r   r#   r     s    zSwitchInstr.__init__c                 C   s
   | j d S rh   ri   r&   r   r   r#   value   s    zSwitchInstr.valuec                 C   s:   t |tstt |ts&t| jj|}| j||f d S r$   )	r   r   r   r   r   r   r2   r   r4   )r   r   r   r   r   r#   add_case$  s    
zSwitchInstr.add_casec                 C   sJ   dd | j D }|d| jj| j | j d|| jdd d S )Nc                 S   s(   g | ] \}}d  |j| | qS )z{0} {1}, label {2}r   r,   r   r   r   r   r#   r.   +  s   z%SwitchInstr.descr.<locals>.<listcomp>z%switch {0} {1}, label {2} [{3}]  {4}
r(   Tr/   )	r   r4   r5   r   r2   r*   r   r1   r3   )r   r6   r   r   r   r#   r7   *  s    
zSwitchInstr.descr)	r;   r=   r>   r   r?   r   r   r7   r@   r   r   r!   r#   r     s
   
r   c                   @   s   e Zd ZdS )ResumeNr   r   r   r   r#   r   7  s   r   c                       sJ   e Zd Zd fdd	Zedd Zedd Zed	d
 Zdd Z  Z	S )SelectInstrr   r   c                    s8   |j |j ksttt| j||j d|||g||d d S )Nselectr   r   )r2   r   r   r   r   )r   r   condlhsrhsr   r   r!   r   r#   r   <  s     zSelectInstr.__init__c                 C   s
   | j d S rh   ri   r&   r   r   r#   r   B  s    zSelectInstr.condc                 C   s
   | j d S rk   ri   r&   r   r   r#   r   F  s    zSelectInstr.lhsc                 C   s
   | j d S )N   ri   r&   r   r   r#   r   J  s    zSelectInstr.rhsc                 C   sP   | dd| j| jj| j | jj| j | jj| j | j	dd d S )Nz)select {0} {1} {2}, {3} {4}, {5} {6} {7}
r(   Tr/   )
r4   r5   r1   r   r   r2   r*   r   r   r3   rz   r   r   r#   r7   N  s    
   
zSelectInstr.descr)r   r   )
r;   r=   r>   r   r?   r   r   r   r7   r@   r   r   r!   r#   r   ;  s   


r   c                       s2   e Zd ZdZi Zdg f fdd	Zdd Z  ZS )CompareInstrzinvalid-comparer   c           
         s   || j krtd|| jf |D ] }|| jkr td|| jf q | j}t|jtjrnttd|jj	}	n
td}	t
t| j||	|||g||d || _d S )Nzinvalid comparison %r for %szinvalid flag %r for %srP   )r   r   )VALID_OPrZ   OPNAME
VALID_FLAGr   r2   r   
VectorTyper   countr   r   r   r-   )
r   r   r-   r   r   r   r   flagr   r    r!   r   r#   r   ]  s     


  zCompareInstr.__init__c                 C   s\   | dj| jddd | jD | j| jd j| jd  | jd  | j	ddd	 d S )
Nz.{opname}{flags} {op} {ty} {lhs}, {rhs} {meta}
r   c                 s   s   | ]}d | V  qdS )r(   Nr   )r,   itr   r   r#   	<genexpr>p  s     z%CompareInstr.descr.<locals>.<genexpr>r   rP   Tr/   )r   r   r-   rw   r   r   rt   )
r4   r5   r   r1   r   r-   r   r2   r*   r3   rz   r   r   r#   r7   m  s    

zCompareInstr.descr)r;   r=   r>   r   r   r   r7   r@   r   r   r!   r#   r   X  s   r   c                   @   s0   e Zd ZdZdddddddd	d
dd
Ze ZdS )	ICMPInstrZicmpequalz	not equalzunsigned greater thanzunsigned greater or equalzunsigned less thanzunsigned less or equalzsigned greater thanzsigned greater or equalzsigned less thanzsigned less or equal)
eqneugtugeultuleZsgtZsgeZsltZsleN)r;   r=   r>   r   r   setr   r   r   r   r#   r   y  s   r   c                   @   sJ   e Zd ZdZdddddddd	d
ddddddddZddddddddhZdS )	FCMPInstrZfcmpz#no comparison, always returns falsezordered and equalzordered and greater thanz!ordered and greater than or equalzordered and less thanzordered and less than or equalzordered and not equalzordered (no nans)zunordered or equalzunordered or greater thanz"unordered or greater than or equalzunordered or less thanzunordered or less than or equalzunordered or not equalzunordered (either nans)z"no comparison, always returns true)falseZoeqZogtZogeZoltZoleoneordZueqr   r   r   r   ZuneZunotruerH   rI   rJ   rK   rL   rM   rN   rG   N)r;   r=   r>   r   r   r   r   r   r   r#   r     s*   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )	CastInstrr   c                    s    t t| j||||g|d d S r   )r   r   r   )r   r   r-   r   r    r   r!   r   r#   r     s    zCastInstr.__init__c                 C   s:   | d| j| jd j| jd  | j| jdd d S )Nz{0} {1} {2} to {3} {4}
r   Tr/   )r4   r5   r   r   r2   r*   r3   rz   r   r   r#   r7     s    

zCastInstr.descr)r   r   r   r   r!   r#   r     s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )	LoadInstrr   c                    s*   t t| j||jjd|g|d d | _d S )Nloadr   )r   r   r   r2   pointeealign)r   r   ptrr   r!   r   r#   r     s
     zLoadInstr.__init__c                 C   sP   | j \}| jd k	rd| j }nd}|d|jj|j| || jdd d S )N
, align %dr   zload {0}, {1} {2}{3}{4}
Tr/   )r   r   r4   r5   r2   r   r*   r3   )r   r6   r   r   r   r   r#   r7     s    

zLoadInstr.descr)r   r   r   r   r!   r#   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )
StoreInstrc                    s"   t t| |t d||g d S )Nstore)r   r   r   r   r   )r   r   r   r   r!   r   r#   r     s    zStoreInstr.__init__c                 C   sV   | j \}}| jd k	r d| j }nd}|d|j| |j| || jdd d S )Nr   r   zstore {0} {1}, {2} {3}{4}{5}
Tr/   )r   r   r4   r5   r2   r*   r3   )r   r6   r   r   r   r   r   r#   r7     s    


zStoreInstr.descrr   r   r   r!   r#   r     s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )LoadAtomicInstrr   c                    s0   t t| j||jjd|g|d || _|| _d S )Nzload atomicr   )r   r   r   r2   r   orderingr   )r   r   r   r   r   r   r!   r   r#   r     s      zLoadAtomicInstr.__init__c                 C   s<   | j \}|d|jj|j| | j| j| jdd d S )Nz+load atomic {0}, {1} {2} {3}, align {4}{5}
Tr/   )	r   r4   r5   r2   r   r*   r   r   r3   )r   r6   r   r   r   r#   r7     s    
zLoadAtomicInstr.descr)r   r   r   r   r!   r#   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )StoreAtomicInstrc                    s.   t t| |t d||g || _|| _d S )Nzstore atomic)r   r   r   r   r   r   r   )r   r   r   r   r   r   r!   r   r#   r     s     zStoreAtomicInstr.__init__c                 C   sB   | j \}}|d|j| |j| | j| j| jdd d S )Nz0store atomic {0} {1}, {2} {3} {4}, align {5}{6}
Tr/   )r   r4   r5   r2   r*   r   r   r3   )r   r6   r   r   r   r   r#   r7     s    

zStoreAtomicInstr.descrr   r   r   r!   r#   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )AllocaInstrc                    s4   |r
|gnd}t t| || d|| d | _d S )Nr   Zalloca)r   r   r   
as_pointerr   )r   r   r    r   r   r   r!   r   r#   r     s     zAllocaInstr.__init__c                 C   sv   | d| j| jj | jr>| j\}| d|j|  | jd k	rZ| d| j | jrr| | j	dd d S )Nrr   z	, {0} {1}z, align {0}Tr/   )
r4   r5   r   r2   r   r   r*   r   r   r3   )r   r6   r-   r   r   r#   r7   	  s    
zAllocaInstr.descrr   r   r   r!   r#   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )GEPInstrc           
         s   |j }d }d}|D ]&}	|||	 }}t|tjr|j}qt|tjsXt|tjrX|}n
||}tt| j	||d|gt
| |d || _|| _|| _d S )Nr   getelementptrr   )r2   Zgepr   r   ZPointerTypeZ	addrspacer   r   r   r   r   pointerindicesinbounds)
r   r   r   r   r   r   r    ZlasttypZlastaddrspacerd   r!   r   r#   r     s&    

 zGEPInstr.__init__c                 C   sZ   dd | j D }| jrdnd}|d|| jjj| jj| j d|| j	dd d S )	Nc                 S   s   g | ]}d  |j| qS r   r   r,   rd   r   r   r#   r.   ,  s   z"GEPInstr.descr.<locals>.<listcomp>zgetelementptr inboundsr   z{0} {1}, {2} {3}, {4} {5}
r)   Tr/   )
r   r   r4   r5   r   r2   r   r*   r1   r3   )r   r6   r   r-   r   r   r#   r7   +  s    
zGEPInstr.descrr   r   r   r!   r#   r     s   r   c                       s6   e Zd Zd
 fdd	Zdd Zdd Zdd	 Z  ZS )PhiInstrr   c                    s&   t t| j||dd||d g | _d S )Nphir   r   )r   r   r   	incomings)r   r   r    r   r   r!   r   r#   r   :  s    zPhiInstr.__init__c              
   C   sB   d dd | jD }|dd | j| j|| jdd d S )Nr)   c                 s   s&   | ]\}}d  | | V  qdS )z
[{0}, {1}]Nr   )r,   vbr   r   r#   r   @  s   
z!PhiInstr.descr.<locals>.<genexpr>zphi {0} {1} {2} {3}
r(   Tr/   )r1   r   r4   r5   r   r2   r3   )r   r6   Zincsr   r   r#   r7   ?  s    


zPhiInstr.descrc                 C   s"   t |tst| j||f d S r$   )r   r   r   r   r4   )r   r   r   r   r   r#   add_incomingJ  s    zPhiInstr.add_incomingc                    s    fdd| j D | _ d S )Nc                    s$   g | ]\}}|kr n||fqS r   r   r   r9   r8   r   r#   r.   O  s   z*PhiInstr.replace_usage.<locals>.<listcomp>)r   )r   r8   r9   r   r   r#   r:   N  s    zPhiInstr.replace_usage)r   )r;   r=   r>   r   r7   r   r:   r@   r   r   r!   r#   r   9  s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )ExtractElementr   c                    sV   t |jtjstdt |jtjs,td|jj}tt| j	||d||g|d d S )N!vector needs to be of VectorType.index needs to be of IntType.Zextractelementr   )
r   r2   r   r   r^   r   elementr   r   r   )r   r   vectorindexr   r    r!   r   r#   r   T  s     zExtractElement.__init__c                 C   s0   d dd | jD }|dj| j|d d S )Nr)   c                 s   s    | ]}d  |j| V  qdS rr   Nr   r+   r   r   r#   r   ^  s
    z'ExtractElement.descr.<locals>.<genexpr>{opname} {operands}
r   r   r1   r   r4   r5   r   r   r6   r   r   r   r#   r7   ]  s    
 zExtractElement.descr)r   r   r   r   r!   r#   r   S  s   	r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )InsertElementr   c                    sz   t |jtjstd|j|jjks:td|jj|jt |jtjsPtd|j}tt	| j
||d|||g|d d S )Nr   z$value needs to be of type {} not {}.r   Zinsertelementr   )r   r2   r   r   r^   r   r5   r   r   r   r   )r   r   r   r   r   r   r    r!   r   r#   r   e  s       zInsertElement.__init__c                 C   s0   d dd | jD }|dj| j|d d S )Nr)   c                 s   s    | ]}d  |j| V  qdS r   r   r+   r   r   r#   r   s  s
    z&InsertElement.descr.<locals>.<genexpr>r   r   r   r   r   r   r#   r7   r  s    
 zInsertElement.descr)r   r   r   r   r!   r#   r   d  s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )ShuffleVectorr   c                    s   t |jtjstd|tkr2|j|jkr2tdt |trht |jtjrht |jjtjrh|jjj	dksptdt|jj|jj
}t|tkr|jj
n
d|jj
  t fdd|jD std tt| j||d	|||g|d
 d S )Nz"vector1 needs to be of VectorType.z=vector2 needs to be Undefined or of the same type as vector1.r   z'mask needs to be a constant i32 vector.r   c                 3   s   | ]}|j  kV  qd S r$   )constant)r,   iiZindex_ranger   r#   r     s     z)ShuffleVector.__init__.<locals>.<genexpr>zmask values need to be in {0}Zshufflevectorr   )r   r2   r   r   r^   r   r   r   r   widthr   r[   allr   
IndexErrorr5   r   r   r   )r   r   Zvector1Zvector2maskr   r    r!   r   r#   r   z  s6    


 zShuffleVector.__init__c                 C   s0   | dddd | jD | jdd d S )Nzshufflevector {0} {1}
r)   c                 s   s    | ]}d  |j| V  qdS r   r   r+   r   r   r#   r     s   z&ShuffleVector.descr.<locals>.<genexpr>Tr/   )r4   r5   r1   r   r3   rz   r   r   r#   r7     s    

zShuffleVector.descr)r   r   r   r   r!   r#   r   y  s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )ExtractValuer   c              	      sz   |j }z|D ]}|j| }qW n. ttfk
rL   tdt||j f Y nX tt| j||d|g|d || _	|| _
d S )NCan't index at %r in %sZextractvaluer   )r2   elementsAttributeErrorr   r^   r   r   r   r   	aggregater   )r   r   aggr   r   r    rd   r!   r   r#   r     s     zExtractValue.__init__c              
   C   sB   dd | j D }|d| jj| j d|| jdd d S )Nc                 S   s   g | ]}t |qS r   rS   r   r   r   r#   r.     s     z&ExtractValue.descr.<locals>.<listcomp>zextractvalue {0} {1}, {2} {3}
r)   Tr/   )r   r4   r5   r   r2   r*   r1   r3   r   r6   r   r   r   r#   r7     s    
zExtractValue.descr)r   r   r   r   r!   r#   r     s   r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )InsertValuer   c              	      s   |j }z|D ]}|j| }qW n. ttfk
rL   tdt||j f Y nX |j |krttd|t||j |j f tt| j||j d||g|d || _	|| _
|| _d S )Nr   z&Can only insert %s at %r in %s: got %sZinsertvaluer   )r2   r   r   r   r^   r   r   r   r   r   r   r   )r   r   r   elemr   r   r    rd   r!   r   r#   r     s&    
 zInsertValue.__init__c                 C   sP   dd | j D }|d| jj| j | jj| j d|| jdd d S )Nc                 S   s   g | ]}t |qS r   r   r   r   r   r#   r.     s     z%InsertValue.descr.<locals>.<listcomp>z&insertvalue {0} {1}, {2} {3}, {4} {5}
r)   Tr/   )	r   r4   r5   r   r2   r*   r   r1   r3   r   r   r   r#   r7     s      
zInsertValue.descr)r   r   r   r   r!   r#   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )Unreachablec                    s"   t t| j|t dddd d S )NZunreachabler   r   r   )r   r   r   r   r   )r   r   r!   r   r#   r     s
      zUnreachable.__init__c                 C   s   || j df7 }d S )N
)r   rz   r   r   r#   r7     s    zUnreachable.descrr   r   r   r!   r#   r     s   r   c                   @   s.   e Zd ZdddZdd Zdd Zdd	 Zd
S )	InlineAsmFc                 C   s$   |j | _|| _|| _|| _|| _d S r$   )r_   r2   r\   asm
constraintside_effect)r   Zftyper   r   r   r   r   r#   r     s
    zInlineAsm.__init__c                 C   s0   | j r
dnd}d}||j|| j| jd d S )N
sideeffectr   z)asm {sideeffect} "{asm}", "{constraint}"
)r   r   r   )r   r4   r5   r   r   )r   r6   r   fmtr   r   r#   r7     s
    zInlineAsm.descrc                 C   s   g }|  | d|S )Nr   )r7   r1   rz   r   r   r#   r*     s    
zInlineAsm.get_referencec                 C   s   d | j|  S )Nrr   r   r&   r   r   r#   __str__  s    zInlineAsm.__str__N)F)r;   r=   r>   r   r7   r*   r   r   r   r   r#   r     s   
r   c                       s$   e Zd Z fddZdd Z  ZS )	AtomicRMWc                    s0   t t| j||jd||f|d || _|| _d S )NZ	atomicrmwr   )r   r   r   r2   	operationr   )r   r   r-   r   r   r   r   r!   r   r#   r     s     zAtomicRMW.__init__c                 C   sH   | j \}}d}||j| j|j| |j| | j| jddd d S )NzBatomicrmw {op} {ptrty} {ptr}, {valty} {val} {ordering} {metadata}
Tr/   )r-   ptrtyr   Zvaltyr   r   r   )r   r4   r5   r  r2   r*   r   r3   )r   r6   r   r   r   r   r   r#   r7     s    
zAtomicRMW.descrr   r   r   r!   r#   r     s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )CmpXchgzdThis instruction has changed since llvm3.5.  It is not compatible with
    older llvm versions.
    c           	         sF   t |jt dg}tt| j||d|||f|d || _|| _d S )NrP   Zcmpxchgr   )	r   ZLiteralStructTyper2   r   r   r  r   r   failordering)	r   r   r   cmpr   r   r  r   Zouttyper!   r   r#   r     s     zCmpXchg.__init__c                 C   sP   | j \}}}d}||j|j| |j| | | j| j| jddd d S )NzScmpxchg {ptrty} {ptr}, {ty} {cmp}, {ty} {val} {ordering} {failordering} {metadata}
Tr/   )r  r   rw   r  r   r   r  r   )r   r4   r5   r2   r*   r   r  r3   )r   r6   r   Zcmpvalr   r   r   r   r#   r7     s    zCmpXchg.descrr;   r=   r>   __doc__r   r7   r@   r   r   r!   r#   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )_LandingPadClausec                 C   s
   || _ d S r$   )r   r   r   r   r   r#   r   %  s    z_LandingPadClause.__init__c                 C   s   dj | j| jj| j dS )Nz{kind} {type} {value})kindr2   r   )r5   r
  r   r2   r*   r&   r   r   r#   r   (  s
    z_LandingPadClause.__str__N)r;   r=   r>   r   r   r   r   r   r#   r  $  s   r  c                   @   s   e Zd ZdZdS )CatchClauseZcatchN)r;   r=   r>   r
  r   r   r   r#   r  /  s   r  c                       s    e Zd ZdZ fddZ  ZS )FilterClausefilterc                    s4   t |tstt |jtjs ttt| | d S r$   )	r   r   r   r2   r   	ArrayTyper   r  r   r	  r!   r   r#   r   6  s    zFilterClause.__init__)r;   r=   r>   r
  r   r@   r   r   r!   r#   r  3  s   r  c                       s.   e Zd Zd	 fdd	Zdd Zdd Z  ZS )
LandingPadInstrr   Fc                    s*   t t| j||dg |d || _g | _d S )NZ
landingpadr   )r   r  r   cleanupclauses)r   r   r    r   r  r!   r   r#   r   =  s
    zLandingPadInstr.__init__c                 C   s   t |tst| j| d S r$   )r   r  r   r  r4   )r   clauser   r   r#   
add_clauseC  s    zLandingPadInstr.add_clausec              	   C   s<   d}| |j| j| jrdndddd | jD d d S )Nz$landingpad {type}{cleanup}{clauses}
z cleanupr   c                 S   s   g | ]}d  |qS )z

      {0})r5   )r,   r  r   r   r#   r.   K  s   z)LandingPadInstr.descr.<locals>.<listcomp>)r2   r  r  )r4   r5   r2   r  r1   r  )r   r6   r   r   r   r#   r7   G  s    
zLandingPadInstr.descr)r   F)r;   r=   r>   r   r  r7   r@   r   r   r!   r#   r  <  s   r  c                       s6   e Zd ZdZddddhZd fdd		Zd
d Z  ZS )Fencez|
    The `fence` instruction.

    As of LLVM 5.0.1:

    fence [syncscope("<target-scope>")] <ordering>  ; yields void
    acquirereleaseZacq_relZseq_cstNr   c                    sT   t t| j|t dd|d || jkrDd}t||d| j|| _	|| _
d S )NZfencer   r   z3Invalid fence ordering "{0}"! Should be one of {1}.r)   )r   r  r   r   r   VALID_FENCE_ORDERINGSrZ   r5   r1   r   targetscope)r   r   r   r  r   rg   r!   r   r#   r   [  s    

zFence.__init__c                 C   s:   | j d krd}nd| j }d}||j|| jd d S )Nr   zsyncscope("{0}") zfence {syncscope}{ordering}
)	syncscoper   )r  r5   r4   r   )r   r6   r  r   r   r   r#   r7   e  s    

zFence.descr)Nr   )r;   r=   r>   r  r  r   r7   r@   r   r   r!   r#   r  P  s   
r  c                       s(   e Zd ZdZ fddZdd Z  ZS )Commentz
    A line comment.
    c                    s8   t t| j|t dddd d|ks.td|| _d S )N;r   r   r   r   zComment cannot contain new line)r   r  r   r   r   r   text)r   r   r  r!   r   r#   r   v  s
    zComment.__init__c                 C   s   | d| j  d S )Nz; )r4   r  rz   r   r   r#   r7   |  s    zComment.descrr  r   r   r!   r#   r  q  s   r  N);r  Zllvmlite.irr   Zllvmlite.ir.valuesr   r   r   r   r   r   r	   r
   r   r   Zllvmlite.ir._utilsr   r   rA   rD   rT   rF   rO   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   objectr   r   r  r  r  r  r  r  r  r   r   r   r#   <module>   sX   0*p!% 		!