o
    ߐi	|                     @   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g d	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 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Z0G dDdE dEe1Z2G dFdG dGeZ3G dHdI dIeZ4G dJdK dKe1Z5G dLdM dMe5Z6G dNdO dOe5Z7G dPdQ dQeZ8G dRdS dSeZ9G dTdU dUeZ:dVS )Wz)
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   g/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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&         
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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   sJ   || j v r#g }| j D ]}|||u r|n| q
t|| _ |   d S d S r#   )r   r5   r   Z_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   r3   r   r   r%   r   r   r"   __repr__0   s   zInstruction.__repr__r   r   )r=   
__module____qualname__r   propertyr$   r&   r8   r<   r>   __classcell__r   r   r    r"   r      s    	


r   c                   @      e Zd Zeg dZdS )CallInstrAttributes)ZnoreturnZnounwindreadonlyZreadnoneZnoinlineZalwaysinlineNr=   r@   rA   	frozensetZ_knownr   r   r   r"   rE   6       rE   )tailZmusttailZnotailc                   @   rD   )FastMathFlags)fastnnanninfnszarcpcontractafnreassocNrG   r   r   r   r"   rK   >   rI   rK   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   Nr   c
                    sV  |d u rt |tr|jn|| _t |tr|tv rn|rd}nd}|| _t|| _t	|| _
i | _|	rV|	 D ]\}
}d|
  krFt|k sNn td|
t|| j|
< q6t|}tt|jjD ]2}|| }|jj| }t |tjr}|j|kr}t|}|j|krdd| ||j}t||||< qbtt| j||jjd|gt| |d d S )	NrJ   r   r   zInvalid argument index {}z%Type of #{0} arg mismatch: {1} != {2}   callr   )r   r   Zcalling_conventioncconvstrTailMarkerOptionsrJ   rK   fastmathrE   
attributesarg_attributesitemslen
ValueErrorr6   r   r   rangefunction_typeargsr   ZMetaDataTyper3   r   	TypeErrorr   rT   r   return_type)r   r   funcrb   r   rW   rJ   rZ   attrs	arg_attrsidxiargexpected_typemsgr    r   r"   r   D   sH   





zCallInstr.__init__c                 C   
   | j d S Nr   r   r%   r   r   r"   calleeo   r'   zCallInstr.calleec                 C   s   || j d< d S rn   ro   )r   Z	newcalleer   r   r"   rp   s      c                 C   s   | j dd  S NrU   ro   r%   r   r   r"   rb   w   rq   zCallInstr.argsc                 C   s    |j | jj krtd|| _d S )Nz"New function has incompatible type)ra   rp   rc   )r   Znewfuncr   r   r"   replace_callee{   s   
zCallInstr.replace_calleec                 C   s   | j S )zThe callee function)rp   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	r5dj	|}d}j
r@dj
}jrOd	d	 j|j nd}jr`d	d	 j|j nd}	|d
j|j||	|||rujddndd d S )Nc                    s@   |  j v rd j |  |jd }nd}d|j|| S )Nr(   r   
{0} {1}{2})r\   r2   _to_listr3   r6   r*   )ri   arf   r%   r   r"   	descr_arg   s   
z#CallInstr._descr.<locals>.descr_argr)   c                    s   g | ]	\}} ||qS r   r   )r,   ri   rw   )rx   r   r"   r.      s    z$CallInstr._descr.<locals>.<listcomp>{0} {1}r   z{0} r(   z2{tail}{op}{fastmath} {callee}({args}){attr}{meta}
Tr0   )rJ   r-   rp   rZ   rb   attrmeta)r2   	enumeraterb   rp   ra   Zvar_argrd   r6   r*   rW   rJ   r[   rv   rZ   r5   r   r4   )
r   r7   add_metadatarb   ZfntytyZ
callee_refZtail_markerZfn_attrsZfm_attrsr   )rx   r   r"   _descr   s>   zCallInstr._descrc                 C   s   | j |dd d S )NTr}   )r   r   r7   r   r   r"   r8         zCallInstr.descr)r   NNr   r   N)r=   r@   rA   r   rB   rp   setterrb   rs   rt   r   r8   rC   r   r   r    r"   rT   C   s    +



*rT   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)rJ   rZ   rf   rg   Zinvoke)r   r   r   r   r   r   	normal_to	unwind_to)r   r   re   rb   r   r   r   rW   rZ   rf   rg   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   r5   r6   r   r*   r   r4   r   r    r   r"   r8      s   
zInvokeInstr.descr)r   Nr   r   Nr=   r@   rA   r   r8   rC   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 ry   r6   r3   r*   r+   r   r   r"   r.          z$Terminator.descr.<locals>.<listcomp>Tr0   ru   )r   r2   r   r4   r5   r6   )r   r7   r   r   r   r   r   r"   r8      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 )NZbranch_weightsr   z(branch weight must be a positive integer    Zprof)	r	   r&   r_   r5   r   r   IntTyper}   Zset_metadata)r   weightsr   wmdr   r   r"   set_weights   s   zPredictableInstr.set_weightsN)r=   r@   rA   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 rn   ro   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   r1   z{0}{1}
)r   r4   r5   r6   r   r3   r*   )r   r7   r   r   r   r   r"   r8      s   
z	Ret.descrr#   )r=   r@   rA   r   rB   r   r8   rC   r   r   r    r"   r      s
    
r   c                   @      e Zd ZdS )BranchNr=   r@   rA   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   rm   rn   ro   r%   r   r   r"   address  r'   zIndirectBranch.addressc                 C      t |tsJ | j| d S r#   )r   r   r   r5   )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}r6   r*   )r,   blkr   r   r"   r.     s    z(IndirectBranch.descr.<locals>.<listcomp>zindirectbr {0} {1}, [{2}]  {3}
r)   Tr0   )r   r5   r6   r   r3   r*   r2   r4   )r   r7   r   r   r   r"   r8     s   

zIndirectBranch.descr)	r=   r@   rA   r   rB   r   r   r8   rC   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   rm   rn   ro   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   r3   r   r5   )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   r5   r6   r   r3   r*   r   r2   r4   )r   r7   r   r   r   r"   r8   *  s   

zSwitchInstr.descr)	r=   r@   rA   r   rB   r   r   r8   rC   r   r   r    r"   r     s    
r   c                   @   r   )ResumeNr   r   r   r   r"   r   7  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   )r3   r   r   r   )r   r   condlhsrhsr   r   r    r   r"   r   <  s
   

zSelectInstr.__init__c                 C   rm   rn   ro   r%   r   r   r"   r   B  r'   zSelectInstr.condc                 C   rm   rr   ro   r%   r   r   r"   r   F  r'   zSelectInstr.lhsc                 C   rm   )N   ro   r%   r   r   r"   r   J  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   )
r5   r6   r2   r   r   r3   r*   r   r   r4   r   r   r   r"   r8   N  s   


zSelectInstr.descrr?   )
r=   r@   rA   r   rB   r   r   r   r8   rC   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 %srU   )r   r   )VALID_OPr_   OPNAME
VALID_FLAGr   r3   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   rU   Tr0   )r   r   r-   r~   r   r   r{   )
r5   r6   r   r2   r   r-   r   r3   r*   r4   r   r   r   r"   r8   m  s   

zCompareInstr.descr)r=   r@   rA   r   r   r   r8   rC   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@   rA   r   r   setr   r   r   r   r"   r   y  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 )$	FCMPInstrZfcmpfalsez#no comparison, always returns falseZoeqzordered and equalZogtzordered and greater thanZogez!ordered and greater than or equalZoltzordered and less thanZolezordered and less than or equalonezordered and not equalordzordered (no nans)Z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 equalZunezunordered or not equalZunozunordered (either nans)truez"no comparison, always returns true>   rS   rL   rM   rQ   rN   rR   rO   rP   N)r=   r@   rA   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   )r5   r6   r   r   r3   r*   r4   r   r   r   r"   r8     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   r3   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   r5   r6   r3   r   r*   r4   )r   r7   r   r   r   r   r"   r8     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   r5   r6   r3   r*   r4   )r   r7   r   r   r   r   r   r"   r8     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   r3   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   r5   r6   r3   r   r*   r   r   r4   )r   r7   r   r   r   r"   r8     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   r5   r6   r3   r*   r   r   r4   )r   r7   r   r   r   r   r"   r8     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   Z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 )Nry   z	, {0} {1}z, align {0}Tr0   )
r5   r6   r   r3   r   r   r*   r   r   r4   )r   r7   r-   r   r   r"   r8   	  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   )r3   Zgepr   r   ZPointerTypeZ	addrspacer   r   r   r   r   pointerindicesinbounds)
r   r   r   r   r   r   r   ZlasttypZlastaddrspaceri   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,   ri   r   r   r"   r.   ,  r   z"GEPInstr.descr.<locals>.<listcomp>zgetelementptr inboundsr   z{0} {1}, {2} {3}, {4} {5}
r)   Tr0   )
r   r   r5   r6   r   r3   r   r*   r2   r4   )r   r7   r   r-   r   r   r"   r8   +  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   )r2   r   r5   r6   r   r3   r4   )r   r7   Zincsr   r   r"   r8   ?  s   



zPhiInstr.descrc                 C   s"   t |tsJ | j||f d S r#   )r   r   r   r5   )r   r   r   r   r   r"   add_incomingJ  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:   r9   r   r"   r.   O  s    z*PhiInstr.replace_usage.<locals>.<listcomp>)r   )r   r9   r:   r   r   r"   r<   N  s   zPhiInstr.replace_usage)r   )r=   r@   rA   r   r8   r   r<   rC   r   r   r    r"   r   9  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.Zextractelementr   )
r   r3   r   r   rc   r   elementr   r   r   )r   r   vectorindexr   r   r    r   r"   r   T  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 ry   Nr   r+   r   r   r"   r   ^      
z'ExtractElement.descr.<locals>.<genexpr>{opname} {operands}
r   r   r2   r   r5   r6   r   r   r7   r   r   r   r"   r8   ]     
zExtractElement.descrr   r   r   r   r    r"   r   S  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   Zinsertelementr   )r   r3   r   r   rc   r   r6   r   r   r   r   )r   r   r   r   r   r   r   r    r   r"   r   e  s   


zInsertElement.__init__c                 C   r   )Nr)   c                 s   r   r   r   r+   r   r   r"   r   s  r   z&InsertElement.descr.<locals>.<genexpr>r   r   r   r   r   r   r"   r8   r  r   zInsertElement.descrr   r   r   r   r    r"   r   d  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Zindex_ranger   r"   r     s    z)ShuffleVector.__init__.<locals>.<genexpr>zmask values need to be in {0}Zshufflevectorr   )r   r3   r   r   rc   r   r   r   r   widthr   r`   allr   
IndexErrorr6   r   r   r   )r   r   Zvector1Zvector2maskr   r   r    r  r"   r   z  s2   



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   )r5   r6   r2   r   r4   r   r   r   r"   r8     s   


zShuffleVector.descrr   r   r   r   r    r"   r   y  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 %sZextractvaluer   )r3   elementsAttributeErrorr  rc   r   r   r  r   	aggregater   )r   r   aggr   r   r   ri   r    r   r"   r     s   
zExtractValue.__init__c              
   C   r   )Nc                 S      g | ]}t |qS r   rX   r   r   r   r"   r.     r/   z&ExtractValue.descr.<locals>.<listcomp>zextractvalue {0} {1}, {2} {3}
r)   Tr0   )r   r5   r6   r  r3   r*   r2   r4   r   r7   r   r   r   r"   r8     s   

zExtractValue.descrr   r   r   r   r    r"   r    s    r  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 )Nr  z&Can only insert %s at %r in %s: got %sZinsertvaluer   )r3   r	  r
  r  rc   r   r   r  r   r  r   r   )r   r   r  elemr   r   r   ri   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   r5   r6   r  r3   r*   r   r2   r4   r  r   r   r"   r8     s   

zInsertValue.descrr   r   r   r   r    r"   r    s    r  c                       r   )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   r   r   r   r"   r8     r   zUnreachable.descrr   r   r   r    r"   r    r   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#   )rd   r3   ra   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  r5   r6   r  r  )r   r7   r  fmtr   r   r"   r8     s
   zInlineAsm.descrc                 C   s   g }|  | d|S Nr   )r8   r2   r   r   r   r"   r*     s   

zInlineAsm.get_referencec                 C   s   d | j|  S )Nry   r   r%   r   r   r"   __str__  r   zInlineAsm.__str__N)F)r=   r@   rA   r   r8   r*   r  r   r   r   r"   r    s
    
r  c                       r   )	AtomicRMWc                    s0   t t| j||jd||f|d || _|| _d S )NZ	atomicrmwr   )r   r  r   r3   	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   Zvaltyr   r   r   )r   r5   r6   r  r3   r*   r   r4   )r   r7   r   r   r  r   r   r"   r8     s   
zAtomicRMW.descrr   r   r   r    r"   r    r   r  c                       (   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 )NrU   Zcmpxchgr   )	r   ZLiteralStructTyper3   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}
Tr0   )r  r   r~   r"  r   r   r!  r   )r   r5   r6   r3   r*   r   r!  r4   )r   r7   r   Zcmpvalr   r  r   r   r"   r8     s   zCmpXchg.descrr=   r@   rA   __doc__r   r8   rC   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})kindr3   r   )r6   r'  r   r3   r*   r%   r   r   r"   r  (  s
   z_LandingPadClause.__str__N)r=   r@   rA   r   r  r   r   r   r"   r%  $  s    r%  c                   @   s   e Zd ZdZdS )CatchClauseZcatchN)r=   r@   rA   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   r3   r   	ArrayTyper   r)  r   r&  r    r   r"   r   6  s   zFilterClause.__init__)r=   r@   rA   r'  r   rC   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   r   r#   )r   r%  r.  r5   )r   clauser   r   r"   
add_clauseC  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})r6   )r,   r/  r   r   r"   r.   K  s    z)LandingPadInstr.descr.<locals>.<listcomp>)r3   r-  r.  )r5   r6   r3   r-  r2   r.  )r   r7   r  r   r   r"   r8   G  s   
zLandingPadInstr.descr)r   F)r=   r@   rA   r   r0  r8   rC   r   r   r    r"   r,  <  s    r,  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
    >   releaseacquireZacq_relZseq_cstNr   c                    sT   t t| j|t dd|d || jvr"d}t||d| j|| _	|| _
d S )NZfencer   r   z3Invalid fence ordering "{0}"! Should be one of {1}.r)   )r   r1  r   r   r   VALID_FENCE_ORDERINGSr_   r6   r2   r   targetscope)r   r   r   r5  r   rl   r    r   r"   r   [  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   )r5  r6   r5   r   )r   r7   r6  r  r   r   r"   r8   e  s   

zFence.descrr  )r=   r@   rA   r$  r4  r   r8   rC   r   r   r    r"   r1  P  s
    
r1  c                       r  )Commentz
    A line comment.
    c                    s8   t t| j|t dddd d|vsJ d|| _d S )N;r   r   r   r  zComment cannot contain new line)r   r7  r   r   r   text)r   r   r9  r    r   r"   r   v  s
   
zComment.__init__c                 C   s   | d| j  d S )Nz; )r5   r9  r   r   r   r"   r8   |  s   zComment.descrr#  r   r   r    r"   r7  q  s    r7  N);r$  Zllvmlite.irr   Zllvmlite.ir.valuesr   r   r   r   r   r   r	   r
   r   r   Zllvmlite.ir._utilsr   r   rE   rH   rY   rK   rT   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,  r1  r7  r   r   r   r"   <module>   sZ    0*p!% 		!