o
    µôj�  ã                   @   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   úk/var/www/html/academy/tools/voices/clone/cosy-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   )ÚtailZmusttailZnotailc                   @   rF   )ÚFastMathFlags)ÚfastÚnnanÚninfÚnszÚarcpÚcontractÚafnÚreassocNrO   r   r   r   r"   rT   >   rR   rT   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r�d 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   rT   ÚfastmathrG   Ú
attributesÚarg_attributesÚitemsÚlenÚ
ValueErrorr7   r   r   ÚrangeÚfunction_typeÚargsr   ÚMetaDataTyper4   r   Ú	TypeErrorr   r]   r   Úreturn_type)r   r   Úfuncrl   r   ra   rS   rd   Ú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 ry   rz   )r   Z	newcalleer   r   r"   r{   s   ó   c                 C   s   | j dd … S ©Nr^   rz   r%   r   r   r"   rl   w   r|   zCallInstr.argsc                 C   s    |j | jj krtdƒ‚|| _d S )Nz"New function has incompatible type)rk   r{   rn   )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})rf   r3   Ú_to_listr4   r7   r*   )rt   Úarq   r%   r   r"   Ú	descr_arg†   s   
z#CallInstr._descr.<locals>.descr_argr)   c                    s   g | ]	\}}ˆ ||ƒ‘qS r   r   )r,   rt   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{   rd   rl   ÚattrÚmeta)r3   Ú	enumeraterl   r{   rk   Úvar_argro   r7   r*   ra   rS   re   r‚   rd   r6   r   r5   )
r   r8   Úadd_metadatarl   ÚfntyÚtyZ
callee_refZtail_markerZfn_attrsZ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{   Úsetterrl   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   rd   rq   rr   Úinvoke)r   r   r   r’   r   r   Ú	normal_toÚ	unwind_to)r   r   rp   rl   r”   r•   r   ra   rd   rq   rr   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 )NZbranch_weightsr   z(branch weight must be a positive integeré    Úprof)	r	   r&   ri   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 ry   rz   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   rx   ry   rz   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   rx   ry   rz   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   rx   ry   rz   r%   r   r   r"   rÆ   B  r'   zSelectInstr.condc                 C   rx   r}   rz   r%   r   r   r"   rÇ   F  r'   zSelectInstr.lhsc                 C   rx   )Né   rz   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_OPri   Ú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 )Ú	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?   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 )$Ú	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>   rX   r\   rV   rW   r[   rY   rU   rZ   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Úpointeeri   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ê   ri   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ê   ri   r   rú   r   r   ÚpointerÚindicesÚinbounds)r   r   rì   r  r  r   rü   r   ZlasttypZlastaddrspacert   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,   rt   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   Z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.Zextractelementr   )
r   r4   r   rÎ   rn   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  Zinsertelementr   )r   r4   r   rÎ   rn   r  r7   r¢   r   r  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  r  r  r  r   r   r"   r9   �  r  zInsertElement.descrrã   r–   r   r   r    r"   r    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   r4   r   rÎ   rn   r   r   r  r¢   ÚwidthrÏ   rj   Úallr  Ú
IndexErrorr7   r   r  r   )r   r   Úvector1Úvector2Úmaskr   r   r    r  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"   r  ”  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   )r4   ÚelementsÚAttributeErrorr!  rn   r   r   r%  r   Ú	aggregater  )r   r   Úaggr  r   r   rt   r    r   r"   r   µ  s   ÿÿÿÿ
zExtractValue.__init__c              
   C   r¸   )Nc                 S   ó   g | ]}t |ƒ‘qS r   ©rb   r  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"   r%  ´  rõ   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   )r4   r'  r(  r!  rn   r   r   r.  r   r)  r¿   r  )r   r   r*  Úelemr  r   r   rt   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"   r.  Ï  s    r.  c                       r—   )ÚUnreachablec                    s"   t t| ƒj|t ¡ dddd� d S )NÚunreachabler   r   r   )r   r0  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"   r0  í  rž   r0  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#   )ro   r4   rk   ÚasmÚ
constraintÚside_effect)r   Úftyper4  r5  r6  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}")r8  r4  r5  )r6  r6   r7   r4  r5  )r   r8   r8  Ú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*   r;  r   r   r   r"   r3  ö  s
    
r3  c                       r—   )Ú	AtomicRMWc                    s0   t t| ƒj||jd||f|d� || _|| _d S )NZ	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ì   Zvaltyr¾   ró   r   )r   r6   r7   r=  r4   r*   ró   r5   )r   r8   rì   r¾   r9  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   r@  r   ró   Úfailordering)	r   r   rì   Úcmpr¾   ró   rC  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Œ   rD  r¾   ró   rC  r   )r   r6   r7   r4   r*   ró   rC  r5   )r   r8   rì   Zcmpvalr¾   r9  r   r   r"   r9   /  s   ÿùzCmpXchg.descr©r?   rB   rC   Ú__doc__r   r9   rE   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})Úkindr4   r¿   )r7   rJ  r¿   r4   r*   r%   r   r   r"   r;  C  s
   ýz_LandingPadClause.__str__N)r?   rB   rC   r   r;  r   r   r   r"   rH  ?  s    rH  c                   @   s   e Zd ZdZdS )ÚCatchClauseZcatchN)r?   rB   rC   rJ  r   r   r   r"   rK  J  s    rK  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   rL  r   rI  r    r   r"   r   Q  s   zFilterClause.__init__)r?   rB   rC   rJ  r   rE   r   r   r    r"   rL  N  s    rL  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   rO  r   ÚcleanupÚclauses)r   r   r   r   rQ  r    r   r"   r   X  s
   ÿ
zLandingPadInstr.__init__c                 C   r´   r#   )r   rH  rR  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,   rS  r   r   r"   r.   f  s    ÿz)LandingPadInstr.descr.<locals>.<listcomp>)r4   rQ  rR  )r6   r7   r4   rQ  r3   rR  )r   r8   r9  r   r   r"   r9   b  s   
ÿþzLandingPadInstr.descr)r   F)r?   rB   rC   r   rT  r9   rE   r   r   r    r"   rO  W  s    rO  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
    >   Zseq_cstZacq_relÚreleaseÚacquireNr   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   rU  r   r   r™   ÚVALID_FENCE_ORDERINGSri   r7   r3   ró   Útargetscope)r   r   ró   rZ  r   rw   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ó   )rZ  r7   r6   ró   )r   r8   r[  r9  r   r   r"   r9   €  s   

ÿzFence.descrr:  )r?   rB   rC   rG  rY  r   r9   rE   r   r   r    r"   rU  k  s
    
rU  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   r2  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.descrrF  r   r   r    r"   r\  Œ  s    r\  N);rG  Úllvmlite.irr   Zllvmlite.ir.valuesr   r   r   r   r   r   r	   r
   r   r   Úllvmlite.ir._utilsr   r   rG   rP   rc   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.  r0  Úobjectr3  r<  r@  rH  rK  rL  rO  rU  r\  r   r   r   r"   Ú<module>   sZ    0*p!. 		!