U
    9%eI                     @   s>  d dl mZmZmZmZmZmZmZmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZmZ G dd dejZG dd dejZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dej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!ej"eegej#j$_%ej"gej#j&_%ej'ej#j&_(ej"gej#j)_%eej#j)_(ej"egej#j*_%ej"gej#j+_%ej,ej#j+_(ej,gej#j-_%eej#j-_(ej,gej#j._%e
ej#j._(ej,gej#j/_%ej,ej#j/_(ej,gej#j0_%eej#j0_(ej"gej#j1_%eej#j1_(ej"egej#j2_%ej"gej#j3_%eej#j3_(ej"egej#j4_%ej"gej#j5_%eej#j5_(ej"egej#j6_%eegej#j7_%eej#j7_(ej"egej#j8_%ej"gej#j9_%eej#j9_(ej"gej#j:_%ej;ej#j:_(ej"gej#j<_%ej;ej#j<_(ej"gej#j=_%ej;ej#j=_(ej"gej#j>_%ej?ej#j>_(ej"gej#j@_%ej?ej#j@_(ej"gej#jA_%ejBej#jA_(ej"gej#jC_%ejDej#jC_(ej"gej#jE_%ejFej#jE_(ej"gej#jG_%ejHej#jG_(ej;gej#jI_%ej?gej#jJ_%ejBgej#jK_%ejFgej#jL_%ejHgej#jM_%ej;gej#jN_%eej#jN_(ej?gej#jO_%eej#jO_(ejBgej#jP_%ej"ej#jP_(ejDgej#jQ_%ej"ej#jQ_(ejFgej#jR_%ej"ej#jR_(ejHgej#jS_%ej"ej#jS_(ej"gej#jT_%eej#jT_(ej"gej#jU_%e
ej#jU_(ej"gej#jV_%eej#jV_(ej"ee
gej#jW_%ee	ej#jW_(ej"gej#jX_%eej#jX_(ej"ee
gej#jY_%eej#jY_(dS )!    )POINTERbyrefcastc_char_pc_doublec_intc_size_tc_uintc_uint64c_boolc_void_pN)ffi)_decode_string_encode_stringc                   @   sP   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdS )Linkager                           	   
                     N)__name__
__module____qualname__ZexternalZavailable_externallyZlinkonce_anyZlinkonce_odrZlinkonce_odr_autohideZweak_anyZweak_odrZ	appendingZinternalprivate	dllimport	dllexportZexternal_weakghostcommonZlinker_privateZlinker_private_weak r)   r)   U/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/llvmlite/binding/value.pyr   	   s"   r   c                   @   s   e Zd ZdZdZdZdS )
Visibilityr   r   r   N)r!   r"   r#   defaultZhiddenZ	protectedr)   r)   r)   r*   r+      s   r+   c                   @   s   e Zd ZdZdZdZdS )StorageClassr   r   r   N)r!   r"   r#   r,   r%   r&   r)   r)   r)   r*   r-   '   s   r-   c                   @   st   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS )	ValueKindr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r                               N)r!   r"   r#   argumentZbasic_blockZ
memory_useZ
memory_defZ
memory_phifunctionZglobal_aliasZglobal_ifuncZglobal_variableZblock_addressZconstant_exprZconstant_arrayZconstant_structZconstant_vectorZundef_valueZconstant_aggregate_zeroZconstant_data_arrayZconstant_data_vectorconstant_intconstant_fpZconstant_pointer_nullZconstant_token_noneZmetadata_as_valueZ
inline_asminstructionZpoison_valuer)   r)   r)   r*   r.   /   s4   r.   c                   @   s<   e Zd ZdZedd Zedd Zedd Zdd	 Zd
S )TypeRefz$A weak reference to a LLVM type
    c                 C   s   t t j| S )z
        Get type name
        )r   
ret_stringlibLLVMPY_GetTypeNameselfr)   r)   r*   nameU   s    zTypeRef.namec                 C   s   t j| S )z=
        Returns true is the type is a pointer type.
        )r   r?   LLVMPY_TypeIsPointerrA   r)   r)   r*   
is_pointer\   s    zTypeRef.is_pointerc                 C   s$   | j std| ttj| S )zh
        Returns the pointed-to type. When the type is not a pointer,
        raises exception.
        zType {} is not a pointer)rE   
ValueErrorformatr=   r   r?   LLVMPY_GetElementTyperA   r)   r)   r*   element_typec   s    zTypeRef.element_typec                 C   s   t t j| S N)r   r>   r?   LLVMPY_PrintTyperA   r)   r)   r*   __str__m   s    zTypeRef.__str__N)	r!   r"   r#   __doc__propertyrC   rE   rI   rL   r)   r)   r)   r*   r=   R   s   


	r=   c                   @   s  e Zd ZdZdd Zdd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Ze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ed'd( Zejd)d( Zd*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Zed8d9 Zed:d; Z d@d=d>Z!d?S )AValueRefz&A weak reference to a LLVM value.
    c                 C   s   || _ || _tj| | d S rJ   )_kind_parentsr   	ObjectRef__init__)rB   ptrkindparentsr)   r)   r*   rS   u   s    zValueRef.__init__c              
   C   s6   t  $}t j| | t|W  5 Q R  S Q R X d S rJ   )r   OutputStringr?   LLVMPY_PrintValueToStringstr)rB   Zoutstrr)   r)   r*   rL   z   s    
zValueRef.__str__c                 C   s   | j dS )zV
        The module this function or global variable value was obtained from.
        modulerQ   getrA   r)   r)   r*   rZ      s    zValueRef.modulec                 C   s   | j dS )zT
        The function this argument or basic block value was obtained from.
        r9   r[   rA   r)   r)   r*   r9      s    zValueRef.functionc                 C   s   | j dS )zE
        The block this instruction value was obtained from.
        blockr[   rA   r)   r)   r*   r]      s    zValueRef.blockc                 C   s   | j dS )zG
        The instruction this operand value was obtained from.
        r<   r[   rA   r)   r)   r*   r<      s    zValueRef.instructionc                 C   s
   | j dkS )NglobalrP   rA   r)   r)   r*   	is_global   s    zValueRef.is_globalc                 C   s
   | j dkS )Nr9   r_   rA   r)   r)   r*   is_function   s    zValueRef.is_functionc                 C   s
   | j dkS )Nr]   r_   rA   r)   r)   r*   is_block   s    zValueRef.is_blockc                 C   s
   | j dkS )Nr8   r_   rA   r)   r)   r*   is_argument   s    zValueRef.is_argumentc                 C   s
   | j dkS )Nr<   r_   rA   r)   r)   r*   is_instruction   s    zValueRef.is_instructionc                 C   s
   | j dkS )Noperandr_   rA   r)   r)   r*   
is_operand   s    zValueRef.is_operandc                 C   s   t tj| S rJ   )boolr   r?   LLVMPY_IsConstantrA   r)   r)   r*   is_constant   s    zValueRef.is_constantc                 C   s   t tj| S rJ   )r.   r   r?   LLVMPY_GetValueKindrA   r)   r)   r*   
value_kind   s    zValueRef.value_kindc                 C   s   t tj| S rJ   )r   r   r?   LLVMPY_GetValueNamerA   r)   r)   r*   rC      s    zValueRef.namec                 C   s   t j| t| d S rJ   )r   r?   LLVMPY_SetValueNamer   )rB   valr)   r)   r*   rC      s    c                 C   s   t tj| S rJ   )r   r   r?   LLVMPY_GetLinkagerA   r)   r)   r*   linkage   s    zValueRef.linkagec                 C   s$   t |tst| }tj| | d S rJ   )
isinstancer   r   r?   LLVMPY_SetLinkagerB   valuer)   r)   r*   rp      s    
c                 C   s   t tj| S rJ   )r+   r   r?   LLVMPY_GetVisibilityrA   r)   r)   r*   
visibility   s    zValueRef.visibilityc                 C   s$   t |tst| }tj| | d S rJ   )rq   r+   r   r?   LLVMPY_SetVisibilityrs   r)   r)   r*   rv      s    
c                 C   s   t tj| S rJ   )r-   r   r?   LLVMPY_GetDLLStorageClassrA   r)   r)   r*   storage_class   s    zValueRef.storage_classc                 C   s$   t |tst| }tj| | d S rJ   )rq   r-   r   r?   LLVMPY_SetDLLStorageClassrs   r)   r)   r*   ry      s    
c                 C   s\   | j std| jf t|}tjt|t|}|dkrJtd	|tj
| | dS )z{Only works on function value

        Parameters
        -----------
        attr : str
            attribute name
        expected function value, got %sr   zno such attribute {!r}N)ra   rF   rP   rY   r   r?   "LLVMPY_GetEnumAttributeKindForNamer   lenrG   LLVMPY_AddFunctionAttr)rB   attrattrnameZattrvalr)   r)   r*   add_function_attribute   s     zValueRef.add_function_attributec                 C   s   t tj| S )z)
        This value's LLVM type.
        )r=   r   r?   LLVMPY_TypeOfrA   r)   r)   r*   type   s    zValueRef.typec                 C   s(   | j s| jstd| jf tj| S )zb
        Whether this value (presumably global) is defined in the current
        module.
        z)expected global or function value, got %s)r`   ra   rF   rP   r   r?   LLVMPY_IsDeclarationrA   r)   r)   r*   is_declaration   s
    zValueRef.is_declarationc                 C   s   t d}| jr$tj| }t|}n|| jrj| jdkrJtj| }t|}q| jdkrtj	| }t|}n6| j
rtj| }t|}n| jrtj| }t|}|S )z
        Return an iterator over this value's attributes.
        The iterator will yield a string for each attribute.
        r)   callZinvoke)iterra   r   r?   LLVMPY_FunctionAttributesIter_AttributeListIteratorrd   opcodeLLVMPY_CallInstAttributesIterLLVMPY_InvokeInstAttributesIterr`   LLVMPY_GlobalAttributesIter_AttributeSetIteratorrc   LLVMPY_ArgumentAttributesIter)rB   itritr)   r)   r*   
attributes  s$    





zValueRef.attributesc                 C   sB   | j std| jf tj| }| j }|j| d t	||S )z|
        Return an iterator over this function's blocks.
        The iterator will yield a ValueRef for each block.
        r{   r9   )
ra   rF   rP   r   r?   LLVMPY_FunctionBlocksIterrQ   copyupdate_BlocksIteratorrB   r   rV   r)   r)   r*   blocks  s    
zValueRef.blocksc                 C   sB   | j std| jf tj| }| j }|j| d t	||S )z
        Return an iterator over this function's arguments.
        The iterator will yield a ValueRef for each argument.
        r{   r   )
ra   rF   rP   r   r?   LLVMPY_FunctionArgumentsIterrQ   r   r   _ArgumentsIteratorr   r)   r)   r*   	arguments+  s    
zValueRef.argumentsc                 C   sB   | j std| jf tj| }| j }|j| d t	||S )z
        Return an iterator over this block's instructions.
        The iterator will yield a ValueRef for each instruction.
        zexpected block value, got %s)r]   )
rb   rF   rP   r   r?   LLVMPY_BlockInstructionsIterrQ   r   r   _InstructionsIteratorr   r)   r)   r*   instructions8  s    
zValueRef.instructionsc                 C   sB   | j std| jf tj| }| j }|j| d t	||S )z
        Return an iterator over this instruction's operands.
        The iterator will yield a ValueRef for each operand.
        "expected instruction value, got %s)r<   )
rd   rF   rP   r   r?   LLVMPY_InstructionOperandsIterrQ   r   r   _OperandsIteratorr   r)   r)   r*   operandsE  s    
zValueRef.operandsc                 C   s(   | j std| jf ttj| S )Nr   )rd   rF   rP   r   r>   r?   LLVMPY_GetOpcodeNamerA   r)   r)   r*   r   S  s
    zValueRef.opcodeFc           	      C   s   | j std| jf | jtjkrztd}tj	| }tj
| t|}tt|tt| j}tj||jrpdnd|dS | jtjkrtd}tj| t|}|jr|stdt|  |S t| S )a  
        Return the constant value, either as a literal (when supported)
        or as a string.

        Parameters
        -----------
        signed_int : bool
            if True and the constant is an integer, returns a signed version
        round_fp : bool
            if True and the constant is a floating point value, rounds the
            result upon accuracy loss (e.g., when querying an fp128 value).
            By default, raises an exception on accuracy loss
        zexpected constant value, got %sFlittlebig)signedz:Accuracy loss encountered in conversion of constant value )ri   rF   rP   rk   r.   r:   r   r   r?   LLVMPY_GetConstantIntNumWordsLLVMPY_GetConstantIntRawValuer   bytesr   r   r
   contentsint
from_bytesrt   r;   LLVMPY_GetConstantFPValuerY   )	rB   Z
signed_intZround_fpZlittle_endianwordsrT   ZasbytesZaccuracy_lossrt   r)   r)   r*   get_constant_valueZ  s8     
zValueRef.get_constant_valueN)FF)"r!   r"   r#   rM   rS   rL   rN   rZ   r9   r]   r<   r`   ra   rb   rc   rd   rf   ri   rk   rC   setterrp   rv   ry   r   r   r   r   r   r   r   r   r   r   r)   r)   r)   r*   rO   q   sz   




























rO   c                   @   s,   e Zd ZdZdd Zdd ZeZdd ZdS )_ValueIteratorNc                 C   s6   t j| | || _| jd kr2tdt| jf d S )Nz%s must specify kind attribute)r   rR   rS   rQ   rU   NotImplementedErrorr   r!   )rB   rT   rV   r)   r)   r*   rS     s    

z_ValueIterator.__init__c                 C   s$   |   }|rt|| j| jS td S rJ   )_nextrO   rU   rQ   StopIterationrB   Zvpr)   r)   r*   __next__  s    z_ValueIterator.__next__c                 C   s   | S rJ   r)   rA   r)   r)   r*   __iter__  s    z_ValueIterator.__iter__)r!   r"   r#   rU   rS   r   nextr   r)   r)   r)   r*   r     s
   r   c                   @   s    e Zd Zdd ZeZdd ZdS )_AttributeIteratorc                 C   s   |   }|r|S td S rJ   )r   r   r   r)   r)   r*   r     s    z_AttributeIterator.__next__c                 C   s   | S rJ   r)   rA   r)   r)   r*   r     s    z_AttributeIterator.__iter__N)r!   r"   r#   r   r   r   r)   r)   r)   r*   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   | j |  d S rJ   )_capiLLVMPY_DisposeAttributeListIterrA   r)   r)   r*   _dispose  s    z_AttributeListIterator._disposec                 C   s   t t j| S rJ   )r   	ret_bytesr?   LLVMPY_AttributeListIterNextrA   r)   r)   r*   r     s    z_AttributeListIterator._nextNr!   r"   r#   r   r   r)   r)   r)   r*   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   | j |  d S rJ   )r   LLVMPY_DisposeAttributeSetIterrA   r)   r)   r*   r     s    z_AttributeSetIterator._disposec                 C   s   t t j| S rJ   )r   r   r?   LLVMPY_AttributeSetIterNextrA   r)   r)   r*   r     s    z_AttributeSetIterator._nextNr   r)   r)   r)   r*   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   r]   c                 C   s   | j |  d S rJ   )r   LLVMPY_DisposeBlocksIterrA   r)   r)   r*   r     s    z_BlocksIterator._disposec                 C   s   t j| S rJ   )r   r?   LLVMPY_BlocksIterNextrA   r)   r)   r*   r     s    z_BlocksIterator._nextNr!   r"   r#   rU   r   r   r)   r)   r)   r*   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   r8   c                 C   s   | j |  d S rJ   )r   ZLLVMPY_DisposeArgumentsIterrA   r)   r)   r*   r     s    z_ArgumentsIterator._disposec                 C   s   t j| S rJ   )r   r?   LLVMPY_ArgumentsIterNextrA   r)   r)   r*   r     s    z_ArgumentsIterator._nextNr   r)   r)   r)   r*   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   r<   c                 C   s   | j |  d S rJ   )r   LLVMPY_DisposeInstructionsIterrA   r)   r)   r*   r     s    z_InstructionsIterator._disposec                 C   s   t j| S rJ   )r   r?   LLVMPY_InstructionsIterNextrA   r)   r)   r*   r     s    z_InstructionsIterator._nextNr   r)   r)   r)   r*   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   re   c                 C   s   | j |  d S rJ   )r   LLVMPY_DisposeOperandsIterrA   r)   r)   r*   r     s    z_OperandsIterator._disposec                 C   s   t j| S rJ   )r   r?   LLVMPY_OperandsIterNextrA   r)   r)   r*   r     s    z_OperandsIterator._nextNr   r)   r)   r)   r*   r     s   r   )Zctypesr   r   r   r   r   r   r   r	   r
   r   r   enumZllvmlite.bindingr   Zllvmlite.binding.commonr   r   IntEnumr   r+   r-   r.   rR   r=   rO   r   r   r   r   r   r   r   r   ZLLVMValueRefr?   rX   ZargtypesZLLVMPY_GetGlobalParentZLLVMModuleRefrestyperl   rm   r   ZLLVMTypeRefrK   rD   rH   r@   ro   rr   ru   rw   rx   rz   r|   r~   r   r   ZLLVMAttributeListIteratorr   r   r   ZLLVMAttributeSetIteratorr   r   ZLLVMBlocksIteratorr   ZLLVMArgumentsIteratorr   ZLLVMInstructionsIteratorr   ZLLVMOperandsIteratorr   r   r   r   r   r   r   r   r   r   r   r   rh   rj   r   r   r   r)   r)   r)   r*   <module>   s   4#  		


















