o
    C2h+                     @   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)llvmircontextstrbuferrmsgmod r   k/var/www/html/alexa/alex_system/speach-to-text/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   )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.
        Nr   )
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.
        globalrA   )r	   r   LLVMPY_GetNamedGlobalVariabler   rD   r   rE   rF   r   r   r   get_global_variableY   rJ   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   rD   r   rF   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)   outmsgr   r   r   verifym   s
   
"zModuleRef.verifyc                 C      t tj| S )z*
        The module's identifier.
        )r   r	   r   LLVMPY_GetModuleNamer<   r   r   r   rG   u      zModuleRef.namec                 C   s   t j| t| d S r%   )r	   r   LLVMPY_SetModuleNamer   )r)   r4   r   r   r   rG   |   s   c                 C   rT   )z8
        The module's original source file name
        )r   r	   r   LLVMPY_GetModuleSourceFileNamer<   r   r   r   source_file   rV   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.   rQ   r   r   r   data_layout      $zModuleRef.data_layoutc                 C      t j| t|d d S Nutf8)r	   r   LLVMPY_SetDataLayoutr   encoder)   strrepr   r   r   r^      
   c                 C   rZ   )zK
        This module's target "triple" specification, as a string.
        Fr[   N)r	   r   r   LLVMPY_GetTargetr.   rQ   r   r   r   triple   r_   zModuleRef.triplec                 C   r`   ra   )r	   r   LLVMPY_SetTargetr   rd   re   r   r   r   ri      rg   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)
        rA   )r	   r   LLVMPY_ModuleGlobalsIter_GlobalsIteratorrE   r)   itr   r   r   global_variables   s   
zModuleRef.global_variablesc                 C   ro   )z
        Return an iterator over this module's functions.
        The iterator will yield a ValueRef for each function.
        rA   )r	   r   LLVMPY_ModuleFunctionsIter_FunctionsIteratorrE   rr   r   r   r   	functions      zModuleRef.functionsc                 C   ro   )z|
        Return an iterator over the struct types defined in
        the module. The iterator will yield a TypeRef.
        rA   )r	   r   LLVMPY_ModuleTypesIter_TypesIteratorrE   rr   r   r   r   struct_types   rx   zModuleRef.struct_typesc                 C   s   t tj| | jS r%   )r   r	   r   LLVMPY_CloneModuler(   r<   r   r   r   rk      s   zModuleRef.clone)F)__name__
__module____qualname____doc__r'   r0   r8   r=   rI   rM   rO   rS   propertyrG   setterrY   r^   ri   rn   rt   rw   r{   rk   __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)   r6   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   r<   r   r   r   __iter__   s   z_Iterator.__iter__)r}   r~   r   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 )rq   rK   c                 C   r9   r%   )r:   LLVMPY_DisposeGlobalsIterr<   r   r   r   r=      r>   z_GlobalsIterator._disposec                 C      t j| S r%   )r	   r   LLVMPY_GlobalsIterNextr<   r   r   r   r         z_GlobalsIterator._nextNr}   r~   r   r   r=   r   r   r   r   r   rq          rq   c                   @   r   )rv   r@   c                 C   r9   r%   )r:   LLVMPY_DisposeFunctionsIterr<   r   r   r   r=      r>   z_FunctionsIterator._disposec                 C   r   r%   )r	   r   LLVMPY_FunctionsIterNextr<   r   r   r   r      r   z_FunctionsIterator._nextNr   r   r   r   r   rv      r   rv   c                   @   s,   e Zd ZdZdd Zdd Zdd ZeZdS )	rz   typec                 C   r9   r%   )r:   LLVMPY_DisposeTypesIterr<   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_TypesIterNextr<   r   r   r   r     r   z_TypesIterator._nextN)r}   r~   r   r   r=   r   r   r   r   r   r   r   rz      s    rz   r%   )@ctypesr   r   r   r   r   r   r   llvmlite.bindingr	   llvmlite.binding.linkerr
   llvmlite.binding.commonr   r   llvmlite.binding.valuer   r   llvmlite.binding.contextr   r   r$   r   r   r   rq   rv   rz   LLVMContextRefr   r   argtypesLLVMModuleRefrestyper    r;   r-   r2   rC   LLVMValueRefrP   r]   rc   rh   rj   rL   rN   LLVMTypeRefrp   LLVMGlobalsIteratorr   r   ru   LLVMFunctionsIteratorry   LLVMTypesIteratorr   r   r   r   r|   rU   rW   rX   r   r   r   r   <module>   s   $ 

 %







