o
    "&iN                     @   sZ  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 d dl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"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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jJej%jI_*ej;gej%jK_'ej?gej%jL_'ejBgej%jM_'ejFgej%jN_'ejHgej%jO_'ejJgej%jP_'ej;gej%jQ_'eej%jQ_*ej?gej%jR_'eej%jR_*ejBgej%jS_'ej$ej%jS_*ejDgej%jT_'ej$ej%jT_*ejFgej%jU_'ej$ej%jU_*ejHgej%jV_'ej$ej%jV_*ejJgej%jW_'ej$ej%jW_*ej$gej%jX_'eej%jX_*ej$gej%jY_'e
ej%jY_*ej$gej%jZ_'eej%jZ_*ej$ee
gej%j[_'ee	ej%j[_*ej$gej%j\_'eej%j\_*ej$ee
gej%j]_'eej%j]_*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_string)TypeRefc                   @   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*   AC:\wamp64\www\opt\env\Lib\site-packages\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$   defaultZhiddenZ	protectedr*   r*   r*   r+   r-           r-   c                   @   r,   )StorageClassr   r   r   N)r"   r#   r$   r.   r&   r'   r*   r*   r*   r+   r0   (   r/   r0   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+   r1   0   s6    r1   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 ed<d= Z!ed>d? Z"dDdAdBZ#dCS )EValueRefz&A weak reference to a LLVM value.
    c                 C   s   || _ || _tj| | d S N)_kind_parentsr   	ObjectRef__init__)selfptrkindparentsr*   r*   r+   rE   W   s   zValueRef.__init__c                 C   sB   t  }t j| | t|W  d    S 1 sw   Y  d S rA   )r   OutputStringlibLLVMPY_PrintValueToStringstr)rF   Zoutstrr*   r*   r+   __str__\   s   
$zValueRef.__str__c                 C      | j dS )zV
        The module this function or global variable value was obtained from.
        modulerC   getrF   r*   r*   r+   rP   a      zValueRef.modulec                 C   rO   )zT
        The function this argument or basic block value was obtained from.
        r<   rQ   rS   r*   r*   r+   r<   h   rT   zValueRef.functionc                 C   rO   )zE
        The block this instruction value was obtained from.
        blockrQ   rS   r*   r*   r+   rU   o   rT   zValueRef.blockc                 C   rO   )zG
        The instruction this operand value was obtained from.
        r?   rQ   rS   r*   r*   r+   r?   v   rT   zValueRef.instructionc                 C   
   | j dkS )NglobalrB   rS   r*   r*   r+   	is_global}      
zValueRef.is_globalc                 C   rV   )Nr<   rX   rS   r*   r*   r+   is_function   rZ   zValueRef.is_functionc                 C   rV   )NrU   rX   rS   r*   r*   r+   is_block   rZ   zValueRef.is_blockc                 C   rV   )Nr;   rX   rS   r*   r*   r+   is_argument   rZ   zValueRef.is_argumentc                 C   rV   )Nr?   rX   rS   r*   r*   r+   is_instruction   rZ   zValueRef.is_instructionc                 C   rV   )NoperandrX   rS   r*   r*   r+   
is_operand   rZ   zValueRef.is_operandc                 C      t tj| S rA   )boolr   rK   LLVMPY_IsConstantrS   r*   r*   r+   is_constant      zValueRef.is_constantc                 C   ra   rA   )r1   r   rK   LLVMPY_GetValueKindrS   r*   r*   r+   
value_kind   re   zValueRef.value_kindc                 C   ra   rA   )r   r   rK   LLVMPY_GetValueNamerS   r*   r*   r+   name   re   zValueRef.namec                 C   s   t j| t| d S rA   )r   rK   LLVMPY_SetValueNamer   )rF   valr*   r*   r+   ri      s   c                 C   ra   rA   )r   r   rK   LLVMPY_GetLinkagerS   r*   r*   r+   linkage   re   zValueRef.linkagec                 C   $   t |ts	t| }tj| | d S rA   )
isinstancer   r   rK   LLVMPY_SetLinkagerF   valuer*   r*   r+   rm         
c                 C   ra   rA   )r-   r   rK   LLVMPY_GetVisibilityrS   r*   r*   r+   
visibility   re   zValueRef.visibilityc                 C   rn   rA   )ro   r-   r   rK   LLVMPY_SetVisibilityrq   r*   r*   r+   ru      rs   c                 C   ra   rA   )r0   r   rK   LLVMPY_GetDLLStorageClassrS   r*   r*   r+   storage_class   re   zValueRef.storage_classc                 C   rn   rA   )ro   r0   r   rK   LLVMPY_SetDLLStorageClassrq   r*   r*   r+   rx      rs   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)r[   
ValueErrorrB   rM   r   rK   "LLVMPY_GetEnumAttributeKindForNamer   lenformatLLVMPY_AddFunctionAttr)rF   attrattrnameZattrvalr*   r*   r+   add_function_attribute   s   zValueRef.add_function_attributec                 C   ra   )z)
        This value's LLVM type.
        )r   r   rK   LLVMPY_TypeOfrS   r*   r*   r+   type   s   zValueRef.typec                 C   s    | j s| jsJ ttj| S )z
        Uses ``LLVMGlobalGetValueType()``.
        Needed for opaque pointers in globals.
        > For globals, use getValueType().
        See https://llvm.org/docs/OpaquePointers.html#migration-instructions
        )rY   r[   r   r   rK   LLVMPY_GlobalGetValueTyperS   r*   r*   r+   global_value_type   s   zValueRef.global_value_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)rY   r[   r{   rB   r   rK   LLVMPY_IsDeclarationrS   r*   r*   r+   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.
        r*   callZinvoke)iterr[   r   rK   LLVMPY_FunctionAttributesIter_AttributeListIteratorr^   opcodeLLVMPY_CallInstAttributesIterLLVMPY_InvokeInstAttributesIterrY   LLVMPY_GlobalAttributesIter_AttributeSetIteratorr]   LLVMPY_ArgumentAttributesIter)rF   itritr*   r*   r+   
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.
        rz   r<   )
r[   r{   rB   r   rK   LLVMPY_FunctionBlocksIterrC   copyupdate_BlocksIteratorrF   r   rI   r*   r*   r+   blocks     

zValueRef.blocksc                 C   r   )z
        Return an iterator over this function's arguments.
        The iterator will yield a ValueRef for each argument.
        rz   r   )
r[   r{   rB   r   rK   LLVMPY_FunctionArgumentsIterrC   r   r   _ArgumentsIteratorr   r*   r*   r+   	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)rU   )
r\   r{   rB   r   rK   LLVMPY_BlockInstructionsIterrC   r   r   _InstructionsIteratorr   r*   r*   r+   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r?   )
r^   r{   rB   r   rK   LLVMPY_InstructionOperandsIterrC   r   r   _OperandsIteratorr   r*   r*   r+   operands2  s   

zValueRef.operandsc                 C   s(   | j std| jf ttj| S )Nr   )r^   r{   rB   r   Z
ret_stringrK   LLVMPY_GetOpcodeNamerS   r*   r*   r+   r   @  s
   zValueRef.opcodec                 C   sL   | j r| jdkrtd| jf tj| }| j }|j	| d t
||S )z
        Return an iterator over this phi instruction's incoming blocks.
        The iterator will yield a ValueRef for each block.
        phiz&expected phi instruction value, got %sr   )r^   r   r{   rB   r   rK   LLVMPY_PhiIncomingBlocksIterrC   r   r   _IncomingBlocksIteratorr   r*   r*   r+   incoming_blocksG  s   

zValueRef.incoming_blocksFc           	      C   s   | j std| jf | jtjkr@td}tj	| }tj
| t|}tt|tt| j}tj||jr;d|dS d|dS | jtjkrctd}tj| t|}|jra|sat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 )rd   r{   rB   rg   r1   r=   r   r   rK   LLVMPY_GetConstantIntNumWordsLLVMPY_GetConstantIntRawValuer   bytesr   r   r
   contentsint
from_bytesrr   r>   LLVMPY_GetConstantFPValuerM   )	rF   Z
signed_intZround_fpZlittle_endianwordsrG   ZasbytesZaccuracy_lossrr   r*   r*   r+   get_constant_valueU  s@   
zValueRef.get_constant_valueN)FF)$r"   r#   r$   __doc__rE   rN   propertyrP   r<   rU   r?   rY   r[   r\   r]   r^   r`   rd   rg   ri   setterrm   ru   rx   r   r   r   r   r   r   r   r   r   r   r   r   r*   r*   r*   r+   r@   S   s    































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 u rtdt| jf d S )Nz%s must specify kind attribute)r   rD   rE   rC   rH   NotImplementedErrorr   r"   )rF   rG   rI   r*   r*   r+   rE     s   

z_ValueIterator.__init__c                 C   s    |   }|rt|| j| jS trA   )_nextr@   rH   rC   StopIterationrF   Zvpr*   r*   r+   __next__  s   z_ValueIterator.__next__c                 C      | S rA   r*   rS   r*   r*   r+   __iter__     z_ValueIterator.__iter__)r"   r#   r$   rH   rE   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rA   )r   r   r   r*   r*   r+   r     s   z_AttributeIterator.__next__c                 C   r   rA   r*   rS   r*   r*   r+   r     r   z_AttributeIterator.__iter__N)r"   r#   r$   r   r   r   r*   r*   r*   r+   r     s    r   c                   @      e Zd Zdd Zdd ZdS )r   c                 C      | j |  d S rA   )_capiLLVMPY_DisposeAttributeListIterrS   r*   r*   r+   _dispose     z_AttributeListIterator._disposec                 C      t t j| S rA   )r   	ret_bytesrK   LLVMPY_AttributeListIterNextrS   r*   r*   r+   r        z_AttributeListIterator._nextNr"   r#   r$   r   r   r*   r*   r*   r+   r         r   c                   @   r   )r   c                 C   r   rA   )r   LLVMPY_DisposeAttributeSetIterrS   r*   r*   r+   r     r   z_AttributeSetIterator._disposec                 C   r   rA   )r   r   rK   LLVMPY_AttributeSetIterNextrS   r*   r*   r+   r     r   z_AttributeSetIterator._nextNr   r*   r*   r*   r+   r     r   r   c                   @       e Zd ZdZdd Zdd ZdS )r   rU   c                 C   r   rA   )r   LLVMPY_DisposeBlocksIterrS   r*   r*   r+   r     r   z_BlocksIterator._disposec                 C      t j| S rA   )r   rK   LLVMPY_BlocksIterNextrS   r*   r*   r+   r        z_BlocksIterator._nextNr"   r#   r$   rH   r   r   r*   r*   r*   r+   r         r   c                   @   r   )r   r;   c                 C   r   rA   )r   ZLLVMPY_DisposeArgumentsIterrS   r*   r*   r+   r     r   z_ArgumentsIterator._disposec                 C   r   rA   )r   rK   LLVMPY_ArgumentsIterNextrS   r*   r*   r+   r     r   z_ArgumentsIterator._nextNr   r*   r*   r*   r+   r     r   r   c                   @   r   )r   r?   c                 C   r   rA   )r   LLVMPY_DisposeInstructionsIterrS   r*   r*   r+   r     r   z_InstructionsIterator._disposec                 C   r   rA   )r   rK   LLVMPY_InstructionsIterNextrS   r*   r*   r+   r     r   z_InstructionsIterator._nextNr   r*   r*   r*   r+   r     r   r   c                   @   r   )r   r_   c                 C   r   rA   )r   LLVMPY_DisposeOperandsIterrS   r*   r*   r+   r     r   z_OperandsIterator._disposec                 C   r   rA   )r   rK   LLVMPY_OperandsIterNextrS   r*   r*   r+   r     r   z_OperandsIterator._nextNr   r*   r*   r*   r+   r     r   r   c                   @   r   )r   rU   c                 C   r   rA   )r    LLVMPY_DisposeIncomingBlocksIterrS   r*   r*   r+   r     r   z _IncomingBlocksIterator._disposec                 C   r   rA   )r   rK   LLVMPY_IncomingBlocksIterNextrS   r*   r*   r+   r     r   z_IncomingBlocksIterator._nextNr   r*   r*   r*   r+   r     r   r   )^ctypesr   r   r   r   r   r   r   r	   r
   r   r   enumZllvmlite.bindingr   Zllvmlite.binding.commonr   r   Zllvmlite.binding.typerefr   IntEnumr   r-   r0   r1   rD   r@   r   r   r   r   r   r   r   r   r   ZLLVMValueRefrK   rL   argtypesZLLVMPY_GetGlobalParentZLLVMModuleRefrestyperh   rj   r   ZLLVMTypeRefr   ZLLVMPY_GetTypeNamerl   rp   rt   rv   rw   ry   r|   r   r   r   ZLLVMAttributeListIteratorr   r   r   ZLLVMAttributeSetIteratorr   r   ZLLVMBlocksIteratorr   ZLLVMArgumentsIteratorr   ZLLVMInstructionsIteratorr   ZLLVMOperandsIteratorr   ZLLVMIncomingBlocksIteratorr   r   r   r   r   r   r   r   r   r   r   r   r   r   rc   rf   r   r   r   r*   r*   r*   r+   <module>   s   4 #  2		


















