o
    4ήcx                     @   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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 d-d. d.eZ$G d/d0 d0eZ%G d1d2 d2eZ&G d3d4 d4eZ'G d5d6 d6eZ(G d7d8 d8eZ)G d9d: d:eZ*G d;d< d<eZ+G d=d> d>eZ,G d?d@ d@eZ-G dAdB dBeZ.G dCdD dDe/Z0G dEdF dFeZ1G dGdH dHeZ2G dIdJ dJe/Z3G dKdL dLe3Z4G dMdN dNe3Z5G dOdP dPeZ6G dQdR dReZ7dSS )Tz)
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J t|ttfsJ || _|| _t|| _	i | _
d S Nname)superr   __init__
isinstancer   tuplelistopnameoperandsflagsmetadata)selfparenttypr   r   r   r   	__class__r   ?/tmp/pip-target-vg8gfxp4/lib/python/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&         
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>"       z%Instruction.descr.<locals>.<listcomp>T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   sJ   || j v r#g }| j D ]}|||u r|n| q
t|| _ |   d S d S r#   )r   r6   r   _clear_string_cache)r   oldnew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   r4   r   r   r%   r   r   r"   __repr__0   s   zInstruction.__repr__r   r   )r?   
__module____qualname__r   propertyr$   r&   r9   r>   r@   __classcell__r   r   r    r"   r      s    	


r   c                   @      e Zd Zeg dZdS )CallInstrAttributes)noreturnnounwindreadonlyreadnonenoinlinealwaysinlineNr?   rB   rC   	frozenset_knownr   r   r   r"   rG   6       rG   c                   @   rF   )FastMathFlags)fastnnanninfnszarcpcontractafnreassocNrN   r   r   r   r"   rR   ;   rQ   rR   c                       sl   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   NFr   c
                    s4  |d u rt |tr|jn|| _|| _t|| _t|| _i | _	|	rE|	
 D ]\}
}d|
  kr5t|k s=n td|
t|| j	|
< q%t|}tt|jjD ]2}|| }|jj| }t |tjrl|j|krlt|}|j|krdd| ||j}t||||< qQtt| j||jjd|gt| |d d S )Nr   zInvalid argument index {}z%Type of #{0} arg mismatch: {1} != {2}   callr   )r   r   calling_conventioncconvtailrR   fastmathrG   
attributesarg_attributesitemslen
ValueErrorr7   r   r   rangefunction_typeargsr   MetaDataTyper4   r   	TypeErrorr   r[   r   return_type)r   r   funcri   r   r_   r`   ra   attrs	arg_attrsidxiargexpected_typemsgr    r   r"   r   A   sD   




zCallInstr.__init__c                 C   
   | j d S Nr   r   r%   r   r   r"   calleeb   r'   zCallInstr.calleec                 C   s   || j d< d S rv   rw   )r   	newcalleer   r   r"   rx   f      c                 C   s   | j dd  S Nr\   rw   r%   r   r   r"   ri   j   rz   zCallInstr.argsc                 C   s    |j | jj krtd|| _d S )Nz"New function has incompatible type)rh   rx   rk   )r   newfuncr   r   r"   replace_calleen   s   
zCallInstr.replace_calleec                 C   s   | j S )zAlias for llvmpy)rx   r%   r   r   r"   called_functions   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	r5dj	|}|
djjr>dnd	j|d	 d
d jD |d	 dd jD |r_jddnd	d d S )Nc                    s<   |  j v rd j |   d }nd}d|j|| S )Nr(   r   
{0} {1}{2})rc   r3   _to_listr7   r4   r*   )rq   arn   r%   r   r"   	descr_argy   s   
z#CallInstr._descr.<locals>.descr_argr)   c                    s   g | ]	\}} ||qS r   r   )r,   rq   r   )r   r   r"   r.      s    z$CallInstr._descr.<locals>.<listcomp>{0} {1}z2{tail}{op}{fastmath} {callee}({args}){attr}{meta}
ztail r   c                 S      g | ]}d | qS r(   r   r,   attrr   r   r"   r.      r/   c                 S   r   r   r   r   r   r   r"   r.      r/   Tr0   )r`   r-   rx   ra   ri   r   meta)r3   	enumerateri   rx   rh   var_argrl   r7   r*   r_   r6   r`   r   ra   rb   r5   )r   r8   add_metadatari   fntyty
callee_refr   )r   r   r"   _descrx   s(   zCallInstr._descrc                 C   s   | j |dd d S )NTr   )r   r   r8   r   r   r"   r9         zCallInstr.descr)r   NFr   r   N)r?   rB   rC   r   rD   rx   setterri   r}   r~   r   r9   rE   r   r   r    r"   r[   @   s    !



r[   c                       s.   e Zd Z		d fdd	Z fddZ  ZS )	InvokeInstrr   Nr   c                    sT   t |tsJ t |tsJ tt| j|||||d||	|
d	 d| _|| _|| _d S )NF)r`   ra   rn   ro   invoke)r   r   r   r   r   r   	normal_to	unwind_to)r   r   rm   ri   r   r   r   r_   ra   rn   ro   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 )NFr   z.      to label {0} unwind label {1}{metadata}
Tr0   )r   )	r   r   r   r6   r7   r   r*   r   r5   r   r    r   r"   r9      s   
zInvokeInstr.descr)r   Nr   r   Nr?   rB   rC   r   r9   rE   r   r   r    r"   r      s
    r   c                       $   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      g | ]}d  |j| qS r   r7   r4   r*   r+   r   r   r"   r.          z$Terminator.descr.<locals>.<listcomp>Tr0   r   )r   r3   r   r5   r6   r7   )r   r8   r   r   r   r   r   r"   r9      s   
zTerminator.descrr   r   r   r    r"   r          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 )Nbranch_weightsr   z(branch weight must be a positive integer    prof)	r	   r&   rf   r6   r   r   IntTyper   set_metadata)r   weightsr   wmdr   r   r"   set_weights   s   zPredictableInstr.set_weightsN)r?   rB   rC   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 u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 rv   rw   r%   r   r   r"   r      s   
zRet.return_valuec                 C   sT   | j }| jdd}|d ur|d| j|j| | d S |d| j| d S )NTr0   r2   z{0}{1}
)r   r5   r6   r7   r   r4   r*   )r   r8   r   r   r   r   r"   r9      s   
z	Ret.descrr#   )r?   rB   rC   r   rD   r   r9   rE   r   r   r    r"   r      s
    
r   c                   @      e Zd ZdS )BranchNr?   rB   rC   r   r   r   r"   r          r   c                   @   r   )ConditionalBranchNr   r   r   r   r"   r      r   r   c                       8   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   ru   rv   rw   r%   r   r   r"   address   r'   zIndirectBranch.addressc                 C      t |tsJ | j| d S r#   )r   r   r   r6   )r   blockr   r   r"   add_destination      zIndirectBranch.add_destinationc              
   C   B   dd | j D }|d| jj| j d|| jdd d S )Nc                 S   s   g | ]	}d  | qS )z	label {0}r7   r*   )r,   blkr   r   r"   r.      s    z(IndirectBranch.descr.<locals>.<listcomp>zindirectbr {0} {1}, [{2}]  {3}
r)   Tr0   )r   r6   r7   r   r4   r*   r3   r5   )r   r8   r   r   r   r"   r9      s   

zIndirectBranch.descr)	r?   rB   rC   r   rD   r   r   r9   rE   r   r   r    r"   r      s    
r   c                       r   )	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   ru   rv   rw   r%   r   r   r"   value  r'   zSwitchInstr.valuec                 C   s:   t |tsJ t |tst| jj|}| j||f d S r#   )r   r   r   r   r   r4   r   r6   )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(   Tr0   )	r   r6   r7   r   r4   r*   r   r3   r5   )r   r8   r   r   r   r"   r9     s   

zSwitchInstr.descr)	r?   rB   rC   r   rD   r   r   r9   rE   r   r   r    r"   r     s    
r   c                   @   r   )ResumeNr   r   r   r   r"   r     r   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J tt| j||j d|||g||d d S )Nselectr   r   )r4   r   r   r   )r   r   condlhsrhsr   r   r    r   r"   r   $  s
   

zSelectInstr.__init__c                 C   ru   rv   rw   r%   r   r   r"   r   *  r'   zSelectInstr.condc                 C   ru   r{   rw   r%   r   r   r"   r   .  r'   zSelectInstr.lhsc                 C   ru   )N   rw   r%   r   r   r"   r   2  r'   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(   Tr0   )
r6   r7   r3   r   r   r4   r*   r   r   r5   r   r   r   r"   r9   6  s   


zSelectInstr.descrrA   )
r?   rB   rC   r   rD   r   r   r   r9   rE   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 vrtd|| jf |D ]}|| jvr td|| jf q| j}t|jtjr7ttd|jj	}	ntd}	t
t| j||	|||g||d || _d S )Nzinvalid comparison %r for %szinvalid flag %r for %sr\   )r   r   )VALID_OPrf   OPNAME
VALID_FLAGr   r4   r   
VectorTyper   countr   r   r   r-   )
r   r   r-   r   r   r   r   flagr   r   r    r   r"   r   E  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>X  s    z%CompareInstr.descr.<locals>.<genexpr>r   r\   Tr0   )r   r   r-   r   r   r   r   )
r6   r7   r   r3   r   r-   r   r4   r*   r5   r   r   r   r"   r9   U  s   

zCompareInstr.descr)r?   rB   rC   r   r   r   r9   rE   r   r   r    r"   r   @  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 )	ICMPInstr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ulesgtsgesltsleN)r?   rB   rC   r   r   setr   r   r   r   r"   r   a  s    
r   c                   @   s|   e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!Zh d"Zd#S )$	FCMPInstrfcmpfalsez#no comparison, always returns falseoeqzordered and equalogtzordered and greater thanogez!ordered and greater than or equaloltzordered and less thanolezordered and less than or equalonezordered and not equalordzordered (no nans)ueqzunordered or equalr   zunordered or greater thanr   z"unordered or greater than or equalr   zunordered or less thanr   zunordered or less than or equalunezunordered or not equalunozunordered (either nans)truez"no comparison, always returns true>   rY   rV   rW   rS   rU   rT   rZ   rX   N)r?   rB   rC   r   r   r   r   r   r   r"   r   r  sH    	
r   c                       &   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   Tr0   )r6   r7   r   r   r4   r*   r5   r   r   r   r"   r9     s   


zCastInstr.descrr   r   r   r   r    r"   r     s    r   c                       r   )	LoadInstrr   c                    s*   t t| j||jjd|g|d d | _d S )Nloadr   )r   r   r   r4   pointeealign)r   r   ptrr   r    r   r"   r     s   
zLoadInstr.__init__c                 C   sP   | j \}| jd urd| j }nd}|d|jj|j| || jdd d S )N
, align %dr   zload {0}, {1} {2}{3}{4}
Tr0   )r   r   r6   r7   r4   r   r*   r5   )r   r8   r   r   r   r   r"   r9     s   


zLoadInstr.descrr   r   r   r   r    r"   r     s    r   c                       r   )
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 urd| j }nd}|d|j| |j| || jdd d S )Nr   r   zstore {0} {1}, {2} {3}{4}{5}
Tr0   )r   r   r6   r7   r4   r*   r5   )r   r8   r   r   r   r   r   r"   r9     s   



zStoreInstr.descrr   r   r   r    r"   r     r   r   c                       r   )LoadAtomicInstrr   c                    s0   t t| j||jjd|g|d || _|| _d S )Nzload atomicr   )r   r   r   r4   r   orderingr   )r   r   r   r   r   r   r    r   r"   r     
   
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}
Tr0   )	r   r6   r7   r4   r   r*   r   r   r5   )r   r8   r   r   r   r"   r9     s   

zLoadAtomicInstr.descrr   r   r   r   r    r"   r     s    r   c                       r   )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}
Tr0   )r   r6   r7   r4   r*   r   r   r5   )r   r8   r   r   r   r   r"   r9     s   


zStoreAtomicInstr.descrr   r   r   r    r"   r         r   c                       r   )AllocaInstrc                    s4   |r|gnd}t t| || d|| d | _d S )Nr   alloca)r   r  r   
as_pointerr   )r   r   r   r   r   r   r    r   r"   r     s
   
zAllocaInstr.__init__c                 C   sz   | d| j| jj | jr| j\}| d|j|  | jd ur-| d| j | jr;| | j	dd d S d S )Nr   z	, {0} {1}z, align {0}Tr0   )
r6   r7   r   r4   r   r   r*   r   r   r5   )r   r8   r-   r   r   r"   r9     s   
zAllocaInstr.descrr   r   r   r    r"   r    r  r  c                       r   )GEPInstrc           
         s   |j }d }d}|D ]}	|||	}}t|tjr|j}q	t|tjs,t|tjr,|}n||}tt| j	||d|gt
| |d || _|| _|| _d S )Nr   getelementptrr   )r4   gepr   r   PointerType	addrspacer  r   r  r   r   pointerindicesinbounds)
r   r   r   r  r  r   r   lasttyplastaddrspacerq   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   r   r   r   r,   rq   r   r   r"   r.     r   z"GEPInstr.descr.<locals>.<listcomp>zgetelementptr inboundsr  z{0} {1}, {2} {3}, {4} {5}
r)   Tr0   )
r  r  r6   r7   r
  r4   r   r*   r3   r5   )r   r8   r  r-   r   r   r"   r9     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(   Tr0   )r3   r  r6   r7   r   r4   r5   )r   r8   incsr   r   r"   r9   '  s   



zPhiInstr.descrc                 C   s"   t |tsJ | j||f d S r#   )r   r   r  r6   )r   r   r   r   r   r"   add_incoming2  s   zPhiInstr.add_incomingc                    s    fdd| j D | _ d S )Nc                    s$   g | ]\}}|u r n||fqS r   r   r   r<   r;   r   r"   r.   7  s    z*PhiInstr.replace_usage.<locals>.<listcomp>)r  )r   r;   r<   r   r  r"   r>   6  s   zPhiInstr.replace_usage)r   )r?   rB   rC   r   r9   r  r>   rE   r   r   r    r"   r  !  s
    r  c                       r   )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.extractelementr   )
r   r4   r   r   rk   r   elementr   r  r   )r   r   vectorindexr   r   r    r   r"   r   <  s   
zExtractElement.__init__c                 C   0   d dd | jD }|dj| j|d d S )Nr)   c                 s   "    | ]}d  |j| V  qdS r   Nr   r+   r   r   r"   r   F      
z'ExtractElement.descr.<locals>.<genexpr>{opname} {operands}
r   r   r3   r   r6   r7   r   r   r8   r   r   r   r"   r9   E     
zExtractElement.descrr   r   r   r   r    r"   r  ;  s    	r  c                       r   )InsertElementr   c                    sz   t |jtjstd|j|jjkstd|jj|jt |jtjs(td|j}tt	| j
||d|||g|d d S )Nr  z$value needs to be of type {} not {}.r  insertelementr   )r   r4   r   r   rk   r  r7   r   r   r(  r   )r   r   r  r   r  r   r   r    r   r"   r   M  s   


zInsertElement.__init__c                 C   r  )Nr)   c                 s   r   r!  r   r+   r   r   r"   r   [  r"  z&InsertElement.descr.<locals>.<genexpr>r#  r$  r%  r&  r   r   r"   r9   Z  r'  zInsertElement.descrr   r   r   r   r    r"   r(  L  s    r(  c                       r   )ShuffleVectorr   c                    s   t |jtjstd|tkr|j|jkrtdt |tr4t |jtjr4t |jjtjr4|jjj	dks8tdt|jj|jj
}t|tkrK|jj
nd|jj
  t fdd|jD set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  v V  qd S r#   )constant)r,   iiindex_ranger   r"   r   r  s    z)ShuffleVector.__init__.<locals>.<genexpr>zmask values need to be in {0}shufflevectorr   )r   r4   r   r   rk   r   r   r  r   widthr   rg   allr+  
IndexErrorr7   r   r*  r   )r   r   vector1vector2maskr   r   r    r-  r"   r   b  s4   




zShuffleVector.__init__c                 C   s0   | dddd | jD | jdd d S )Nzshufflevector {0} {1}
r)   c                 s   r   r!  r   r+   r   r   r"   r   {  s    z&ShuffleVector.descr.<locals>.<genexpr>Tr0   )r6   r7   r3   r   r5   r   r   r   r"   r9   y  s   


zShuffleVector.descrr   r   r   r   r    r"   r*  a  s    r*  c                       r   )ExtractValuer   c              	      st   |j }z|D ]}|j| }qW n ttfy#   tdt||j f w tt| j||d|g|d || _	|| _
d S )NCan't index at %r in %sextractvaluer   )r4   elementsAttributeErrorr2  rk   r   r   r6  r   	aggregater  )r   r   aggr  r   r   rq   r    r   r"   r     s   
zExtractValue.__init__c              
   C   r   )Nc                 S      g | ]}t |qS r   strr  r   r   r"   r.     r/   z&ExtractValue.descr.<locals>.<listcomp>zextractvalue {0} {1}, {2} {3}
r)   Tr0   )r  r6   r7   r;  r4   r*   r3   r5   r   r8   r  r   r   r"   r9     s   

zExtractValue.descrr   r   r   r   r    r"   r6    s    r6  c                       r   )InsertValuer   c              	      s   |j }z|D ]}|j| }qW n ttfy#   tdt||j f w |j |kr7td|t||j |j f tt| j||j d||g|d || _	|| _
|| _d S )Nr7  z&Can only insert %s at %r in %s: got %sinsertvaluer   )r4   r9  r:  r2  rk   r   r   rA  r   r;  r   r  )r   r   r<  elemr  r   r   rq   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   r=  r   r>  r  r   r   r"   r.     r/   z%InsertValue.descr.<locals>.<listcomp>z&insertvalue {0} {1}, {2} {3}, {4} {5}
r)   Tr0   )	r  r6   r7   r;  r4   r*   r   r3   r5   r@  r   r   r"   r9     s   

zInsertValue.descrr   r   r   r   r    r"   rA    s    rA  c                       r   )Unreachablec                    s"   t t| j|t dddd d S )Nunreachabler   r   r   )r   rD  r   r   r   )r   r   r    r   r"   r     s   
zUnreachable.__init__c                 C   s   || j df7 }d S )N
)r   r   r   r   r"   r9     r   zUnreachable.descrr   r   r   r    r"   rD    r   rD  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#   )rl   r4   rh   asm
constraintside_effect)r   ftyperH  rI  rJ  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}"
)rL  rH  rI  )rJ  r6   r7   rH  rI  )r   r8   rL  fmtr   r   r"   r9     s
   zInlineAsm.descrc                 C   s   g }|  | d|S Nr   )r9   r3   r   r   r   r"   r*     s   

zInlineAsm.get_referencec                 C   s   d | j|  S )Nr   r   r%   r   r   r"   __str__  r   zInlineAsm.__str__N)F)r?   rB   rC   r   r9   r*   rO  r   r   r   r"   rG    s
    
rG  c                       r   )	AtomicRMWc                    s0   t t| j||jd||f|d || _|| _d S )N	atomicrmwr   )r   rP  r   r4   	operationr   )r   r   r-   r   r   r   r   r    r   r"   r     r   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}
Tr0   )r-   ptrtyr   valtyr   r   r   )r   r6   r7   rR  r4   r*   r   r5   )r   r8   r   r   rM  r   r   r"   r9     s   
zAtomicRMW.descrr   r   r   r    r"   rP    r  rP  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 )Nr\   cmpxchgr   )	r   LiteralStructTyper4   r   r   rU  r   r   failordering)	r   r   r   cmpr   r   rX  r   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}
Tr0   )rS  r   r   rY  r   r   rX  r   )r   r6   r7   r4   r*   r   rX  r5   )r   r8   r   cmpvalr   rM  r   r   r"   r9     s   zCmpXchg.descr)r?   rB   rC   __doc__r   r9   rE   r   r   r    r"   rU    s    rU  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})kindr4   r   )r7   r_  r   r4   r*   r%   r   r   r"   rO    s
   z_LandingPadClause.__str__N)r?   rB   rC   r   rO  r   r   r   r"   r]    s    r]  c                   @   s   e Zd ZdZdS )CatchClausecatchN)r?   rB   rC   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J t |jtjsJ tt| | d S r#   )r   r   r4   r   	ArrayTyper   rb  r   r^  r    r   r"   r     s   zFilterClause.__init__)r?   rB   rC   r_  r   rE   r   r   r    r"   rb    s    rb  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 )N
landingpadr   )r   re  r   cleanupclauses)r   r   r   r   rg  r    r   r"   r   %  s
   
zLandingPadInstr.__init__c                 C   r   r#   )r   r]  rh  r6   )r   clauser   r   r"   
add_clause+  r   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})r7   )r,   ri  r   r   r"   r.   3  s    z)LandingPadInstr.descr.<locals>.<listcomp>)r4   rg  rh  )r6   r7   r4   rg  r3   rh  )r   r8   rM  r   r   r"   r9   /  s   
zLandingPadInstr.descr)r   F)r?   rB   rC   r   rj  r9   rE   r   r   r    r"   re  $  s    re  c                       s2   e Zd ZdZh d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
    >   acq_relacquirereleaseseq_cstNr   c                    sT   t t| j|t dd|d || jvr"d}t||d| j|| _	|| _
d S )Nfencer   r   z3Invalid fence ordering "{0}"! Should be one of {1}.r)   )r   rk  r   r   r   VALID_FENCE_ORDERINGSrf   r7   r3   r   targetscope)r   r   r   rr  r   rt   r    r   r"   r   C  s   


zFence.__init__c                 C   s:   | j d u rd}nd| j }d}||j|| jd d S )Nr   zsyncscope("{0}") zfence {syncscope}{ordering}
)	syncscoper   )rr  r7   r6   r   )r   r8   rs  rM  r   r   r"   r9   M  s   

zFence.descrrN  )r?   rB   rC   r\  rq  r   r9   rE   r   r   r    r"   rk  8  s
    
rk  N)8r\  llvmlite.irr   llvmlite.ir.valuesr   r   r   r   r   r   r	   r
   r   r   llvmlite.ir._utilsr   r   rG   rR   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*  r6  rA  rD  objectrG  rP  rU  r]  r`  rb  re  rk  r   r   r   r"   <module>   sV    0*[!% 		