o
    µôjÓ…  ã                   @   s@  d Z ddlZddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
mZmZ eeeejƒƒeeeejƒƒB eeedƒƒB Ze d¡Zdd	d
ddddœZi fdd„Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZeƒ ZG dd„ de
eeeƒZG dd„ deƒZG dd „ d e
eeƒZ G d!d"„ d"e ƒZ!G d#d$„ d$e
eeƒZ"G d%d&„ d&eƒZ#G d'd(„ d(e ƒZ$G d)d*„ d*ƒZ%G d+d,„ d,e ƒZ&G d-d.„ d.e eeƒZ'G d/d0„ d0e'ƒZ(G d1d2„ d2e)ƒZ*G d3d4„ d4e*ƒZ+G d5d6„ d6e'ƒZ,G d7d8„ d8e*ƒZ-G d9d:„ d:e ƒZ.G d;d<„ d<e.ƒZ/G d=d>„ d>e.ƒZ0G d?d@„ d@e ƒZ1G dAdB„ dBeƒZ2dS )Cz_
Classes that are LLVM values: Value, Constant...
Instructions are in the instructions module.
é    N)ÚMappingProxyType)ÚvaluesÚtypesÚ_utils)Ú_StrCachingÚ_StringReferenceCachingÚ_HasMetadataz !#$%&'()*+,-./:;<=>?@[]^_`{|}~z[-a-zA-Z$._][-a-zA-Z$._0-9]*$ÚgtÚltÚeqÚneÚgeÚle)ú>ú<ú==ú!=z>=z<=c                    st   t | tƒr	|  ¡ } t | ttfƒsJ ‚ˆ s,tdƒD ]}|tv r%t|ƒˆ |< qd| ˆ |< q‡ fdd„| D ƒ}d |¡S )z�
    Escape the given bytestring for safe use as a LLVM array constant.
    Any unicode string input is first encoded with utf8 into bytes.
    é   z\%02xc                    s   g | ]}ˆ | ‘qS © r   )Ú.0Úch©Ú_mapr   úe/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/llvmlite/ir/values.pyÚ
<listcomp>/   s    z"_escape_string.<locals>.<listcomp>Ú )	Ú
isinstanceÚstrÚencodeÚbytesÚ	bytearrayÚrangeÚ_VALID_CHARSÚchrÚjoin)Útextr   r   Úbufr   r   r   Ú_escape_string   s   

r'   c                    ó   ‡ fdd„}|S )Nc                    s   t  | ¡‡ fdd„ƒ}|S )Nc                    sJ   | j |j krtd| j |j f ƒ‚d ˆ | j |  ¡ |j | ¡ ¡}t| j |ƒS )Nú,Operands must be the same type, got (%s, %s)z{0} ({1} {2}, {3} {4}))ÚtypeÚ
ValueErrorÚformatÚget_referenceÚFormattedConstant)ÚlhsÚrhsÚfmt©Úopnamer   r   Úwrapped5   s   
ÿ

þz%_binop.<locals>.wrap.<locals>.wrapped©Ú	functoolsÚwraps©Úfnr4   r2   r   r   Úwrap4   s   
z_binop.<locals>.wrapr   ©r3   r:   r   r2   r   Ú_binop3   s   r<   c                    r(   )Nc                    s   t  ˆ ¡‡ ‡fdd„ƒ}|S )Nc                    s8   ˆ | |ƒ || j kr| S d ˆ| j |  ¡ |¡}t||ƒS )Nz{0} ({1} {2} to {3}))r*   r,   r-   r.   )ÚselfÚtypÚop)r9   r3   r   r   r4   F   s   


ÿ
z&_castop.<locals>.wrap.<locals>.wrappedr5   r8   r2   )r9   r   r:   E   s   	z_castop.<locals>.wrapr   r;   r   r2   r   Ú_castopD   s   r@   c                   @   s8  e Zd ZdZedƒdd„ ƒZedƒdd„ ƒZedƒd	d
„ ƒZedƒdd„ ƒZedƒdd„ ƒZ	edƒdd„ ƒZ
edƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZed ƒd!d"„ ƒZed#ƒd$d%„ ƒZed&ƒd'd(„ ƒZed)ƒd*d+„ ƒZed,ƒd-d.„ ƒZed/ƒd0d1„ ƒZed2ƒd3d4„ ƒZed5ƒd6d7„ ƒZd8d9„ Zd:d;„ Zd<d=„ Zd>d?„ Zd@dA„ ZdBdC„ ZdDdE„ ZdFdG„ ZedHƒdIdJ„ ƒZ edKƒdLdM„ ƒZ!edNƒdOdP„ ƒZ"edQƒdRdS„ ƒZ#edTƒdUdV„ ƒZ$edWƒdXdY„ ƒZ%edZƒd[d\„ ƒZ&ed]ƒd^d_„ ƒZ'ed`ƒdadb„ ƒZ(edcƒddde„ ƒZ)edfƒdgdh„ ƒZ*ediƒdjdk„ ƒZ+dldm„ Z,dnS )oÚ_ConstOpMixinzQ
    A mixin defining constant operations, for use in constant-like classes.
    Úshlc                 C   ó   dS )z<
        Left integer shift:
            lhs << rhs
        Nr   ©r=   Úotherr   r   r   rB   ]   ó    z_ConstOpMixin.shlÚlshrc                 C   rC   )zP
        Logical (unsigned) right integer shift:
            lhs >> rhs
        Nr   rD   r   r   r   rG   d   rF   z_ConstOpMixin.lshrÚashrc                 C   rC   )zQ
        Arithmetic (signed) right integer shift:
            lhs >> rhs
        Nr   rD   r   r   r   rH   k   rF   z_ConstOpMixin.ashrÚaddc                 C   rC   )z9
        Integer addition:
            lhs + rhs
        Nr   rD   r   r   r   rI   r   rF   z_ConstOpMixin.addÚfaddc                 C   rC   )z@
        Floating-point addition:
            lhs + rhs
        Nr   rD   r   r   r   rJ   y   rF   z_ConstOpMixin.faddÚsubc                 C   rC   )z<
        Integer subtraction:
            lhs - rhs
        Nr   rD   r   r   r   rK   €   rF   z_ConstOpMixin.subÚfsubc                 C   rC   )zC
        Floating-point subtraction:
            lhs - rhs
        Nr   rD   r   r   r   rL   ‡   rF   z_ConstOpMixin.fsubÚmulc                 C   rC   )z?
        Integer multiplication:
            lhs * rhs
        Nr   rD   r   r   r   rM   Ž   rF   z_ConstOpMixin.mulÚfmulc                 C   rC   )zF
        Floating-point multiplication:
            lhs * rhs
        Nr   rD   r   r   r   rN   •   rF   z_ConstOpMixin.fmulÚudivc                 C   rC   )zB
        Unsigned integer division:
            lhs / rhs
        Nr   rD   r   r   r   rO   œ   rF   z_ConstOpMixin.udivÚsdivc                 C   rC   )z@
        Signed integer division:
            lhs / rhs
        Nr   rD   r   r   r   rP   £   rF   z_ConstOpMixin.sdivÚfdivc                 C   rC   )z@
        Floating-point division:
            lhs / rhs
        Nr   rD   r   r   r   rQ   ª   rF   z_ConstOpMixin.fdivÚuremc                 C   rC   )zC
        Unsigned integer remainder:
            lhs % rhs
        Nr   rD   r   r   r   rR   ±   rF   z_ConstOpMixin.uremÚsremc                 C   rC   )zA
        Signed integer remainder:
            lhs % rhs
        Nr   rD   r   r   r   rS   ¸   rF   z_ConstOpMixin.sremÚfremc                 C   rC   )zA
        Floating-point remainder:
            lhs % rhs
        Nr   rD   r   r   r   rT   ¿   rF   z_ConstOpMixin.fremÚorc                 C   rC   )z;
        Bitwise integer OR:
            lhs | rhs
        Nr   rD   r   r   r   Úor_Æ   rF   z_ConstOpMixin.or_Úandc                 C   rC   )z<
        Bitwise integer AND:
            lhs & rhs
        Nr   rD   r   r   r   Úand_Í   rF   z_ConstOpMixin.and_Úxorc                 C   rC   )z<
        Bitwise integer XOR:
            lhs ^ rhs
        Nr   rD   r   r   r   rY   Ô   rF   z_ConstOpMixin.xorc              	   C   sœ   |d }zt | }W n ty   td||f ƒ‚w |dkr"|dv s&|| }| j|jkr6td| j|jf ƒ‚d ||| j|  ¡ |j| ¡ ¡}tt d¡|ƒS )NÚcmpzinvalid comparison %r for %sÚi)r   r   r)   z{0} {1} ({2} {3}, {4} {5})é   )	Ú_CMP_MAPÚKeyErrorr+   r*   r,   r-   r.   r   ÚIntType)r=   ÚprefixÚsignÚcmpoprE   Úinsr?   r1   r   r   r   Ú_cmpÛ   s$   ÿ
ÿ

ýz_ConstOpMixin._cmpc                 C   ó   |   dd||¡S )z…
        Signed integer comparison:
            lhs <cmpop> rhs

        where cmpop can be '==', '!=', '<', '<=', '>', '>='
        r[   Ús©rd   ©r=   rb   rE   r   r   r   Úicmp_signedð   ó   z_ConstOpMixin.icmp_signedc                 C   re   )z”
        Unsigned integer (or pointer) comparison:
            lhs <cmpop> rhs

        where cmpop can be '==', '!=', '<', '<=', '>', '>='
        r[   Úurg   rh   r   r   r   Úicmp_unsignedù   rj   z_ConstOpMixin.icmp_unsignedc                 C   re   )z›
        Floating-point ordered comparison:
            lhs <cmpop> rhs

        where cmpop can be '==', '!=', '<', '<=', '>', '>=', 'ord', 'uno'
        ÚfÚorg   rh   r   r   r   Úfcmp_ordered  rj   z_ConstOpMixin.fcmp_orderedc                 C   re   )z�
        Floating-point unordered comparison:
            lhs <cmpop> rhs

        where cmpop can be '==', '!=', '<', '<=', '>', '>=', 'ord', 'uno'
        rm   rk   rg   rh   r   r   r   Úfcmp_unordered  rj   z_ConstOpMixin.fcmp_unorderedc                 C   s>   t | jtjƒrt | jd| jj ¡}nt | jd¡}|  |¡S )z@
        Bitwise integer complement:
            ~value
        )éÿÿÿÿrq   )r   r*   r   Ú
VectorTyper   ÚConstantÚcountrY   )r=   r0   r   r   r   Únot_  s   
z_ConstOpMixin.not_c                 C   s   t  | jd¡}| | ¡S )z6
        Integer negative:
            -value
        r   )r   rs   r*   rK   )r=   Úzeror   r   r   Úneg$  s   
z_ConstOpMixin.negc                 C   s   d  | j|  ¡ ¡}t| j|ƒS )z=
        Floating-point negative:
            -value
        zfneg ({0} {1}))r,   r*   r-   r.   )r=   r1   r   r   r   Úfneg,  s   z_ConstOpMixin.fnegÚtruncc                 C   rC   )z@
        Truncating integer downcast to a smaller type.
        Nr   ©r=   r>   r   r   r   ry   8  rF   z_ConstOpMixin.truncÚzextc                 C   rC   )z@
        Zero-extending integer upcast to a larger type
        Nr   rz   r   r   r   r{   >  rF   z_ConstOpMixin.zextÚsextc                 C   rC   )zA
        Sign-extending integer upcast to a larger type.
        Nr   rz   r   r   r   r|   D  rF   z_ConstOpMixin.sextÚfptruncc                 C   rC   )zA
        Floating-point downcast to a less precise type.
        Nr   rz   r   r   r   r}   J  rF   z_ConstOpMixin.fptruncÚfpextc                 C   rC   )z?
        Floating-point upcast to a more precise type.
        Nr   rz   r   r   r   r~   P  rF   z_ConstOpMixin.fpextÚbitcastc                 C   rC   )z;
        Pointer cast to a different pointer type.
        Nr   rz   r   r   r   r   V  rF   z_ConstOpMixin.bitcastÚfptouic                 C   rC   )z=
        Convert floating-point to unsigned integer.
        Nr   rz   r   r   r   r€   \  rF   z_ConstOpMixin.fptouiÚuitofpc                 C   rC   )z=
        Convert unsigned integer to floating-point.
        Nr   rz   r   r   r   r�   b  rF   z_ConstOpMixin.uitofpÚfptosic                 C   rC   )z;
        Convert floating-point to signed integer.
        Nr   rz   r   r   r   r‚   h  rF   z_ConstOpMixin.fptosiÚsitofpc                 C   rC   )z;
        Convert signed integer to floating-point.
        Nr   rz   r   r   r   rƒ   n  rF   z_ConstOpMixin.sitofpÚptrtointc                 C   ó@   t | jtjƒsd}t|| jf ƒ‚t |tjƒstd|f ƒ‚dS )z*
        Cast pointer to integer.
        z2can only call ptrtoint() on pointer type, not '%s'z-can only ptrtoint() to integer type, not '%s'N)r   r*   r   ÚPointerTypeÚ	TypeErrorr_   ©r=   r>   Úmsgr   r   r   r„   t  ó   ÿÿz_ConstOpMixin.ptrtointÚinttoptrc                 C   r…   )z*
        Cast integer to pointer.
        z7can only call inttoptr() on integer constants, not '%s'z-can only inttoptr() to pointer type, not '%s'N)r   r*   r   r_   r‡   r†   rˆ   r   r   r   r‹   €  rŠ   z_ConstOpMixin.inttoptrc                 C   sx   t | jtjƒstd| jf ƒ‚| j}|D ]}| |¡}qdd„ |D ƒ}d | jj| j|  ¡ d 	|¡¡}t
| | j¡|ƒS )z>
        Call getelementptr on this pointer constant.
        z2can only call gep() on pointer constants, not '%s'c                 S   s   g | ]}d   |j| ¡ ¡‘qS )ú{0} {1}©r,   r*   r-   )r   Úidxr   r   r   r   ˜  s    ÿz%_ConstOpMixin.gep.<locals>.<listcomp>z!getelementptr ({0}, {1} {2}, {3})ú, )r   r*   r   r†   r‡   Úgepr,   Úpointeer-   r$   r.   Ú
as_pointerÚ	addrspace)r=   ÚindicesZouttyper[   Z
strindicesr?   r   r   r   r�   Œ  s   ÿÿ
þz_ConstOpMixin.gepN)-Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   rB   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rV   rX   rY   rd   ri   rl   ro   rp   ru   rw   rx   r@   ry   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r‹   r�   r   r   r   r   rA   T   sŽ    

















			











rA   c                   @   ó   e Zd ZdZdd„ ZdS )ÚValuez(
    The base class for all values.
    c                 C   s   d| j j| jf S )Nz<ir.%s type='%s' ...>)Ú	__class__r•   r*   ©r=   r   r   r   Ú__repr__¦  ó   zValue.__repr__N)r•   r–   r—   r˜   r�   r   r   r   r   rš   ¡  ó    rš   c                   @   r™   )Ú
_Undefinedz0
    'undef': a value for undefined values.
    c                 C   s$   zt W S  ty   t t¡ Y S w ©N)Ú	UndefinedÚ	NameErrorÚobjectÚ__new__r    )Úclsr   r   r   r¥   ®  s
   ÿz_Undefined.__new__N)r•   r–   r—   r˜   r¥   r   r   r   r   r    ª  s    r    c                   @   sn   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZeddd„ƒZ	e
dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )rs   z 
    A constant LLVM value.
    c                 C   s:   t |tjƒsJ ‚t |tjƒrJ ‚|| _| |¡}|| _d S r¡   )r   r   ÚTypeÚVoidTyper*   Úwrap_constant_valueÚconstant©r=   r>   rª   r   r   r   Ú__init__½  s
   

zConstant.__init__c                 C   ó   d  | j|  ¡ ¡S ©NrŒ   r�   rœ   r   r   r   Ú
_to_stringÄ  rž   zConstant._to_stringc                 C   sZ   | j d u r| jj}|S | j tu rd}|S t| j tƒr$d t| j ƒ¡}|S | j | j ¡}|S )NZundefzc"{0}")	rª   r*   Únullr¢   r   r    r,   r'   Úformat_constant©r=   Úvalr   r   r   Ú_get_referenceÇ  s   

÷úþzConstant._get_referencec                 C   sZ   dd„ |D ƒ}t |ƒdkrtdƒ‚|d }|D ]
}||kr!tdƒ‚q| t |t |ƒ¡|ƒS )zO
        Construct a literal array constant made of the given members.
        c                 S   ó   g | ]}|j ‘qS r   ©r*   ©r   Úelr   r   r   r   Û  ó    z*Constant.literal_array.<locals>.<listcomp>r   zneed at least one elementz$all elements must have the same type)Úlenr+   r‡   r   Ú	ArrayType)r¦   ÚelemsÚtysÚtyrE   r   r   r   Úliteral_arrayÖ  s   ÿzConstant.literal_arrayFc                 C   s    dd„ |D ƒ}| t  ||¡|ƒS )zS
        Construct a literal structure constant made of the given members.
        c                 S   rµ   r   r¶   r·   r   r   r   r   é  r¹   z+Constant.literal_struct.<locals>.<listcomp>)r   ÚLiteralStructType)r¦   r¼   Úpackedr½   r   r   r   Úliteral_structä  s   zConstant.literal_structc                 C   s   t | jtjƒstdƒ‚| jjS )Nz)Only pointer constant have address spaces)r   r*   r   r†   r‡   r“   rœ   r   r   r   r“   ì  s   zConstant.addrspacec                 C   s   t |tƒrt| ƒt|ƒkS dS ©NF)r   rs   r   rD   r   r   r   Ú__eq__ò  s   
zConstant.__eq__c                 C   ó   |   |¡ S r¡   ©rÄ   rD   r   r   r   Ú__ne__ø  ó   zConstant.__ne__c                 C   s   t t| ƒƒS r¡   )Úhashr   rœ   r   r   r   Ú__hash__û  rÈ   zConstant.__hash__c                 C   s   d| j | jf S )Nz <ir.Constant type='%s' value=%r>)r*   rª   rœ   r   r   r   r�   þ  ó   zConstant.__repr__N)F)r•   r–   r—   r˜   r¬   r¯   r´   Úclassmethodr¿   rÂ   Úpropertyr“   rÄ   rÇ   rÊ   r�   r   r   r   r   rs   ¸  s    

rs   c                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r.   zA
    A constant with an already formatted IR representation.
    c                 C   s    t |tƒsJ ‚t | ||¡ d S r¡   )r   r   rs   r¬   r«   r   r   r   r¬     s   zFormattedConstant.__init__c                 C   ó   | j S r¡   ©rª   rœ   r   r   r   r¯     ó   zFormattedConstant._to_stringc                 C   rÏ   r¡   rÐ   rœ   r   r   r   r´     rÑ   z FormattedConstant._get_referenceN)r•   r–   r—   r˜   r¬   r¯   r´   r   r   r   r   r.     s
    r.   c                   @   sf   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
ee	e
ƒZdd„ Zdd„ Zedd„ ƒZdS )Ú
NamedValuez*
    The base class for named values.
    ú%Tc                 C   s6   |d usJ ‚t |tjƒsJ ‚|| _|| _|  |¡ d S r¡   )r   r   r§   Úparentr*   Ú	_set_name)r=   rÔ   r*   Únamer   r   r   r¬     s
   zNamedValue.__init__c                 C   s>   g }t | jtjƒs| d |  ¡ ¡¡ |  |¡ d |¡ 	¡ S )Nz{0} = r   )
r   r*   r   r¨   Úappendr,   r-   Údescrr$   Úrstrip©r=   r&   r   r   r   r¯      s
   
zNamedValue._to_stringc                 C   s   t ‚r¡   )ÚNotImplementedErrorrÚ   r   r   r   rØ   '  ó   zNamedValue.descrc                 C   rÏ   r¡   )Ú_namerœ   r   r   r   Ú	_get_name*  rÑ   zNamedValue._get_namec                 C   s   | j jj|| jd�}|| _d S )N)Údeduplicate)rÔ   ÚscopeÚregisterÚdeduplicate_namerÝ   ©r=   rÖ   r   r   r   rÕ   -  s   
ÿ
zNamedValue._set_namec                 C   s8   | j }d|v sd|v r| dd¡ dd¡}d | j|¡S )Nú\ú"ú\5cú\22z{0}"{1}")rÖ   Úreplacer,   Úname_prefixrã   r   r   r   r´   4  s   zNamedValue._get_referencec                 C   ó   d| j j| j| jf S )Nz<ir.%s %r of type '%s'>©r›   r•   rÖ   r*   rœ   r   r   r   r�   ;  s   ÿzNamedValue.__repr__c                 C   s:   | j }t|tjƒr| j j}t|tjƒr|S td | j ¡ƒ‚)NzNot a function: {0})r*   r   r   r†   r‘   ÚFunctionTyper‡   r,   )r=   r¾   r   r   r   Úfunction_type?  s   zNamedValue.function_typeN)r•   r–   r—   r˜   ré   râ   r¬   r¯   rØ   rÞ   rÕ   rÍ   rÖ   r´   r�   rí   r   r   r   r   rÒ     s    
rÒ   c                       sL   e Zd ZdZ‡ fdd„Zdd„ Zdd„ ZeZdd	„ Zd
d„ Z	dd„ Z
‡  ZS )ÚMetaDataStringz[
    A metadata string, i.e. a constant string used as a value in a metadata
    node.
    c                    s$   t t| ƒj|t ¡ dd� || _d S )Nr   ©rÖ   )Úsuperrî   r¬   r   ÚMetaDataTypeÚstring)r=   rÔ   rò   ©r›   r   r   r¬   P  s
   þ
zMetaDataString.__init__c                 C   s   ||   ¡ df7 }d S )NÚ
)r-   rÚ   r   r   r   rØ   V  ó   zMetaDataString.descrc                 C   s   d  t| jƒ¡S )Nz!"{0}")r,   r'   rò   rœ   r   r   r   r´   Y  rË   zMetaDataString._get_referencec                 C   ó   t |tƒr| j|jkS dS rÃ   )r   rî   rò   rD   r   r   r   rÄ   ^  ó   
zMetaDataString.__eq__c                 C   rÅ   r¡   rÆ   rD   r   r   r   rÇ   d  rÈ   zMetaDataString.__ne__c                 C   ó
   t | jƒS r¡   )rÉ   rò   rœ   r   r   r   rÊ   g  ó   
zMetaDataString.__hash__)r•   r–   r—   r˜   r¬   rØ   r´   r¯   rÄ   rÇ   rÊ   Ú__classcell__r   r   ró   r   rî   J  s    rî   c                   @   s$   e Zd ZdZdd„ Zdd„ ZeZdS )ÚMetaDataArgumentzÊ
    An argument value to a function taking metadata arguments.
    This can wrap any other kind of LLVM value.

    Do not instantiate directly, Builder.call() will create these
    automatically.
    c                 C   s4   t |tƒsJ ‚t |jtjƒrJ ‚t ¡ | _|| _d S r¡   )r   rš   r*   r   rñ   Úwrapped_value©r=   Úvaluer   r   r   r¬   t  s   

zMetaDataArgument.__init__c                 C   s   d  | jj| j ¡ ¡S r®   )r,   rü   r*   r-   rœ   r   r   r   r´   z  s   
ÿzMetaDataArgument._get_referenceN)r•   r–   r—   r˜   r¬   r´   r¯   r   r   r   r   rû   k  s
    rû   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚNamedMetaDatazk
    A named metadata node.

    Do not instantiate directly, use Module.add_named_metadata() instead.
    c                 C   s   || _ g | _d S r¡   )rÔ   Úoperands)r=   rÔ   r   r   r   r¬   ‰  s   
zNamedMetaData.__init__c                 C   ó   | j  |¡ d S r¡   )r   r×   )r=   Zmdr   r   r   rI   �  rË   zNamedMetaData.addN)r•   r–   r—   r˜   r¬   rI   r   r   r   r   rÿ   ‚  s    rÿ   c                       óL   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
‡  ZS )ÚMDValuezš
    A metadata node's value, consisting of a sequence of elements ("operands").

    Do not instantiate directly, use Module.add_metadata() instead.
    ú!c                    s4   t t| ƒj|t ¡ |d� t|ƒ| _|j | ¡ d S ©Nrï   )	rð   r  r¬   r   rñ   Útupler   Úmetadatar×   )r=   rÔ   r   rÖ   ró   r   r   r¬   ™  s   þ
zMDValue.__init__c                 C   s†   g }| j D ]-}t|jtjƒr&t|tƒr|jd u r| d¡ q| | ¡ ¡ q| d 	|j| ¡ ¡¡ qd 
|¡}|d 	|¡df7 }d S )Nr°   rŒ   r�   z
!{{ {0} }}rô   )r   r   r*   r   rñ   rs   rª   r×   r-   r,   r$   )r=   r&   r   r?   r   r   r   rØ      s   

zMDValue.descrc                 C   ó   | j t| jƒ S r¡   ©ré   r   rÖ   rœ   r   r   r   r´   ­  rË   zMDValue._get_referencec                 C   rö   rÃ   )r   r  r   rD   r   r   r   rÄ   °  r÷   zMDValue.__eq__c                 C   rÅ   r¡   rÆ   rD   r   r   r   rÇ   ¶  rÈ   zMDValue.__ne__c                 C   rø   r¡   )rÉ   r   rœ   r   r   r   rÊ   ¹  rù   zMDValue.__hash__©r•   r–   r—   r˜   ré   r¬   rØ   r´   rÄ   rÇ   rÊ   rú   r   r   ró   r   r  ‘  s    r  c                   @   r™   )ÚDITokenz§
    A debug information enumeration value that should appear bare in
    the emitted metadata.

    Use this to wrap known constants, e.g. the DW_* enumerations.
    c                 C   s
   || _ d S r¡   )rþ   rý   r   r   r   r¬   Å  rù   zDIToken.__init__N)r•   r–   r—   r˜   r¬   r   r   r   r   r  ½  s    r  c                       r  )ÚDIValuezŒ
    A debug information descriptor, containing key-value pairs.

    Do not instantiate directly, use Module.add_debug_info() instead.
    r  c                    s@   t t| ƒj|t ¡ |d� || _|| _t|ƒ| _|j	 
| ¡ d S r  )rð   r  r¬   r   rñ   Úis_distinctÚkindr  r   r  r×   )r=   rÔ   r  r  r   rÖ   ró   r   r   r¬   Ñ  s   þ
zDIValue.__init__c                 C   sö   | j r|d7 }g }| jD ]]\}}|d u rd}nI|du rd}nB|du r%d}n;t|tƒr.|j}n2t|tƒr;d t|ƒ¡}n%t|tƒrEt|ƒ}nt|t	ƒrOt|ƒ}nt|t
ƒrY| ¡ }ntd|f ƒ‚| d	 ||¡¡ qd
 |¡}|d| jd|df7 }d S )N)z	distinct r°   TÚtrueFÚfalsez"{}"z'invalid operand type for debug info: %rz{0}: {1}r�   r  ú(z)
)r  r   r   r  rþ   r   r,   r'   Úintrs   rÒ   r-   r‡   r×   r$   r  )r=   r&   r   Úkeyrþ   Zstrvaluer   r   r   rØ   Ú  s4   







ÿ
zDIValue.descrc                 C   r  r¡   r	  rœ   r   r   r   r´   ø  rË   zDIValue._get_referencec                 C   s2   t |tƒr| j|jko| j|jko| j|jkS dS rÃ   )r   r  r  r  r   rD   r   r   r   rÄ   û  s   

ÿ
þzDIValue.__eq__c                 C   rÅ   r¡   rÆ   rD   r   r   r   rÇ     rÈ   zDIValue.__ne__c                 C   s   t | j| j| jfƒS r¡   )rÉ   r  r  r   rœ   r   r   r   rÊ     rõ   zDIValue.__hash__r
  r   r   ró   r   r  É  s    	r  c                       s(   e Zd ZdZdZdZ‡ fdd„Z‡  ZS )ÚGlobalValuez
    A global value.
    ú@Fc                    s2   t t| ƒj|i |¤Ž d| _d| _d| _i | _d S ©Nr   )rð   r  r¬   ÚlinkageÚstorage_classÚsectionr  )r=   ÚargsÚkwargsró   r   r   r¬     s
   
zGlobalValue.__init__)r•   r–   r—   r˜   ré   râ   r¬   rú   r   r   ró   r   r  
  s
    r  c                       s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚGlobalVariablez
    A global variable.
    r   c                    s`   t |tjƒsJ ‚tt| ƒj|| |¡|d� || _d | _d| _	d| _
|| _d | _| j | ¡ d S )Nrï   F)r   r   r§   rð   r  r¬   r’   Ú
value_typeÚinitializerÚunnamed_addrÚglobal_constantr“   ÚalignrÔ   Ú
add_global)r=   Úmoduler>   rÖ   r“   ró   r   r   r¬     s   ÿzGlobalVariable.__init__c                 C   sX  | j rd}nd}| js| jd u rdnd}n| j}|r!| |d ¡ | jr,| | jd ¡ | jr4| d¡ | jdkrB| d | j¡¡ | d	j|| jd
�¡ | jd uro| jj	| jkrdt
d| jj	| jf ƒ‚| d| j ¡  ¡ n|dvr| d|  t¡ ¡  ¡ | jr‹| d| jf ¡ | jd ur™| d| jf ¡ | jr¥| | jdd�¡ | d¡ d S )Nrª   ÚglobalÚexternalr   ú zunnamed_addr r   zaddrspace({0:d}) z{kind} {type})r  r*   z3got initializer of type %s for global value type %s)r%  Zextern_weakz, section "%s"z
, align %dT)Úleading_commarô   )r   r  r  r×   r  r  r“   r,   r  r*   r‡   r-   r¢   r  r!  r  Ú_stringify_metadata)r=   r&   r  r  r   r   r   rØ   *  s<   


þ
zGlobalVariable.descr)r   )r•   r–   r—   r˜   r¬   rØ   rú   r   r   ró   r   r    s    r  c                       sB   e Zd ZdZdZd‡ fdd„	Zdd„ Z‡ fdd„Zd	d
„ Z‡  Z	S )ÚAttributeSetzxA set of string attribute.
    Only accept items listed in *_known*.

    Properties:
    * Iterate in sorted order
    r   c                    s2   t ƒ  ¡  t|tƒr|g}|D ]}|  |¡ qd S r¡   )rð   r¬   r   r   rI   )r=   r  rÖ   ró   r   r   r¬   `  s   

ÿzAttributeSet.__init__c                 C   s   |S r¡   r   )r=   rÖ   r>   r   r   r   Ú_expandg  rÜ   zAttributeSet._expandc                    s*   || j vrtd || ¡ƒ‚tt| ƒ |¡S )Nzunknown attr {!r} for {})Ú_knownr+   r,   rð   r)  rI   rã   ró   r   r   rI   j  s   
zAttributeSet.addc                    s   ‡ ‡fdd„t ˆ ƒD ƒS )Nc                    s   g | ]}ˆ   |ˆ¡‘qS r   )r*  )r   r[   rz   r   r   r   p  s    z)AttributeSet._to_list.<locals>.<listcomp>)Úsortedrz   r   rz   r   Ú_to_listo  s   zAttributeSet._to_list©r   )
r•   r–   r—   r˜   r+  r¬   r*  rI   r-  rú   r   r   ró   r   r)  W  s    r)  c                       sv   e Zd Zeg d¢ƒZd‡ fdd„	Z‡ fdd„Zedd„ ƒZej	d	d„ ƒZed
d„ ƒZ
e
j	dd„ ƒZ
‡ fdd„Z‡  ZS )ÚFunctionAttributes) Z
argmemonlyÚalwaysinlineÚbuiltinZcoldZ
convergentZinaccessiblememonlyZinaccessiblemem_or_argmemonlyZ
inlinehintZ	jumptableZminsizeZnakedZ	nobuiltinZnoduplicateZnoimplicitfloatÚnoinlineZnonlazybindZ	norecurseZ	noredzoneZnoreturnZnounwindZoptnoneZoptsizeZreadnoneÚreadonlyZreturns_twiceZsanitize_addressZsanitize_memoryZsanitize_threadZsspZsspregZ	sspstrongZuwtabler   c                    s    d| _ d | _tt| ƒ |¡ d S ©Nr   )Ú_alignstackÚ_personalityrð   r/  r¬   ©r=   r  ró   r   r   r¬   ~  s   zFunctionAttributes.__init__c                    s8   |dkrd| v s|dkrd| v rt dƒ‚tƒ  |¡ d S )Nr0  r2  z$Can't have alwaysinline and noinline)r+   rð   rI   rã   ró   r   r   rI   ƒ  s   zFunctionAttributes.addc                 C   rÏ   r¡   ©r5  rœ   r   r   r   Ú
alignstackŠ  ó   zFunctionAttributes.alignstackc                 C   s   |dksJ ‚|| _ d S r4  r8  r²   r   r   r   r9  Ž  s   
c                 C   rÏ   r¡   )r6  rœ   r   r   r   Úpersonality“  r:  zFunctionAttributes.personalityc                 C   s    |d u st |tƒsJ ‚|| _d S r¡   )r   r  r6  r²   r   r   r   r;  —  ó   
c                    sL   t ƒ  |¡}| jr| d | j¡¡ | jr$| dj| jj| j ¡ d�¡ |S )Nzalignstack({0:d})zpersonality {persty} {persfn})ZperstyZpersfn)rð   r-  r9  r×   r,   r;  r*   r-   )r=   Úret_typeÚattrsró   r   r   r-  œ  s   þzFunctionAttributes._to_listr.  )r•   r–   r—   Ú	frozensetr+  r¬   rI   rÍ   r9  Úsetterr;  r-  rú   r   r   ró   r   r/  s  s    




r/  c                       s„   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZedd	„ ƒZddd„Z	ddd„Z
dd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZ‡  ZS )ÚFunctionz�Represent a LLVM Function but does uses a Module as parent.
    Global Values are stored as a set of dependencies (attribute `depends`).
    c                    s†   t |tjƒsJ ‚ttˆ ƒj|| ¡ |d� |ˆ _t 	¡ ˆ _
g ˆ _tƒ ˆ _t‡ fdd„|jD ƒƒˆ _tˆ |jƒˆ _ˆ j ˆ ¡ dˆ _d S )Nrï   c                    s   g | ]}t ˆ |ƒ‘qS r   )ÚArgument)r   Útrœ   r   r   r   ³  s    ÿz%Function.__init__.<locals>.<listcomp>r   )r   r   r§   rð   rA  r¬   r’   Úftyper   Ú	NameScoperà   Úblocksr/  Ú
attributesr  r  ÚReturnValueÚreturn_typeÚreturn_valuerÔ   r"  Úcalling_convention)r=   r#  rD  rÖ   ró   rœ   r   r¬   ¬  s   

ÿ
zFunction.__init__c                 C   rÏ   r¡   ©rÔ   rœ   r   r   r   r#  ¹  r:  zFunction.modulec                 C   s
   | j d S r4  ©rF  rœ   r   r   r   Úentry_basic_block½  ó   
zFunction.entry_basic_blockc                 C   rÏ   r¡   rM  rœ   r   r   r   Úbasic_blocksÁ  r:  zFunction.basic_blocksr   c                 C   s   t | |d�}| j |¡ |S )N©rÔ   rÖ   )ÚBlockrF  r×   )r=   rÖ   Úblkr   r   r   Úappend_basic_blockÅ  s   zFunction.append_basic_blockc                 C   s   t | |d�}| j ||¡ |S )zInsert block before
        rQ  )rR  rF  Úinsert)r=   ÚbeforerÖ   rS  r   r   r   Úinsert_basic_blockÊ  s   zFunction.insert_basic_blockc              	   C   s  | j rdnd}| j}d dd„ | jD ƒ¡}|  ¡ }| jr)dd | j | jj¡¡ nd}t	| jƒr9| jj
r6dnd}n| jj
r?d	nd}| j}| j}	d d
d„ |||	|fD ƒ¡}
|  ¡ }|r`d |¡nd}| jrkd | j¡nd}d}|j|
||||||d�}| |¡ dS )zB
        Describe the prototype ("head") of the function.
        ÚdefineZdeclarer�   c                 s   s   � | ]}t |ƒV  qd S r¡   ©r   )r   Úar   r   r   Ú	<genexpr>×  s   € z+Function.descr_prototype.<locals>.<genexpr>r&  r   z, ...z...c                 s   s   � | ]	}|rt |ƒV  qd S r¡   rY  )r   Úxr   r   r   r[  á  s   € z {}z section "{}"z:{prefix} {name}({args}{vararg}){attrs}{section}{metadata}
)r`   rÖ   r  Úvarargr>  r  r  N)rF  rJ  r$   r  r-   rG  r-  rD  rI  ÚanyÚvar_argr  rK  r(  r,   r  r×   )r=   r&   ÚstateÚretr  rÖ   r>  r]  r  Úcconvr`   r  r  Zpt_strÚ	prototyper   r   r   Údescr_prototypeÑ  s2   ÿÿÿ

þzFunction.descr_prototypec                 C   s   | j D ]}| |¡ qdS )z7
        Describe of the body of the function.
        N)rF  rØ   )r=   r&   rS  r   r   r   Ú
descr_bodyë  s   
ÿzFunction.descr_bodyc                 C   s6   |   |¡ | jr| d¡ |  |¡ | d¡ d S d S )Nz{
z}
)rd  rF  r×   re  rÚ   r   r   r   rØ   ò  s   


ýzFunction.descrc                 C   s   g }|   |¡ d |¡S r  )rØ   r$   rÚ   r   r   r   Ú__str__ù  s   

zFunction.__str__c                 C   s   t | jƒdkS r4  )rº   rF  rœ   r   r   r   Úis_declarationþ  s   zFunction.is_declaration©r   )r•   r–   r—   r˜   r¬   rÍ   r#  rN  rP  rT  rW  rd  re  rØ   rf  rg  rú   r   r   ró   r   rA  §  s"    




rA  c                       sú   e Zd Ze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“dd“ddddœ¥ƒZd%‡ fdd„	Zdd„ Zedd„ ƒZej	dd„ ƒZedd„ ƒZ
e
j	dd„ ƒZ
ed d!„ ƒZej	d"d!„ ƒZ‡ fd#d$„Z‡  ZS )&ÚArgumentAttributesÚbyrefTZbyvalzcaptures(none)FZelementtypeZimmargZinallocaZinregZnestZnoaliasZnofreeZnonnullZnoundefZpreallocatedÚreturnedZsignextZsretZ
swiftasync)Z
swifterrorZ	swiftselfZzeroextr   c                    s&   d| _ d| _d| _tt| ƒ |¡ d S r4  )Ú_alignÚ_dereferenceableÚ_dereferenceable_or_nullrð   ri  r¬   r7  ró   r   r   r¬     s   zArgumentAttributes.__init__c                 C   s&   | j  |¡}|r|› d|j› d�S |S )Nr  ú))r+  Úgetr‘   )r=   rÖ   r>   Zrequires_typer   r   r   r*  %  s   zArgumentAttributes._expandc                 C   rÏ   r¡   )rl  rœ   r   r   r   r!  ,  r:  zArgumentAttributes.alignc                 C   ó    t |tƒr	|dksJ ‚|| _d S r4  )r   r  rl  r²   r   r   r   r!  0  r<  c                 C   rÏ   r¡   )rm  rœ   r   r   r   Údereferenceable5  r:  z"ArgumentAttributes.dereferenceablec                 C   rq  r4  )r   r  rm  r²   r   r   r   rr  9  r<  c                 C   rÏ   r¡   )rn  rœ   r   r   r   Údereferenceable_or_null>  r:  z*ArgumentAttributes.dereferenceable_or_nullc                 C   rq  r4  )r   r  rn  r²   r   r   r   rs  B  r<  c                    s\   t ƒ  |¡}| jr| d | j¡¡ | jr| d | j¡¡ | jr,d}| | | j¡¡ |S )Nzalign {0:d}zdereferenceable({0:d})zdereferenceable_or_null({0:d}))rð   r-  r!  r×   r,   rr  rs  )r=   r>   r>  Zdrefró   r   r   r-  G  s   zArgumentAttributes._to_listr.  )r•   r–   r—   r   r+  r¬   r*  rÍ   r!  r@  rr  rs  r-  rú   r   r   ró   r   ri    sn    ýüûúùø	÷
öõôóòñðïîí
ê





ri  c                       s.   e Zd Zd‡ fdd„	Zdd„ Zdd„ Z‡  ZS )	Ú_BaseArgumentr   c                    s8   t |tjƒsJ ‚tt| ƒj|||d� || _tƒ | _d S r  )	r   r   r§   rð   rt  r¬   rÔ   ri  rG  )r=   rÔ   r>   rÖ   ró   r   r   r¬   T  s   z_BaseArgument.__init__c                 C   rê   )Nz<ir.%s %r of type %s>rë   rœ   r   r   r   r�   Z  s   ÿz_BaseArgument.__repr__c                 C   r  r¡   )rG  rI   )r=   Úattrr   r   r   Úadd_attribute^  rË   z_BaseArgument.add_attributerh  )r•   r–   r—   r¬   r�   rv  rú   r   r   ró   r   rt  S  s    rt  c                   @   r™   )rB  z3
    The specification of a function argument.
    c                 C   s>   | j  | j¡}|rd | jd |¡|  ¡ ¡S d | j|  ¡ ¡S )Nz{0} {1} {2}r&  rŒ   )rG  r-  r*   r,   r$   r-   ©r=   r>  r   r   r   rf  g  s   ÿzArgument.__str__N©r•   r–   r—   r˜   rf  r   r   r   r   rB  b  rŸ   rB  c                   @   r™   )rH  z9
    The specification of a function's return value.
    c                 C   s0   | j  | j¡}|rd d |¡| j¡S t| jƒS )NrŒ   r&  )rG  r-  r*   r,   r$   r   rw  r   r   r   rf  u  s   
zReturnValue.__str__Nrx  r   r   r   r   rH  p  rŸ   rH  c                       s^   e Zd ZdZd‡ fdd„	Zedd„ ƒZedd„ ƒZed	d
„ ƒZdd„ Z	dd„ Z
dd„ Z‡  ZS )rR  a   
    A LLVM IR basic block. A basic block is a sequence of
    instructions whose execution always goes from start to end.  That
    is, a control flow instruction (branch) can only appear as the
    last instruction, and incoming branches can only jump to the first
    instruction.
    r   c                    s2   t t| ƒj|t ¡ |d� |j| _g | _d | _d S r  )rð   rR  r¬   r   Ú	LabelTyperà   ÚinstructionsÚ
terminator)r=   rÔ   rÖ   ró   r   r   r¬   †  s   
zBlock.__init__c                 C   s
   | j d uS r¡   )r{  rœ   r   r   r   Úis_terminatedŒ  rO  zBlock.is_terminatedc                 C   rÏ   r¡   rL  rœ   r   r   r   Úfunction�  r:  zBlock.functionc                 C   s   | j jS r¡   )rÔ   r#  rœ   r   r   r   r#  ”  s   zBlock.modulec                 C   s,   |  d |  ¡ ¡¡ |dd„ | jD ƒ7 }d S )Nz{0}:
c                 S   s   g | ]}d   |¡‘qS )z  {0}
)r,   )r   Úinstrr   r   r   r   š  s    zBlock.descr.<locals>.<listcomp>)r×   r,   Ú_format_namerz  rÚ   r   r   r   rØ   ˜  s   zBlock.descrc                 C   sd   |j |j kr
tdƒ‚| j |¡}| j |¡ | j ||¡ | jjD ]}|jD ]}| ||¡ q&q!dS )zReplace an instructionz$new instruction has a different typeN)	r*   r‡   rz  ÚindexÚremoverU  rÔ   rP  Zreplace_usage)r=   ÚoldÚnewÚposZbbr~  r   r   r   rè   œ  s   
ÿÿzBlock.replacec                 C   s2   | j }t |¡s| dd¡ dd¡}d |¡}|S )Nrä   ræ   rå   rç   z"{0}")rÖ   Ú_SIMPLE_IDENTIFIER_REÚmatchrè   r,   rã   r   r   r   r  ¨  s
   

zBlock._format_namerh  )r•   r–   r—   r˜   r¬   rÍ   r|  r}  r#  rØ   rè   r  rú   r   r   ró   r   rR  }  s    


rR  c                   @   rÎ   )	ÚBlockAddressz'
    The address of a basic block.
    c                 C   s<   t |tƒsJ ‚t |tƒsJ ‚t d¡ ¡ | _|| _|| _d S )Né   )	r   rA  rR  r   r_   r’   r*   r}  Úbasic_block)r=   r}  r‰  r   r   r   r¬   ¸  s
   
zBlockAddress.__init__c                 C   r­   r®   r�   rœ   r   r   r   rf  ¿  rž   zBlockAddress.__str__c                 C   s   d  | j ¡ | j ¡ ¡S )Nzblockaddress({0}, {1}))r,   r}  r-   r‰  rœ   r   r   r   r-   Â  s   þzBlockAddress.get_referenceN)r•   r–   r—   r˜   r¬   rf  r-   r   r   r   r   r‡  ³  s
    r‡  )3r˜   r6   rò   Úrer   r   Úllvmlite.irr   r   Úllvmlite.ir._utilsr   r   r   r?  ÚmapÚordÚascii_lettersÚdigitsr"   Úcompiler…  r]   r'   r<   r@   r¤   rA   rš   r    r¢   rs   r.   rÒ   rî   rû   rÿ   r  r  r  r  r  Úsetr)  r/  rA  ri  rt  rB  rH  rR  r‡  r   r   r   r   Ú<module>   sb    ÿþ
ú
  O	J8!,A>4\P6