o
    Fô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   úc/var/www/html/academy/tools/voices/clone/sv-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 )NÚ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=   Ú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coldÚ
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_threadÚsspZsspregZ	sspstrongZuwtabler   c                    s    d| _ d | _tt| ƒ |¡ d S ©Nr   )Ú_alignstackÚ_personalityrñ   r1  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 )Nr2  r5  z$Can't have alwaysinline and noinline)r+   rñ   rI   rä   rô   r   r   rI   ƒ  s   zFunctionAttributes.addc                 C   rÐ   r¡   ©r9  rœ   r   r   r   Ú
alignstackŠ  ó   zFunctionAttributes.alignstackc                 C   s   |dksJ ‚|| _ d S r8  r<  r³   r   r   r   r=  Ž  s   
c                 C   rÐ   r¡   )r:  rœ   r   r   r   Úpersonality“  r>  zFunctionAttributes.personalityc                 C   s    |d u st |tƒsJ ‚|| _d S r¡   )r   r  r:  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/  r=  rØ   r,   r?  r*   r-   )r=   Úret_typeÚattrsrô   r   r   r/  œ  s   þzFunctionAttributes._to_listr0  )r•   r–   r—   Ú	frozensetr-  r¬   rI   rÎ   r=  Úsetterr?  r/  rû   r   r   rô   r   r1  s  s    




r1  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ñ   rE  r¬   r’   Úftyper   Ú	NameScoperá   Úblocksr1  Ú
attributesr  r  ÚReturnValueÚreturn_typeÚreturn_valuerÕ   r$  Úcalling_convention)r=   r%  rH  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 r8  ©rJ  rœ   r   r   r   Úentry_basic_block½  ó   
zFunction.entry_basic_blockc                 C   rÐ   r¡   rQ  rœ   r   r   r   Úbasic_blocksÁ  r>  zFunction.basic_blocksr   c                 C   s   t | |d�}| j |¡ |S )N©rÕ   r×   )ÚBlockrJ  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
        rU  )rV  rJ  Úinsert)r=   Úbeforer×   rW  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¡   r]  )r   Úxr   r   r   r_  á  s   € z {}z section "{}"z:{prefix} {name}({args}{vararg}){attrs}{section}{metadata}
)r`   r×   r  ÚvarargrB  r  r	  N)rJ  rN  r$   r  r-   rK  r/  rH  rM  ÚanyÚvar_argr  rO  r*  r,   r  rØ   )r=   r&   ÚstateÚretr  r×   rB  ra  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)rJ  rÙ   )r=   r&   rW  r   r   r   Ú
descr_bodyë  s   
ÿzFunction.descr_bodyc                 C   s6   |   |¡ | jr| d¡ |  |¡ | d¡ d S d S )Nz{
z}
)rh  rJ  rØ   ri  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 r8  )r»   rJ  rœ   r   r   r   Úis_declarationþ  s   zFunction.is_declaration©r   )r•   r–   r—   r˜   r¬   rÎ   r%  rR  rT  rX  r[  rh  ri  rÙ   rj  rk  rû   r   r   rô   r   rE  §  s"    




rE  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inregÚnestZnoaliasZnofreeZnonnullZnoundefZpreallocatedÚreturnedZsignextZsretZ
swiftasync)Z
swifterrorZ	swiftselfZzeroextr   c                    s&   d| _ d| _d| _tt| ƒ |¡ d S r8  )Ú_alignÚ_dereferenceableÚ_dereferenceable_or_nullrñ   rm  r¬   r;  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¡   )rq  rœ   r   r   r   r#  ,  r>  zArgumentAttributes.alignc                 C   ó    t |tƒr	|dksJ ‚|| _d S r8  )r   r  rq  r³   r   r   r   r#  0  r@  c                 C   rÐ   r¡   )rr  rœ   r   r   r   Údereferenceable5  r>  z"ArgumentAttributes.dereferenceablec                 C   rv  r8  )r   r  rr  r³   r   r   r   rw  9  r@  c                 C   rÐ   r¡   )rs  rœ   r   r   r   Údereferenceable_or_null>  r>  z*ArgumentAttributes.dereferenceable_or_nullc                 C   rv  r8  )r   r  rs  r³   r   r   r   rx  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,   rw  rx  )r=   r>   rB  Zdrefrô   r   r   r/  G  s   zArgumentAttributes._to_listr0  )r•   r–   r—   r   r-  r¬   r,  rÎ   r#  rD  rw  rx  r/  rû   r   r   rô   r   rm    sn    ýüûúùø	÷
öõôóòñðïîí
ê





rm  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ñ   ry  r¬   rÕ   rm  rK  )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¡   )rK  rI   )r=   Úattrr   r   r   Úadd_attribute^  rÌ   z_BaseArgument.add_attributerl  )r•   r–   r—   r¬   r�   r{  rû   r   r   rô   r   ry  S  s    ry  c                   @   r™   )rF  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Œ   )rK  r/  r*   r,   r$   r-   ©r=   rB  r   r   r   rj  g  s   ÿzArgument.__str__N©r•   r–   r—   r˜   rj  r   r   r   r   rF  b  rŸ   rF  c                   @   r™   )rL  z9
    The specification of a function's return value.
    c                 C   s0   | j  | j¡}|rd d |¡| j¡S t| jƒS )NrŒ   r(  )rK  r/  r*   r,   r$   r   r|  r   r   r   rj  u  s   
zReturnValue.__str__Nr}  r   r   r   r   rL  p  rŸ   rL  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 )rV  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ñ   rV  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Œ  rS  zBlock.is_terminatedc                 C   rÐ   r¡   rP  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_namer  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‡   r  ÚindexÚremoverY  rÕ   rT  Zreplace_usage)r=   ÚoldÚnewÚposÚ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_namerl  )r•   r–   r—   r˜   r¬   rÎ   r�  r‚  r%  rÙ   ré   r„  rû   r   r   rô   r   rV  }  s    


rV  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   rE  rV  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   rj  ¿  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¬   rj  r-   r   r   r   r   r�  ³  s
    r�  )3r˜   r6   ró   Úrer   r   Úllvmlite.irr   r   Úllvmlite.ir._utilsr   r   r   rC  Ú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+  r1  rE  rm  ry  rF  rL  rV  r�  r   r   r   r   Ú<module>   sb    ÿþ
ú
  O	J8!,A>4\P6