o
    C2h                     @   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   l/var/www/html/alexa/alex_system/speach-to-text/venv/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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)
convergentnoreturnnounwindreadonlyreadnonenoinlinealwaysinlineNr?   rB   rC   	frozenset_knownr   r   r   r"   rG   6       rG   )tailmusttailnotailc                   @   rF   )FastMathFlags)fastnnanninfnszarcpcontractafnreassocNrO   r   r   r   r"   rV   >   rR   rV   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 )	NrS   r   r   zInvalid argument index {}z%Type of #{0} arg mismatch: {1} != {2}   callr   )r   r   calling_conventioncconvstrTailMarkerOptionsrS   rV   fastmathrG   
attributesarg_attributesitemslen
ValueErrorr7   r   r   rangefunction_typeargsr   MetaDataTyper4   r   	TypeErrorr   r_   r   return_type)r   r   funcrn   r   rc   rS   rf   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 r{   r|   )r   	newcalleer   r   r"   r}   s      c                 C   s   | j dd  S Nr`   r|   r%   r   r   r"   rn   w   r   zCallInstr.argsc                 C   s    |j | jj krtd|| _d S )Nz"New function has incompatible type)rm   r}   rp   )r   newfuncr   r   r"   replace_callee{   s   
zCallInstr.replace_calleec                 C   s   | j S )zThe callee function)r}   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})rh   r3   _to_listr4   r7   r*   )rv   ars   r%   r   r"   	descr_arg   s   
z#CallInstr._descr.<locals>.descr_argr)   c                    s   g | ]	\}} ||qS r   r   )r,   rv   r   )r   r   r"   r.      s    z$CallInstr._descr.<locals>.<listcomp>{0} {1}r   z{0} r(   z2{tail}{op}{fastmath} {callee}({args}){attr}{meta}
Tr0   )rS   r-   r}   rf   rn   attrmeta)r3   	enumeratern   r}   rm   var_argrq   r7   r*   rc   rS   rg   r   rf   r6   r   r5   )
r   r8   add_metadatarn   fntyty
callee_reftail_markerfn_attrsfm_attrsr   )r   r   r"   _descr   s>   zCallInstr._descrc                 C   s   | j |dd d S )NTr   )r   r   r8   r   r   r"   r9         zCallInstr.descr)r   NNr   r   N)r?   rB   rC   r   rD   r}   setterrn   r   r   r   r9   rE   r   r   r    r"   r_   C   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)rS   rf   rs   rt   invoke)r   r   r   r   r   r   	normal_to	unwind_to)r   r   rr   rn   r   r   r   rc   rf   rs   rt   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&   rk   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 r{   r|   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   rz   r{   r|   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   rz   r{   r|   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   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   )r4   r   r   r   )r   r   condlhsrhsr   r   r    r   r"   r   <  s
   

zSelectInstr.__init__c                 C   rz   r{   r|   r%   r   r   r"   r   B  r'   zSelectInstr.condc                 C   rz   r   r|   r%   r   r   r"   r   F  r'   zSelectInstr.lhsc                 C   rz   )N   r|   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   )
r6   r7   r3   r   r   r4   r*   r   r   r5   r   r   r   r"   r9   N  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_OPrk   OPNAME
VALID_FLAGr   r4   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   r`   Tr0   )r   r   r-   r   r   r   r   )
r6   r7   r   r3   r   r-   r   r4   r*   r5   r   r   r   r"   r9   m  s   

zCompareInstr.descr)r?   rB   rC   r   r   r   r9   rE   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 )	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   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 )$	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>   r]   rZ   r[   rW   rY   rX   r^   r\   N)r?   rB   rC   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                       &   e Zd Zd fdd	Zdd Z  ZS )	LoadInstrr   Nc                    sZ   |d u rt |tr|j}n|jjs|jj}ntdtt| j	||d|g|d d | _
d S )NzLoad lacks type.loadr   )r   AllocaInstrallocated_typer4   	is_opaquepointeerk   r   r   r   align)r   r   ptrr   r   r    r   r"   r     s   


zLoadInstr.__init__c                 C   sN   | j \}| jd urd| j }nd}|d| j|j| || jdd d S )N
, align %dr   zload {0}, {1} {2}{3}{4}
Tr0   r   r  r6   r7   r4   r*   r5   )r   r8   r   r  r   r   r"   r9     s   


zLoadInstr.descrr   Nr   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   r8   r   r  r  r   r   r"   r9     s   



zStoreInstr.descrr   r   r   r    r"   r    r   r  c                       r   )LoadAtomicInstrr   Nc                    s`   |d u rt |tr|j}n|jjs|jj}ntdtt| j	||d|g|d || _
|| _d S )NzLoad atomic lacks type.zload atomicr   )r   r   r   r4   r   r   rk   r   r  r   orderingr  )r   r   r  r	  r  r   r   r    r   r"   r     s   


zLoadAtomicInstr.__init__c                 C   s:   | j \}|d| 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  r5   )r   r8   r   r   r   r"   r9     s   

zLoadAtomicInstr.descrr  r   r   r   r    r"   r        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
  )r   r8   r   r  r   r   r"   r9     s   


zStoreAtomicInstr.descrr   r   r   r    r"   r        r  c                       r   )r   c                    s:   |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"   r     s   
zAllocaInstr.__init__c                 C   sx   | d| 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   r   r   r4   r*   r  r   r5   )r   r8   r-   r   r   r"   r9     s   
zAllocaInstr.descrr   r   r   r    r"   r     s    r   c                       s(   e Zd Z	d fdd	Zdd Z  ZS )GEPInstrNc                    s   |d ur|j }|| _n?|j jsF|j }d }d}	|D ]}
|||
}}t|tjr+|j}	qt|tjs;t|tjr;|}n||	}|j j	| _nt
dtt| j||d|gt| |d || _|| _|| _d S )Nr   zGEP lacks type.getelementptrr   )r4   source_etyper   gepr   r   PointerType	addrspacer  r   rk   r   r  r   r   pointerindicesinbounds)r   r   r  r  r  r   r  r   lasttyplastaddrspacerv   r    r   r"   r   '  s2   


zGEPInstr.__init__c                 C   sV   dd | j D }| jrdnd}|d|| j| jj| j d|| j	dd d S )	Nc                 S   r   r   r   r,   rv   r   r   r"   r.   G  r   z"GEPInstr.descr.<locals>.<listcomp>zgetelementptr inboundsr  z{0} {1}, {2} {3}, {4} {5}
r)   Tr0   )
r  r  r6   r7   r  r  r4   r*   r3   r5   )r   r8   r  r-   r   r   r"   r9   F  s   

zGEPInstr.descrr#   r   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   U  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   Z  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_incominge  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.   j  s    z*PhiInstr.replace_usage.<locals>.<listcomp>)r  )r   r;   r<   r   r#  r"   r>   i  s   zPhiInstr.replace_usage)r   )r?   rB   rC   r   r9   r"  r>   rE   r   r   r    r"   r  T  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   rp   r   elementr   r$  r   )r   r   vectorindexr   r   r    r   r"   r   o  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   y      
z'ExtractElement.descr.<locals>.<genexpr>{opname} {operands}
r   r   r3   r   r6   r7   r   r   r8   r   r   r   r"   r9   x     
zExtractElement.descrr   r   r   r   r    r"   r$  n  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   rp   r(  r7   r   r   r4  r   )r   r   r)  r   r*  r   r   r    r   r"   r     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/  r0  r1  r2  r   r   r"   r9     r3  zInsertElement.descrr   r   r   r   r    r"   r4    s    r4  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     s    z)ShuffleVector.__init__.<locals>.<genexpr>zmask values need to be in {0}shufflevectorr   )r   r4   r   r   rp   r   r   r(  r   widthr   rl   allr7  
IndexErrorr7   r   r6  r   )r   r   vector1vector2maskr   r   r    r9  r"   r     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   )r6   r7   r3   r   r5   r   r   r   r"   r9     s   


zShuffleVector.descrr   r   r   r   r    r"   r6    s    r6  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AttributeErrorr>  rp   r   r   rB  r   	aggregater  )r   r   aggr  r   r   rv   r    r   r"   r     s   
zExtractValue.__init__c              
   C   r   )Nc                 S      g | ]}t |qS r   rd   r  r   r   r"   r.     r/   z&ExtractValue.descr.<locals>.<listcomp>zextractvalue {0} {1}, {2} {3}
r)   Tr0   )r  r6   r7   rG  r4   r*   r3   r5   r   r8   r  r   r   r"   r9     s   

zExtractValue.descrr   r   r   r   r    r"   rB    r  rB  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 )NrC  z&Can only insert %s at %r in %s: got %sinsertvaluer   )r4   rE  rF  r>  rp   r   r   rL  r   rG  r   r  )r   r   rH  elemr  r   r   rv   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   rI  r   rJ  r  r   r   r"   r.     r/   z%InsertValue.descr.<locals>.<listcomp>z&insertvalue {0} {1}, {2} {3}, {4} {5}
r)   Tr0   )	r  r6   r7   rG  r4   r*   r   r3   r5   rK  r   r   r"   r9     s   

zInsertValue.descrr   r   r   r   r    r"   rL    s    rL  c                       r   )Unreachablec                    s"   t t| j|t dddd d S )Nunreachabler   r   r   )r   rO  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"   rO    r   rO  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#   )rq   r4   rm   asm
constraintside_effect)r   ftyperS  rT  rU  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}"
)rW  rS  rT  )rU  r6   r7   rS  rT  )r   r8   rW  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*   rZ  r   r   r   r"   rR    s
    
rR  c                       r   )	AtomicRMWc                    s0   t t| j||jd||f|d || _|| _d S )N	atomicrmwr   )r   r[  r   r4   	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}
Tr0   )r-   ptrtyr  valtyr   r	  r   )r   r6   r7   r]  r4   r*   r	  r5   )r   r8   r  r   rX  r   r   r"   r9     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 )Nr`   cmpxchgr   )	r   LiteralStructTyper4   r   r   ra  r   r	  failordering)	r   r   r  cmpr   r	  rd  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   )r^  r  r   re  r   r	  rd  r   )r   r6   r7   r4   r*   r	  rd  r5   )r   r8   r  cmpvalr   rX  r   r   r"   r9   /  s   zCmpXchg.descrr?   rB   rC   __doc__r   r9   rE   r   r   r    r"   ra  #  s    ra  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   rl  r   r4   r*   r%   r   r   r"   rZ  C  s
   z_LandingPadClause.__str__N)r?   rB   rC   r   rZ  r   r   r   r"   rj  ?  s    rj  c                   @   s   e Zd ZdZdS )CatchClausecatchN)r?   rB   rC   rl  r   r   r   r"   rm  J  s    rm  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   ro  r   rk  r    r   r"   r   Q  s   zFilterClause.__init__)r?   rB   rC   rl  r   rE   r   r   r    r"   ro  N  s    ro  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   rr  r   cleanupclauses)r   r   r   r   rt  r    r   r"   r   X  s
   
zLandingPadInstr.__init__c                 C   r   r#   )r   rj  ru  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,   rv  r   r   r"   r.   f  s    z)LandingPadInstr.descr.<locals>.<listcomp>)r4   rt  ru  )r6   r7   r4   rt  r3   ru  )r   r8   rX  r   r   r"   r9   b  s   
zLandingPadInstr.descr)r   F)r?   rB   rC   r   rw  r9   rE   r   r   r    r"   rr  W  s    rr  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   rx  r   r   r   VALID_FENCE_ORDERINGSrk   r7   r3   r	  targetscope)r   r   r	  r  r   ry   r    r   r"   r   v  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	  )r  r7   r6   r	  )r   r8   r  rX  r   r   r"   r9     s   

zFence.descrrY  )r?   rB   rC   ri  r~  r   r9   rE   r   r   r    r"   rx  k  s
    
rx  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   rQ  zComment cannot contain new line)r   r  r   r   r   text)r   r   r  r    r   r"   r     s
   
zComment.__init__c                 C   s   | d| j  d S )Nz; )r6   r  r   r   r   r"   r9     s   zComment.descrrh  r   r   r    r"   r    s    r  N);ri  llvmlite.irr   llvmlite.ir.valuesr   r   r   r   r   r   r	   r
   r   r   llvmlite.ir._utilsr   r   rG   rP   re   rV   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r  r  r$  r4  r6  rB  rL  rO  objectrR  r[  ra  rj  rm  ro  rr  rx  r  r   r   r   r"   <module>   sZ    0*p!. 		!