U
    +d;                     @   s  d dl 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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j+_ e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e
jj._#e
jege
jj/_ e
jge
jj0_ ee
jj0_#e
jege
jj1_ eege
jj2_ ee
jj2_#e
jege
jj3_ e
jge
jj4_ ee
jj4_#e
jge
jj5_ e
j6e
jj5_#e
jge
jj7_ e
j6e
jj7_#e
jge
jj8_ e
j6e
jj8_#e
jge
jj9_ e
j: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
jAe
jj@_#e
jge
jjB_ e
jCe
jjB_#e
j6ge
jjD_ e
j:ge
jjE_ e
j=ge
jjF_ e
jAge
jjG_ e
jCge
jjH_ e
j6ge
jjI_ ee
jjI_#e
j:ge
jjJ_ ee
jjJ_#e
j=ge
jjK_ e
je
jjK_#e
j?ge
jjL_ e
je
jjL_#e
jAge
jjM_ e
je
jjM_#e
jCge
jjN_ e
je
jjN_#e
jge
jjO_ ee
jjO_#dS )    )POINTERc_char_pc_intc_size_tc_uint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_weakZghostcommonZlinker_privateZlinker_private_weak r$   r$   :/tmp/pip-unpacked-wheel-stw2luzp/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   default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                   @   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%   name1   s    zTypeRef.namec                 C   s   t j| S )z=
        Returns true is the type is a pointer type.
        )r	   r,   LLVMPY_TypeIsPointerr.   r$   r$   r%   
is_pointer8   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)r2   
ValueErrorformatr*   r	   r,   LLVMPY_GetElementTyper.   r$   r$   r%   element_type?   s    zTypeRef.element_typec                 C   s   t t j| S N)r	   r+   r,   LLVMPY_PrintTyper.   r$   r$   r%   __str__I   s    zTypeRef.__str__N)	r   r   r   __doc__propertyr0   r2   r6   r9   r$   r$   r$   r%   r*   .   s   


	r*   c                   @   sh  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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d,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Zd8S )9ValueRefz&A weak reference to a LLVM value.
    c                 C   s   || _ || _tj| | d S r7   )_kind_parentsr	   	ObjectRef__init__)r/   ptrkindparentsr$   r$   r%   r@   Q   s    zValueRef.__init__c              
   C   s6   t  $}t j| | t|W  5 Q R  S Q R X d S r7   )r	   OutputStringr,   LLVMPY_PrintValueToStringstr)r/   Zoutstrr$   r$   r%   r9   V   s    
zValueRef.__str__c                 C   s   | j dS )zV
        The module this function or global variable value was obtained from.
        moduler>   getr.   r$   r$   r%   rG   [   s    zValueRef.modulec                 C   s   | j dS )zT
        The function this argument or basic block value was obtained from.
        functionrH   r.   r$   r$   r%   rJ   b   s    zValueRef.functionc                 C   s   | j dS )zE
        The block this instruction value was obtained from.
        blockrH   r.   r$   r$   r%   rK   i   s    zValueRef.blockc                 C   s   | j dS )zG
        The instruction this operand value was obtained from.
        instructionrH   r.   r$   r$   r%   rL   p   s    zValueRef.instructionc                 C   s
   | j dkS )Nglobalr=   r.   r$   r$   r%   	is_globalw   s    zValueRef.is_globalc                 C   s
   | j dkS )NrJ   rN   r.   r$   r$   r%   is_function{   s    zValueRef.is_functionc                 C   s
   | j dkS )NrK   rN   r.   r$   r$   r%   is_block   s    zValueRef.is_blockc                 C   s
   | j dkS )NargumentrN   r.   r$   r$   r%   is_argument   s    zValueRef.is_argumentc                 C   s
   | j dkS )NrL   rN   r.   r$   r$   r%   is_instruction   s    zValueRef.is_instructionc                 C   s
   | j dkS )NoperandrN   r.   r$   r$   r%   
is_operand   s    zValueRef.is_operandc                 C   s   t tj| S r7   )r
   r	   r,   LLVMPY_GetValueNamer.   r$   r$   r%   r0      s    zValueRef.namec                 C   s   t j| t| d S r7   )r	   r,   LLVMPY_SetValueNamer   )r/   valr$   r$   r%   r0      s    c                 C   s   t tj| S r7   )r   r	   r,   LLVMPY_GetLinkager.   r$   r$   r%   linkage   s    zValueRef.linkagec                 C   s$   t |tst| }tj| | d S r7   )
isinstancer   r	   r,   LLVMPY_SetLinkager/   valuer$   r$   r%   r[      s    
c                 C   s   t tj| S r7   )r&   r	   r,   LLVMPY_GetVisibilityr.   r$   r$   r%   
visibility   s    zValueRef.visibilityc                 C   s$   t |tst| }tj| | d S r7   )r\   r&   r	   r,   LLVMPY_SetVisibilityr^   r$   r$   r%   ra      s    
c                 C   s   t tj| S r7   )r)   r	   r,   LLVMPY_GetDLLStorageClassr.   r$   r$   r%   storage_class   s    zValueRef.storage_classc                 C   s$   t |tst| }tj| | d S r7   )r\   r)   r	   r,   LLVMPY_SetDLLStorageClassr^   r$   r$   r%   rd      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)rP   r3   r=   rF   r	   r,   "LLVMPY_GetEnumAttributeKindForNamer   lenr4   LLVMPY_AddFunctionAttr)r/   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_TypeOfr.   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)rO   rP   r3   r=   r	   r,   LLVMPY_IsDeclarationr.   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)iterrP   r	   r,   LLVMPY_FunctionAttributesIter_AttributeListIteratorrT   opcodeLLVMPY_CallInstAttributesIterLLVMPY_InvokeInstAttributesIterrO   LLVMPY_GlobalAttributesIter_AttributeSetIteratorrS   LLVMPY_ArgumentAttributesIter)r/   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.
        rf   rJ   )
rP   r3   r=   r	   r,   LLVMPY_FunctionBlocksIterr>   copyupdate_BlocksIteratorr/   r|   rC   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.
        rf   r~   )
rP   r3   r=   r	   r,   LLVMPY_FunctionArgumentsIterr>   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)rK   )
rQ   r3   r=   r	   r,   LLVMPY_BlockInstructionsIterr>   r   r   _InstructionsIteratorr   r$   r$   r%   instructions  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)rL   )
rT   r3   r=   r	   r,   LLVMPY_InstructionOperandsIterr>   r   r   _OperandsIteratorr   r$   r$   r%   operands  s    
zValueRef.operandsc                 C   s(   | j std| jf ttj| S )Nr   )rT   r3   r=   r	   r+   r,   LLVMPY_GetOpcodeNamer.   r$   r$   r%   ru   '  s
    zValueRef.opcodeN)r   r   r   r:   r@   r9   r;   rG   rJ   rK   rL   rO   rP   rQ   rS   rT   rV   r0   setterr[   ra   rd   rl   rn   rp   r}   r   r   r   r   ru   r$   r$   r$   r%   r<   M   sp   

























r<   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	   r?   r@   r>   rB   NotImplementedErrorrn   r   )r/   rA   rC   r$   r$   r%   r@   4  s    

z_ValueIterator.__init__c                 C   s$   |   }|rt|| j| jS td S r7   )_nextr<   rB   r>   StopIterationr/   Zvpr$   r$   r%   __next__<  s    z_ValueIterator.__next__c                 C   s   | S r7   r$   r.   r$   r$   r%   __iter__E  s    z_ValueIterator.__iter__)r   r   r   rB   r@   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 r7   )r   r   r   r$   r$   r%   r   K  s    z_AttributeIterator.__next__c                 C   s   | S r7   r$   r.   r$   r$   r%   r   T  s    z_AttributeIterator.__iter__N)r   r   r   r   r   r   r$   r$   r$   r%   r   I  s   r   c                   @   s   e Zd Zdd Zdd ZdS )rt   c                 C   s   | j |  d S r7   )_capiLLVMPY_DisposeAttributeListIterr.   r$   r$   r%   _disposeZ  s    z_AttributeListIterator._disposec                 C   s   t t j| S r7   )r	   	ret_bytesr,   LLVMPY_AttributeListIterNextr.   r$   r$   r%   r   ]  s    z_AttributeListIterator._nextNr   r   r   r   r   r$   r$   r$   r%   rt   X  s   rt   c                   @   s   e Zd Zdd Zdd ZdS )ry   c                 C   s   | j |  d S r7   )r   LLVMPY_DisposeAttributeSetIterr.   r$   r$   r%   r   c  s    z_AttributeSetIterator._disposec                 C   s   t t j| S r7   )r	   r   r,   LLVMPY_AttributeSetIterNextr.   r$   r$   r%   r   f  s    z_AttributeSetIterator._nextNr   r$   r$   r$   r%   ry   a  s   ry   c                   @   s    e Zd ZdZdd Zdd ZdS )r   rK   c                 C   s   | j |  d S r7   )r   LLVMPY_DisposeBlocksIterr.   r$   r$   r%   r   n  s    z_BlocksIterator._disposec                 C   s   t j| S r7   )r	   r,   LLVMPY_BlocksIterNextr.   r$   r$   r%   r   q  s    z_BlocksIterator._nextNr   r   r   rB   r   r   r$   r$   r$   r%   r   j  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   rR   c                 C   s   | j |  d S r7   )r   ZLLVMPY_DisposeArgumentsIterr.   r$   r$   r%   r   y  s    z_ArgumentsIterator._disposec                 C   s   t j| S r7   )r	   r,   LLVMPY_ArgumentsIterNextr.   r$   r$   r%   r   |  s    z_ArgumentsIterator._nextNr   r$   r$   r$   r%   r   u  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   rL   c                 C   s   | j |  d S r7   )r   LLVMPY_DisposeInstructionsIterr.   r$   r$   r%   r     s    z_InstructionsIterator._disposec                 C   s   t j| S r7   )r	   r,   LLVMPY_InstructionsIterNextr.   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   rU   c                 C   s   | j |  d S r7   )r   LLVMPY_DisposeOperandsIterr.   r$   r$   r%   r     s    z_OperandsIterator._disposec                 C   s   t j| S r7   )r	   r,   LLVMPY_OperandsIterNextr.   r$   r$   r%   r     s    z_OperandsIterator._nextNr   r$   r$   r$   r%   r     s   r   )Pctypesr   r   r   r   r   r   r   enumZllvmlite.bindingr	   Zllvmlite.binding.commonr
   r   IntEnumr   r&   r)   r?   r*   r<   r   r   rt   ry   r   r   r   r   ZLLVMValueRefr,   rE   argtypesZLLVMPY_GetGlobalParentZLLVMModuleRefrestyperW   rX   rm   ZLLVMTypeRefr8   r1   r5   r-   rZ   r]   r`   rb   rc   re   rg   ri   ro   rs   ZLLVMAttributeListIteratorrv   rw   rx   ZLLVMAttributeSetIteratorrz   r   ZLLVMBlocksIteratorr   ZLLVMArgumentsIteratorr   ZLLVMInstructionsIteratorr   ZLLVMOperandsIteratorr   r   r   r   r   r   r   r   r   r   r   r   r$   r$   r$   r%   <module>   s   $ c		












