o
    [ôj	<  ã                
   @   sŒ  d dl Z d dlmZmZmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ edg d	¢ƒZd
d„ Zdefdd„ZG dd„ deƒZdd„ Zdd„ Zdd„ Zed  Zdddddddddd œ	Zd-d!d"„Z d#d$„ Z!G d%d&„ d&e
j"ƒZ#e$g d'¢ƒZ%e$g d(¢ƒZ&G d)d*„ d*e
j"ƒZ'G d+d,„ d,e
j"ƒZ(eeƒge
j)j*_+eeeƒeeƒeeƒeeƒge
j)j,_+eeƒge
j)j-_+ee
j)j-_.eeƒge
j)j/_+eeƒge
j)j0_+ege
j)j1_+ee
j)j1_.ege
j)j2_+e
j3e
j)j2_.e
j3eeƒge
j)j4_+e
j3ge
j)j5_+e
j3e
j6ge
j)j7_+ee
j)j7_.e
j3e
j6ege
j)j8_+ee
j)j8_.e
j3e
j6ge
j)j9_+ee
j)j9_.eeeƒ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eeeeeeeeg
e
j)j>_+e
j?e
j)j>_.e
j?ge
j)j@_+e
j?eeƒge
j)jA_+e
j?ege
j)jB_+e
j?e
jCge
j)jD_+e
j?e
jEeeeƒge
j)jF_+e
jGe
j)jF_.e
jGge
j)jH_+ee
j)jH_.e
jGge
j)jI_+ee
j)jI_.e
jGge
j)jJ_+e
j?ge
j)jK_+e
j3e
j)jK_.dS ).é    N)ÚPOINTERÚc_char_pÚ
c_longlongÚc_intÚc_size_tÚc_void_pÚ	string_at)Úffi)Úllvm_version_info)Ú_decode_stringÚ_encode_string)Ú
namedtuple)Ú	_has_svmlÚTriple)ZArchZSubArchZVendorZOSZEnvZObjectFormatc                  C   ó@   t  ¡ �} t j | ¡ t| ƒW  d  ƒ S 1 sw   Y  dS )a  
    Return a target triple suitable for generating code for the current process.
    An example when the default triple from ``get_default_triple()`` is not be
    suitable is when LLVM is compiled for 32-bit but the process is executing
    in 64-bit mode.
    N)r	   ÚOutputStringÚlibÚLLVMPY_GetProcessTripleÚstr©Úout© r   úi/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/llvmlite/binding/targets.pyÚget_process_triple   s   
$þr   Útriplec                 C   sV  t  ¡ ��}t  ¡ �€}t  ¡ �l}t  ¡ �X}t j |  d¡||||¡ t|ƒ}d}|  d¡D ]}| |¡r=|t|ƒd… } nq,t	||t|ƒt|ƒt|ƒt
| ƒƒW  d  ƒ W  d  ƒ W  d  ƒ W  d  ƒ S 1 snw   Y  W d  ƒ n1 s}w   Y  W d  ƒ n1 sŒw   Y  W d  ƒ dS W d  ƒ dS 1 s¤w   Y  dS )z:
    Return a tuple of the parts of the given triple.
    Úutf8Ú ú-N)r	   r   r   ÚLLVMPY_GetTriplePartsÚencoder   ÚsplitÚ
startswithÚlenr   Úget_object_format)r   ÚarchÚvendorÚosÚenvZsubarchÚ_strr   r   r   Úget_triple_parts   s2   
ÿþþÿ
þÿhõ€P r)   c                   @   s   e Zd ZdZddd„ZdS )Ú
FeatureMapz…
    Maps feature name to a boolean indicating the availability of the feature.
    Extends ``dict`` to add `.flatten()` method.
    Tc                    s>   |rt |  ¡ ƒnt|  ¡ ƒ}dddœ‰ d ‡ fdd„|D ƒ¡S )ap  
        Args
        ----
        sort: bool
            Optional.  If True, the features are sorted by name; otherwise,
            the ordering is unstable between python session due to hash
            randomization.  Defaults to True.

        Returns a string suitable for use as the ``features`` argument to
        ``Target.create_target_machine()``.

        ú+r   )TFú,c                 3   s$   � | ]\}}d   ˆ | |¡V  qdS )z{0}{1}N)Úformat)Ú.0ÚkÚv©Úflag_mapr   r   Ú	<genexpr>F   s   € ÿz%FeatureMap.flatten.<locals>.<genexpr>)ÚsortedÚitemsÚiterÚjoin)ÚselfÚsortÚiteratorr   r1   r   Úflatten7   s
   
ÿzFeatureMap.flattenN)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r;   r   r   r   r   r*   1   s    r*   c                  C   s–   t  ¡ �=} tƒ }t j | ¡s|W  d  ƒ S dddœ}t| ƒ}|r8| d¡D ]}|r7||d  ||dd… < q'|W  d  ƒ S 1 sDw   Y  dS )ac  
    Returns a dictionary-like object indicating the CPU features for current
    architecture and whether they are enabled for this CPU.  The key-value pairs
    are the feature name as string and a boolean indicating whether the feature
    is available.  The returned value is an instance of ``FeatureMap`` class,
    which adds a new method ``.flatten()`` for returning a string suitable for
    use as the "features" argument to ``Target.create_target_machine()``.

    If LLVM has not implemented this feature or it fails to get the information,
    this function will raise a RuntimeError exception.
    NTF)r+   r   r,   r   é   )r	   r   r*   r   ÚLLVMPY_GetHostCPUFeaturesr   r    )r   Zoutdictr2   ÚcontentZfeatr   r   r   Úget_host_cpu_featuresJ   s   
ý
€$örC   c                  C   r   )zR
    Return the default target triple LLVM is configured to produce code for.
    N)r	   r   r   ÚLLVMPY_GetDefaultTargetTripler   r   r   r   r   Úget_default_triplec   s   
$þrE   c                  C   r   )zm
    Get the name of the host's CPU, suitable for using with
    :meth:`Target.create_target_machine()`.
    N)r	   r   r   ÚLLVMPY_GetHostCPUNamer   r   r   r   r   Úget_host_cpu_namel   s   
$þrG   ÚUnknownÚCOFFZDXContainerÚELFZGOFFZMachOZSPIRVZWasmZXCOFF)	r   r@   é   é   é   é   é   é   é   c                 C   s&   | du rt ƒ } tj t| ƒ¡}t| S )z~
    Get the object format for the given *triple* string (or the default
    triple if omitted).
    A string is returned
    N)rE   r	   r   ÚLLVMPY_GetTripleObjectFormatr   Ú_object_formats)r   Úresr   r   r   r#   ‡   s   r#   c                 C   s   t tj t| ƒ¡ƒS )zE
    Create a TargetData instance for the given *layout* string.
    )Ú
TargetDatar	   r   ÚLLVMPY_CreateTargetDatar   )Úlayoutr   r   r   Úcreate_target_data“   s   rX   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )rU   z{
    A TargetData provides structured access to a data layout.
    Use :func:`create_target_data` to create instances.
    c                 C   sL   | j rdS t ¡ �}tj | |¡ t|ƒW  d   ƒ S 1 sw   Y  d S )Nz<dead TargetData>)Ú_closedr	   r   r   Ú LLVMPY_CopyStringRepOfTargetDatar   ©r8   r   r   r   r   Ú__str__    s   
$þzTargetData.__str__c                 C   ó   | j  | ¡ d S ©N)Ú_capiÚLLVMPY_DisposeTargetData©r8   r   r   r   Ú_dispose§   ó   zTargetData._disposec                 C   ó   t j | |¡S )z1
        Get ABI size of LLVM type *ty*.
        )r	   r   ÚLLVMPY_ABISizeOfType©r8   Útyr   r   r   Úget_abi_sizeª   ó   zTargetData.get_abi_sizec                 C   s0   t j | ||¡}|dkrtd |t|ƒ¡ƒ‚|S )zL
        Get byte offset of type's ty element at the given position
        éÿÿÿÿzQCould not determined offset of {}th element of the type '{}'. Is it a structtype?)r	   r   ÚLLVMPY_OffsetOfElementÚ
ValueErrorr-   r   )r8   rg   ÚpositionÚoffsetr   r   r   Úget_element_offset°   s   þzTargetData.get_element_offsetc                 C   rd   )z>
        Get minimum ABI alignment of LLVM type *ty*.
        )r	   r   ÚLLVMPY_ABIAlignmentOfTyperf   r   r   r   Úget_abi_alignment¼   ri   zTargetData.get_abi_alignmentN)	r<   r=   r>   r?   r\   rb   rh   ro   rq   r   r   r   r   rU   š   s    rU   )ÚdefaultÚstaticZpicZdynamicnopic)rr   Ú
jitdefaultÚsmallÚkernelÚmediumÚlargec                   @   sd   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZ	ed
d„ ƒZ
dd„ Z			ddd„ZdS )ÚTargetr   c                 C   s   t ƒ }|  |¡S )zB
        Create a Target instance for the default triple.
        )rE   Úfrom_triple)Úclsr   r   r   r   Úfrom_default_tripleÎ   s   
zTarget.from_default_triplec                 C   sb   t  ¡ �#}t j | d¡|¡}|stt|ƒƒ‚| |ƒ}||_|W  d  ƒ S 1 s*w   Y  dS )zK
        Create a Target instance for the given triple (a string).
        r   N)r	   r   r   ÚLLVMPY_GetTargetFromTripler   ÚRuntimeErrorr   Ú_triple)r{   r   ÚouterrÚtargetr   r   r   rz   Ö   s   
ÿ$ùzTarget.from_triplec                 C   ó   t j | ¡}t|ƒS r^   )r	   r   ÚLLVMPY_GetTargetNamer   ©r8   Úsr   r   r   Únameä   ó   zTarget.namec                 C   r‚   r^   )r	   r   ÚLLVMPY_GetTargetDescriptionr   r„   r   r   r   Údescriptioné   r‡   zTarget.descriptionc                 C   s   | j S r^   )r   ra   r   r   r   r   î   s   zTarget.triplec                 C   s   d  | j| j¡S )Nz<Target {0} ({1})>)r-   r†   r‰   ra   r   r   r   r\   ò   rc   zTarget.__str__rK   rr   rt   Fc	                 C   s¦   d|  krdksJ ‚ J ‚|t v sJ ‚|tv sJ ‚| j}	tjdkr*|dkr*|	d7 }	tj | t|	ƒt|ƒt|ƒ|t|ƒt|ƒt	|ƒt	|ƒt|ƒ¡
}
|
rOt
|
ƒS tdƒ‚)am  
        Create a new TargetMachine for this target and the given options.

        Specifying codemodel='default' will result in the use of the "small"
        code model. Specifying codemodel='jitdefault' will result in the code
        model being picked based on platform bitness (32="small", 64="large").

        The `printmc` option corresponds to llvm's `-print-machineinstrs`.

        The `jit` option should be set when the target-machine is to be used
        in a JIT engine.

        The `abiname` option specifies the ABI. RISC-V targets with hard-float
        needs to pass the ABI name to LLVM.
        r   rL   Úntrt   z-elfzCannot create target machine)ÚRELOCÚ	CODEMODELr   r&   r†   r	   r   ÚLLVMPY_CreateTargetMachiner   ÚintÚTargetMachiner~   )r8   ÚcpuÚfeaturesÚoptZrelocZ	codemodelZprintmcÚjitZabinamer   Útmr   r   r   Úcreate_target_machineõ   s(   ÷zTarget.create_target_machineN)r   r   rK   rr   rt   FFr   )r<   r=   r>   r   Úclassmethodr|   rz   Úpropertyr†   r‰   r   r\   r•   r   r   r   r   ry   È   s"    




þry   c                   @   sV   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zddd„Ze	dd„ ƒZ
e	dd„ ƒZdS )r�   c                 C   r]   r^   )r_   ÚLLVMPY_DisposeTargetMachinera   r   r   r   rb   #  rc   zTargetMachine._disposec                 C   ó   t j | |¡ dS )zW
        Register analysis passes for this target machine with a pass manager.
        N)r	   r   ÚLLVMPY_AddAnalysisPasses)r8   Úpmr   r   r   Úadd_analysis_passes&  s   z!TargetMachine.add_analysis_passesc                 C   r™   )z 
        Set whether this target machine will emit assembly with human-readable
        comments describing control flow, debug information, and so on.
        N)r	   r   Ú#LLVMPY_SetTargetMachineAsmVerbosity)r8   Úverboser   r   r   Úset_asm_verbosity,  s   zTargetMachine.set_asm_verbosityc                 C   s   | j |dd�S )z…
        Represent the module as a code object, suitable for use with
        the platform's linker.  Returns a byte string.
        T©Ú
use_object)Ú_emit_to_memory©r8   Úmoduler   r   r   Úemit_object3  s   zTargetMachine.emit_objectc                 C   s   t | j|dd�ƒS )z�
        Return the raw assembler of the module, as a string.

        llvm.initialize_native_asmprinter() must have been called first.
        Fr    )r   r¢   r£   r   r   r   Úemit_assembly:  s   zTargetMachine.emit_assemblyFc              	   C   sŽ   t  ¡ �}t j | |t|ƒ|¡}|stt|ƒƒ‚W d  ƒ n1 s"w   Y  t j |¡}t j |¡}zt	||ƒW t j 
|¡ S t j 
|¡ w )z¨Returns bytes of object code of the module.

        Args
        ----
        use_object : bool
            Emit object code or (if False) emit assembly code.
        N)r	   r   r   Ú LLVMPY_TargetMachineEmitToMemoryrŽ   r~   r   ÚLLVMPY_GetBufferStartÚLLVMPY_GetBufferSizer   ÚLLVMPY_DisposeMemoryBuffer)r8   r¤   r¡   r€   ÚmbZbufptrZbufszr   r   r   r¢   B  s   

þÿü
zTargetMachine._emit_to_memoryc                 C   s   t tj | ¡ƒS r^   )rU   r	   r   ÚLLVMPY_CreateTargetMachineDatara   r   r   r   Útarget_dataX  s   zTargetMachine.target_datac                 C   sB   t  ¡ �}t j | |¡ t|ƒW  d   ƒ S 1 sw   Y  d S r^   )r	   r   r   ÚLLVMPY_GetTargetMachineTripler   r[   r   r   r   r   \  s   
$þzTargetMachine.tripleN)F)r<   r=   r>   rb   rœ   rŸ   r¥   r¦   r¢   r—   r­   r   r   r   r   r   r�   !  s    

r�   r^   )Lr&   Úctypesr   r   r   r   r   r   r   Úllvmlite.bindingr	   Zllvmlite.binding.initfinir
   Úllvmlite.binding.commonr   r   Úcollectionsr   Zllvmlite.binding.configr   Úhas_svmlr   r   r   r)   Údictr*   rC   rE   rG   Zllvm_version_majorrS   r#   rX   Ú	ObjectRefrU   Ú	frozensetr‹   rŒ   ry   r�   r   r   Úargtypesr   rA   ÚrestyperD   rF   rR   rV   ÚLLVMTargetDataRefrZ   r`   ÚLLVMTypeRefre   rk   rp   r}   ÚLLVMTargetRefrƒ   rˆ   r�   ÚLLVMTargetMachineRefr˜   r®   r�   ÚLLVMPassManagerRefrš   ÚLLVMModuleRefr§   ÚLLVMMemoryBufferRefr¨   r©   rª   r¬   r   r   r   r   Ú<module>   sÐ    $	÷
)YE
þ


þ
ÿ
ÿ

þ

ÿ



í
ÿ
ÿ
þ
ü


ÿ