o
    Zôj¦+  ã                   @   s0  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mZ d dlmZ ddd	„Zdd
d„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e	jeeeƒge	jj_e	j e	jj_!e	j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j$_e	j eeƒeeƒge	jj%_e	j ege	jj&_e	j'e	jj&_!e	j eeƒge	jj(_ee	jj(_!e	j eeƒge	jj)_e	j ege	jj*_e	j eeƒge	jj+_e	j ege	jj,_e	j ege	jj-_e	j'e	jj-_!e	j ege	jj._e	j/e	jj._!e	j ge	jj0_e	j1e	jj0_!e	j1ge	jj2_e	j1ge	jj3_e	j'e	jj3_!e	j ge	jj4_e	j5e	jj4_!e	j ge	jj6_e	j7e	jj6_!e	j5ge	jj8_e	j7ge	jj9_e	j5ge	jj:_e	j'e	jj:_!e	j7g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e	jj=_!e	j ege	jj>_e	j ge	jj?_ee	jj?_!dS )é    )Úc_char_pÚbyrefÚPOINTERÚc_boolÚcreate_string_bufferÚc_size_tÚ	string_at)Úffi)Úlink_modules)Ú_decode_stringÚ_encode_string)ÚValueRefÚTypeRef)Úget_global_contextNc                 C   s|   |du rt ƒ }t| ƒ} t| ƒ}t ¡ �!}ttj |||¡|ƒ}|r,| ¡  t	d 
|¡ƒ‚W d  ƒ |S 1 s7w   Y  |S )z-
    Create Module from a LLVM IR string
    NzLLVM IR parsing error
{0})r   r   r   r	   ÚOutputStringÚ	ModuleRefÚlibÚLLVMPY_ParseAssemblyÚcloseÚRuntimeErrorÚformat)ZllvmirÚcontextZstrbufÚerrmsgÚmod© r   úh/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/llvmlite/binding/module.pyÚparse_assembly   s"   
þþ
üùr   c                 C   s~   |du rt ƒ }t| ƒ}t| ƒ}t ¡ �"}ttj ||||¡|ƒ}|r-| ¡  t	d 
|¡ƒ‚W d  ƒ |S 1 s8w   Y  |S )z?
    Create Module from a LLVM *bitcode* (a bytes object).
    NzLLVM bitcode parsing error
{0})r   r   Úlenr	   r   r   r   ÚLLVMPY_ParseBitcoder   r   r   )Zbitcoder   ÚbufÚbufsizer   r   r   r   r   Úparse_bitcode   s(   
ÿÿÿþ
ýùr!   c                       sè   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZej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d(dd„Zed d!„ ƒZed"d#„ ƒZed$d%„ ƒZd&d'„ Z‡  ZS ))r   z'
    A reference to a LLVM module.
    c                    s   t t| ƒ |¡ || _d S ©N)Úsuperr   Ú__init__Ú_context)ÚselfÚ
module_ptrr   ©Ú	__class__r   r   r$   4   s   
zModuleRef.__init__c                 C   sB   t  ¡ �}t j | |¡ t|ƒW  d   ƒ S 1 sw   Y  d S r"   )r	   r   r   ÚLLVMPY_PrintModuleToStringÚstr)r&   Úoutstrr   r   r   Ú__str__8   s   
$þzModuleRef.__str__c              	   C   sh   t dƒ}tdƒ}tj | t|ƒt|ƒ¡ |st‚z|jdks J ‚t||jƒW tj 	|¡ S tj 	|¡ w )zF
        Return the module's LLVM bitcode, as a bytes object.
        Néÿÿÿÿr   )
r   r   r	   r   ÚLLVMPY_WriteBitcodeToStringr   ÚMemoryErrorÚvaluer   ÚLLVMPY_DisposeString)r&   ÚptrÚsizer   r   r   Ú
as_bitcode=   s   zModuleRef.as_bitcodec                 C   ó   | j  | ¡ d S r"   )Ú_capiÚLLVMPY_DisposeModule©r&   r   r   r   Ú_disposeL   ó   zModuleRef._disposec                 C   ó0   t j | t|ƒ¡}|st|ƒ‚t|dt| d�ƒS )z~
        Get a ValueRef pointing to the function named *name*.
        NameError is raised if the symbol isn't found.
        Úfunction©Úmodule)r	   r   ÚLLVMPY_GetNamedFunctionr   Ú	NameErrorr   Údict©r&   ÚnameÚpr   r   r   Úget_functionO   ó   zModuleRef.get_functionc                 C   r<   )z…
        Get a ValueRef pointing to the global variable named *name*.
        NameError is raised if the symbol isn't found.
        Úglobalr>   )r	   r   ÚLLVMPY_GetNamedGlobalVariabler   rA   r   rB   rC   r   r   r   Úget_global_variableY   rG   zModuleRef.get_global_variablec                 C   s&   t j | t|ƒ¡}|st|ƒ‚t|ƒS )z†
        Get a TypeRef pointing to a structure type named *name*.
        NameError is raised if the struct type isn't found.
        )r	   r   ÚLLVMPY_GetNamedStructTyper   rA   r   rC   r   r   r   Úget_struct_typec   s   zModuleRef.get_struct_typec                 C   sH   t  ¡ �}t j | |¡rtt|ƒƒ‚W d  ƒ dS 1 sw   Y  dS )zW
        Verify the module IR's correctness.  RuntimeError is raised on error.
        N)r	   r   r   ÚLLVMPY_VerifyModuler   r+   ©r&   Zoutmsgr   r   r   Úverifym   s
   
ÿ"ÿzModuleRef.verifyc                 C   ó   t tj | ¡ƒS )z*
        The module's identifier.
        )r   r	   r   ÚLLVMPY_GetModuleNamer9   r   r   r   rD   u   ó   zModuleRef.namec                 C   s   t j | t|ƒ¡ d S r"   )r	   r   ÚLLVMPY_SetModuleNamer   )r&   r1   r   r   r   rD   |   s   c                 C   rP   )z8
        The module's original source file name
        )r   r	   r   ÚLLVMPY_GetModuleSourceFileNamer9   r   r   r   Úsource_file€   rR   zModuleRef.source_filec                 C   óF   t jdd��}t j | |¡ t|ƒW  d  ƒ S 1 sw   Y  dS )zG
        This module's data layout specification, as a string.
        F©ÚownedN)r	   r   r   ÚLLVMPY_GetDataLayoutr+   rN   r   r   r   Údata_layout‡   ó   $þzModuleRef.data_layoutc                 C   ó   t j | t| d¡ƒ¡ d S ©NÚutf8)r	   r   ÚLLVMPY_SetDataLayoutr   Úencode©r&   Zstrrepr   r   r   rZ   ‘   ó
   ÿÿc                 C   rV   )zK
        This module's target "triple" specification, as a string.
        FrW   N)r	   r   r   ÚLLVMPY_GetTargetr+   rN   r   r   r   Útriple—   r[   zModuleRef.triplec                 C   r\   r]   )r	   r   ÚLLVMPY_SetTargetr   r`   ra   r   r   r   rd   ¡   rb   Fc                 C   s   |r|  ¡ }t| |ƒ dS )z�
        Link the *other* module into this one.  The *other* module will
        be destroyed unless *preserve* is true.
        N)Úcloner
   )r&   ÚotherÚpreserver   r   r   Úlink_in§   s   zModuleRef.link_inc                 C   ó   t j | ¡}t|t| d�ƒS )a)  
        Return an iterator over this module's global variables.
        The iterator will yield a ValueRef for each global variable.

        Note that global variables don't include functions
        (a function is a "global value" but not a "global variable" in
         LLVM parlance)
        r>   )r	   r   ÚLLVMPY_ModuleGlobalsIterÚ_GlobalsIteratorrB   ©r&   Úitr   r   r   Úglobal_variables°   s   
zModuleRef.global_variablesc                 C   rj   )z€
        Return an iterator over this module's functions.
        The iterator will yield a ValueRef for each function.
        r>   )r	   r   ÚLLVMPY_ModuleFunctionsIterÚ_FunctionsIteratorrB   rm   r   r   r   Ú	functions½   ó   zModuleRef.functionsc                 C   rj   )z|
        Return an iterator over the struct types defined in
        the module. The iterator will yield a TypeRef.
        r>   )r	   r   ÚLLVMPY_ModuleTypesIterÚ_TypesIteratorrB   rm   r   r   r   Ústruct_typesÆ   rs   zModuleRef.struct_typesc                 C   s   t tj | ¡| jƒS r"   )r   r	   r   ÚLLVMPY_CloneModuler%   r9   r   r   r   rf   Ï   s   zModuleRef.clone)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r-   r5   r:   rF   rJ   rL   rO   ÚpropertyrD   ÚsetterrU   rZ   rd   ri   ro   rr   rv   rf   Ú__classcell__r   r   r(   r   r   /   s@    






	

	

	


r   c                   @   s,   e Zd ZdZdd„ Zdd„ ZeZdd„ ZdS )Ú	_IteratorNc                 C   s&   t j | |¡ || _| jd usJ ‚d S r"   )r	   Ú	ObjectRefr$   Ú_parentsÚkind)r&   r3   Úparentsr   r   r   r$   ×   s   z_Iterator.__init__c                 C   s    |   ¡ }|rt|| j| jƒS t‚r"   )Ú_nextr   r‚   r�   ÚStopIteration©r&   Úvpr   r   r   Ú__next__Ü   s   z_Iterator.__next__c                 C   s   | S r"   r   r9   r   r   r   Ú__iter__å   s   z_Iterator.__iter__)rx   ry   rz   r‚   r$   rˆ   Únextr‰   r   r   r   r   r   Ó   s    r   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )rl   rH   c                 C   r6   r"   )r7   ÚLLVMPY_DisposeGlobalsIterr9   r   r   r   r:   í   r;   z_GlobalsIterator._disposec                 C   ó   t j | ¡S r"   )r	   r   ÚLLVMPY_GlobalsIterNextr9   r   r   r   r„   ð   ó   z_GlobalsIterator._nextN©rx   ry   rz   r‚   r:   r„   r   r   r   r   rl   é   ó    rl   c                   @   r‹   )rq   r=   c                 C   r6   r"   )r7   ÚLLVMPY_DisposeFunctionsIterr9   r   r   r   r:   ø   r;   z_FunctionsIterator._disposec                 C   r�   r"   )r	   r   ÚLLVMPY_FunctionsIterNextr9   r   r   r   r„   û   r�   z_FunctionsIterator._nextNr�   r   r   r   r   rq   ô   r‘   rq   c                   @   s,   e Zd ZdZdd„ Zdd„ Zdd„ ZeZdS )	ru   Útypec                 C   r6   r"   )r7   ÚLLVMPY_DisposeTypesIterr9   r   r   r   r:     r;   z_TypesIterator._disposec                 C   s   |   ¡ }|r
t|ƒS t‚r"   )r„   r   r…   r†   r   r   r   rˆ     s   z_TypesIterator.__next__c                 C   r�   r"   )r	   r   ÚLLVMPY_TypesIterNextr9   r   r   r   r„     r�   z_TypesIterator._nextN)rx   ry   rz   r‚   r:   rˆ   r„   rŠ   r   r   r   r   ru   ÿ   s    ru   r"   )@Úctypesr   r   r   r   r   r   r   Úllvmlite.bindingr	   Zllvmlite.binding.linkerr
   Úllvmlite.binding.commonr   r   Zllvmlite.binding.valuer   r   Zllvmlite.binding.contextr   r   r!   r€   r   r   rl   rq   ru   ÚLLVMContextRefr   r   ÚargtypesÚLLVMModuleRefÚrestyper   r8   r*   r/   r@   ÚLLVMValueRefrM   rY   r_   rc   re   rI   rK   ÚLLVMTypeRefrk   ÚLLVMGlobalsIteratorrŒ   rŽ   rp   ÚLLVMFunctionsIteratorrt   ÚLLVMTypesIteratorr’   r•   r“   r–   rw   rQ   rS   rT   r   r   r   r   Ú<module>   sŒ   $ 

 %
þ
þ
ÿ
þ
ÿ
ÿ

