o
    4ήc;                     @   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__externalavailable_externallylinkonce_anylinkonce_odrlinkonce_odr_autohideweak_anyweak_odr	appendinginternalprivate	dllimport	dllexportexternal_weakghostcommonlinker_privatelinker_private_weak r1   r1   =/tmp/pip-target-vg8gfxp4/lib/python/llvmlite/binding/value.pyr      s$    r   c                   @      e Zd ZdZdZdZdS )
Visibilityr   r   r   N)r   r   r   defaulthidden	protectedr1   r1   r1   r2   r4          r4   c                   @   r3   )StorageClassr   r   r   N)r   r   r   r5   r*   r+   r1   r1   r1   r2   r9   &   r8   r9   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      t t j| S )z
        Get type name
        )r	   
ret_stringlibLLVMPY_GetTypeNameselfr1   r1   r2   name1   s   zTypeRef.namec                 C      t j| S )z=
        Returns true is the type is a pointer type.
        )r	   r=   LLVMPY_TypeIsPointerr?   r1   r1   r2   
is_pointer8      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)rD   
ValueErrorformatr:   r	   r=   LLVMPY_GetElementTyper?   r1   r1   r2   element_type?   s   zTypeRef.element_typec                 C   r;   N)r	   r<   r=   LLVMPY_PrintTyper?   r1   r1   r2   __str__I      zTypeRef.__str__N)	r   r   r   __doc__propertyrA   rD   rI   rL   r1   r1   r1   r2   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 rJ   )_kind_parentsr	   	ObjectRef__init__)r@   ptrkindparentsr1   r1   r2   rT   Q   s   zValueRef.__init__c                 C   sB   t  }t j| | t|W  d    S 1 sw   Y  d S rJ   )r	   OutputStringr=   LLVMPY_PrintValueToStringstr)r@   outstrr1   r1   r2   rL   V   s   
$zValueRef.__str__c                 C      | j dS )zV
        The module this function or global variable value was obtained from.
        modulerR   getr?   r1   r1   r2   r]   [   rE   zValueRef.modulec                 C   r\   )zT
        The function this argument or basic block value was obtained from.
        functionr^   r?   r1   r1   r2   r`   b   rE   zValueRef.functionc                 C   r\   )zE
        The block this instruction value was obtained from.
        blockr^   r?   r1   r1   r2   ra   i   rE   zValueRef.blockc                 C   r\   )zG
        The instruction this operand value was obtained from.
        instructionr^   r?   r1   r1   r2   rb   p   rE   zValueRef.instructionc                 C   
   | j dkS )NglobalrQ   r?   r1   r1   r2   	is_globalw      
zValueRef.is_globalc                 C   rc   )Nr`   re   r?   r1   r1   r2   is_function{   rg   zValueRef.is_functionc                 C   rc   )Nra   re   r?   r1   r1   r2   is_block   rg   zValueRef.is_blockc                 C   rc   )Nargumentre   r?   r1   r1   r2   is_argument   rg   zValueRef.is_argumentc                 C   rc   )Nrb   re   r?   r1   r1   r2   is_instruction   rg   zValueRef.is_instructionc                 C   rc   )Noperandre   r?   r1   r1   r2   
is_operand   rg   zValueRef.is_operandc                 C      t tj| S rJ   )r
   r	   r=   LLVMPY_GetValueNamer?   r1   r1   r2   rA         zValueRef.namec                 C   s   t j| t| d S rJ   )r	   r=   LLVMPY_SetValueNamer   )r@   valr1   r1   r2   rA      s   c                 C   ro   rJ   )r   r	   r=   LLVMPY_GetLinkager?   r1   r1   r2   linkage   rq   zValueRef.linkagec                 C   $   t |ts	t| }tj| | d S rJ   )
isinstancer   r	   r=   LLVMPY_SetLinkager@   valuer1   r1   r2   ru         
c                 C   ro   rJ   )r4   r	   r=   LLVMPY_GetVisibilityr?   r1   r1   r2   
visibility   rq   zValueRef.visibilityc                 C   rv   rJ   )rw   r4   r	   r=   LLVMPY_SetVisibilityry   r1   r1   r2   r}      r{   c                 C   ro   rJ   )r9   r	   r=   LLVMPY_GetDLLStorageClassr?   r1   r1   r2   storage_class   rq   zValueRef.storage_classc                 C   rv   rJ   )rw   r9   r	   r=   LLVMPY_SetDLLStorageClassry   r1   r1   r2   r      r{   c                 C   s\   | j std| jf t|}tjt|t|}|dkr%t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)rh   rF   rQ   rZ   r	   r=   "LLVMPY_GetEnumAttributeKindForNamer   lenrG   LLVMPY_AddFunctionAttr)r@   attrattrnameattrvalr1   r1   r2   add_function_attribute   s   zValueRef.add_function_attributec                 C   ro   )z)
        This value's LLVM type.
        )r:   r	   r=   LLVMPY_TypeOfr?   r1   r1   r2   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)rf   rh   rF   rQ   r	   r=   LLVMPY_IsDeclarationr?   r1   r1   r2   is_declaration   s
   zValueRef.is_declarationc                 C   s   t d}| jrtj| }t|}|S | jr8| jdkr'tj| }t|}|S | jdkr6tj	| }t|}|S | j
rGtj| }t|}|S | jrTtj| }t|}|S )z
        Return an iterator over this value's attributes.
        The iterator will yield a string for each attribute.
        r1   callinvoke)iterrh   r	   r=   LLVMPY_FunctionAttributesIter_AttributeListIteratorrl   opcodeLLVMPY_CallInstAttributesIterLLVMPY_InvokeInstAttributesIterrf   LLVMPY_GlobalAttributesIter_AttributeSetIteratorrk   LLVMPY_ArgumentAttributesIter)r@   itritr1   r1   r2   
attributes   s,   


zValueRef.attributesc                 C   B   | 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   r`   )
rh   rF   rQ   r	   r=   LLVMPY_FunctionBlocksIterrR   copyupdate_BlocksIteratorr@   r   rW   r1   r1   r2   blocks      

zValueRef.blocksc                 C   r   )z
        Return an iterator over this function's arguments.
        The iterator will yield a ValueRef for each argument.
        r   r   )
rh   rF   rQ   r	   r=   LLVMPY_FunctionArgumentsIterrR   r   r   _ArgumentsIteratorr   r1   r1   r2   	arguments   r   zValueRef.argumentsc                 C   r   )z
        Return an iterator over this block's instructions.
        The iterator will yield a ValueRef for each instruction.
        zexpected block value, got %s)ra   )
ri   rF   rQ   r	   r=   LLVMPY_BlockInstructionsIterrR   r   r   _InstructionsIteratorr   r1   r1   r2   instructions  r   zValueRef.instructionsc                 C   r   )z
        Return an iterator over this instruction's operands.
        The iterator will yield a ValueRef for each operand.
        "expected instruction value, got %s)rb   )
rl   rF   rQ   r	   r=   LLVMPY_InstructionOperandsIterrR   r   r   _OperandsIteratorr   r1   r1   r2   operands  s   

zValueRef.operandsc                 C   s(   | j std| jf ttj| S )Nr   )rl   rF   rQ   r	   r<   r=   LLVMPY_GetOpcodeNamer?   r1   r1   r2   r   '  s
   zValueRef.opcodeN)r   r   r   rN   rT   rL   rO   r]   r`   ra   rb   rf   rh   ri   rk   rl   rn   rA   setterru   r}   r   r   r   r   r   r   r   r   r   r   r1   r1   r1   r2   rP   M   sr    

























rP   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 u rtdt| jf d S )Nz%s must specify kind attribute)r	   rS   rT   rR   rV   NotImplementedErrorr   r   )r@   rU   rW   r1   r1   r2   rT   4  s   

z_ValueIterator.__init__c                 C   s    |   }|rt|| j| jS trJ   )_nextrP   rV   rR   StopIterationr@   vpr1   r1   r2   __next__<  s   z_ValueIterator.__next__c                 C      | S rJ   r1   r?   r1   r1   r2   __iter__E     z_ValueIterator.__iter__)r   r   r   rV   rT   r   nextr   r1   r1   r1   r2   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rJ   )r   r   r   r1   r1   r2   r   K  s   z_AttributeIterator.__next__c                 C   r   rJ   r1   r?   r1   r1   r2   r   T  r   z_AttributeIterator.__iter__N)r   r   r   r   r   r   r1   r1   r1   r2   r   I  s    r   c                   @      e Zd Zdd Zdd ZdS )r   c                 C      | j |  d S rJ   )_capiLLVMPY_DisposeAttributeListIterr?   r1   r1   r2   _disposeZ     z_AttributeListIterator._disposec                 C   r;   rJ   )r	   	ret_bytesr=   LLVMPY_AttributeListIterNextr?   r1   r1   r2   r   ]  rM   z_AttributeListIterator._nextNr   r   r   r   r   r1   r1   r1   r2   r   X      r   c                   @   r   )r   c                 C   r   rJ   )r   LLVMPY_DisposeAttributeSetIterr?   r1   r1   r2   r   c  r   z_AttributeSetIterator._disposec                 C   r;   rJ   )r	   r   r=   LLVMPY_AttributeSetIterNextr?   r1   r1   r2   r   f  rM   z_AttributeSetIterator._nextNr   r1   r1   r1   r2   r   a  r   r   c                   @       e Zd ZdZdd Zdd ZdS )r   ra   c                 C   r   rJ   )r   LLVMPY_DisposeBlocksIterr?   r1   r1   r2   r   n  r   z_BlocksIterator._disposec                 C   rB   rJ   )r	   r=   LLVMPY_BlocksIterNextr?   r1   r1   r2   r   q     z_BlocksIterator._nextNr   r   r   rV   r   r   r1   r1   r1   r2   r   j      r   c                   @   r   )r   rj   c                 C   r   rJ   )r   LLVMPY_DisposeArgumentsIterr?   r1   r1   r2   r   y  r   z_ArgumentsIterator._disposec                 C   rB   rJ   )r	   r=   LLVMPY_ArgumentsIterNextr?   r1   r1   r2   r   |  r   z_ArgumentsIterator._nextNr   r1   r1   r1   r2   r   u  r   r   c                   @   r   )r   rb   c                 C   r   rJ   )r   LLVMPY_DisposeInstructionsIterr?   r1   r1   r2   r     r   z_InstructionsIterator._disposec                 C   rB   rJ   )r	   r=   LLVMPY_InstructionsIterNextr?   r1   r1   r2   r     r   z_InstructionsIterator._nextNr   r1   r1   r1   r2   r     r   r   c                   @   r   )r   rm   c                 C   r   rJ   )r   LLVMPY_DisposeOperandsIterr?   r1   r1   r2   r     r   z_OperandsIterator._disposec                 C   rB   rJ   )r	   r=   LLVMPY_OperandsIterNextr?   r1   r1   r2   r     r   z_OperandsIterator._nextNr   r1   r1   r1   r2   r     r   r   )Pctypesr   r   r   r   r   r   r   enumllvmlite.bindingr	   llvmlite.binding.commonr
   r   IntEnumr   r4   r9   rS   r:   rP   r   r   r   r   r   r   r   r   LLVMValueRefr=   rY   argtypesLLVMPY_GetGlobalParentLLVMModuleRefrestyperp   rr   r   LLVMTypeRefrK   rC   rH   r>   rt   rx   r|   r~   r   r   r   r   r   r   LLVMAttributeListIteratorr   r   r   LLVMAttributeSetIteratorr   r   LLVMBlocksIteratorr   LLVMArgumentsIteratorr   LLVMInstructionsIteratorr   LLVMOperandsIteratorr   r   r   r   r   r   r   r   r   r   r   r   r1   r1   r1   r2   <module>   s   $  c		












