o
    Hôj+  ã                   @   s  d dl Z 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mZ d dlmZmZmZ ejj ddd„Zdd„ ZG dd	„ d	ejƒZG d
d„ dejƒZejejeeeƒgejj_ejejj_ejejeeƒgejj_eejj_ejejgejj _ejej!egejj"_ejgejj#_ejgejj$_ej%ejj$_g ejj&_eejj&_ejegejj'_eejj'_ejegejj(_eejj(_ejej)gejj*_G dd„ deƒZ+e	deee+ƒƒZ,e	deee+ƒƒZ-e,ej.ƒZ/e-ej0ƒZ1e,e-egejj2_ej3ejj2_ej3gejj4_ejej3gejj5_eejj6_eegejj6_dS )é    N)ÚPOINTERÚc_char_pÚc_boolÚc_void_pÚc_intÚc_uint64Úc_size_tÚ	CFUNCTYPEÚ	string_atÚcastÚ	py_objectÚ	Structure)ÚffiÚtargetsÚobject_filec                 C   st   |du rt  ¡  ¡ dv }t ¡ �}tj | |||¡}|s"tt|ƒƒ‚W d  ƒ n1 s,w   Y  d|_	t
|| d�S )a  
    Create a MCJIT ExecutionEngine from the given *module* and
    *target_machine*.

    *lmm* controls whether the llvmlite memory manager is used. If not supplied,
    the default choice for the platform will be used (``True`` on 64-bit ARM
    systems, ``False`` otherwise).
    N)Zarm64Zaarch64T)Úmodule)ÚplatformÚmachineÚlowerr   ÚOutputStringÚlibÚLLVMPY_CreateMCJITCompilerÚRuntimeErrorÚstrÚ_ownedÚExecutionEngine)r   Ztarget_machineZuse_lmmÚouterrÚengine© r   úq/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/llvmlite/binding/executionengine.pyÚcreate_mcjit_compiler   s   	
ÿÿýr    c                  C   s    t j ¡ } | dkrt| dƒ‚dS )zp
    Check the system allows execution of in-memory JITted functions.
    An exception is raised otherwise.
    r   z‚cannot allocate executable memory. This may be due to security restrictions on your system, such as SELinux or similar mechanisms.N)r   r   Ú"LLVMPY_TryAllocateExecutableMemoryÚOSError)Úerrnor   r   r   Úcheck_jit_execution#   s   
ÿÿr$   c                   @   s¢   e Zd ZdZdZdd„ Z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dd„ Zdd„ Zdd„ Zd%dd„Zdd „ Zd!d"„ Zd#d$„ ZdS )&r   z­An ExecutionEngine owns all Modules associated with it.
    Deleting the engine will remove all associated modules.
    It is an error to delete the associated modules.
    Nc                 C   s*   t |gƒ| _d| _d|_tj | |¡ dS )z;
        Module ownership is transferred to the EE
        NT)ÚsetÚ_modulesÚ_tdr   r   Ú	ObjectRefÚ__init__)ÚselfÚptrr   r   r   r   r)   8   s   zExecutionEngine.__init__c                 C   ó   t j | | d¡¡S )z›
        Return the address of the function named *name* as an integer.

        It's a fatal error in LLVM if the symbol of *name* doesn't exist.
        Úascii)r   r   ÚLLVMPY_GetFunctionAddressÚencode©r*   Únamer   r   r   Úget_function_addressA   ó   z$ExecutionEngine.get_function_addressc                 C   r,   )zŸ
        Return the address of the global value named *name* as an integer.

        It's a fatal error in LLVM if the symbol of *name* doesn't exist.
        r-   )r   r   ÚLLVMPY_GetGlobalValueAddressr/   r0   r   r   r   Úget_global_value_addressI   r3   z(ExecutionEngine.get_global_value_addressc                 C   s   t j | ||¡ d S ©N)r   r   ÚLLVMPY_AddGlobalMapping)r*   ÚgvÚaddrr   r   r   Úadd_global_mappingQ   s   z"ExecutionEngine.add_global_mappingc                 C   s6   || j v r	tdƒ‚tj | |¡ d|_| j  |¡ dS )zL
        Ownership of module is transferred to the execution engine
        z#module already added to this engineTN)r&   ÚKeyErrorr   r   ÚLLVMPY_AddModuler   Úadd)r*   r   r   r   r   Ú
add_moduleT   s
   
zExecutionEngine.add_modulec                 C   ó   t j | ¡ dS )z}
        Make sure all modules owned by the execution engine are fully processed
        and "usable" for execution.
        N)r   r   ÚLLVMPY_FinalizeObject©r*   r   r   r   Úfinalize_object^   ó   zExecutionEngine.finalize_objectc                 C   r?   )zW
        Run static constructors which initialize module-level static objects.
        N)r   r   ZLLVMPY_RunStaticConstructorsrA   r   r   r   Úrun_static_constructorse   s   z'ExecutionEngine.run_static_constructorsc                 C   r?   )zh
        Run static destructors which perform module-level cleanup of static
        resources.
        N)r   r   ZLLVMPY_RunStaticDestructorsrA   r   r   r   Úrun_static_destructorsk   rC   z&ExecutionEngine.run_static_destructorsc                 C   sZ   t  ¡ �}t j | ||¡rtt|ƒƒ‚W d  ƒ n1 sw   Y  | j |¡ d|_dS )z1
        Ownership of module is returned
        NF)	r   r   r   ÚLLVMPY_RemoveModuler   r   r&   Úremover   )r*   r   r   r   r   r   Úremove_moduler   s   
ÿÿ
zExecutionEngine.remove_modulec                 C   s6   | j dur| j S tj | ¡}t |¡| _ d| j _| j S )z;
        The TargetData for this execution engine.
        NT)r'   r   r   Ú#LLVMPY_GetExecutionEngineTargetDatar   Z
TargetDatar   )r*   r+   r   r   r   Útarget_data|   s   
zExecutionEngine.target_datac                 C   s   t j | ¡}|S )z 
        Enable JIT events for profiling of generated code.
        Return value indicates whether connection to profiling tool
        was successful.
        )r   r   ZLLVMPY_EnableJITEvents)r*   Úretr   r   r   Úenable_jit_eventsˆ   s   z!ExecutionEngine.enable_jit_eventsc                 C   s6   t |tƒj}| jD ]}t |jtƒj|kr|  S q	dS )zH
        Find the ModuleRef corresponding to the given pointer.
        N)r   r   Úvaluer&   Ú_ptr)r*   Ú
module_ptrr+   r   r   r   r   Ú_find_module_ptr‘   s   
ÿz ExecutionEngine._find_module_ptrc                 C   s(   t |tƒrtj |¡}tj | |¡ dS )z�
        Add object file to the jit. object_file can be instance of
        :class:ObjectFile or a string representing file system path
        N)Ú
isinstancer   r   ZObjectFileRefÚ	from_pathr   r   ÚLLVMPY_MCJITAddObjectFile)r*   Zobj_filer   r   r   Úadd_object_file›   s   
zExecutionEngine.add_object_filec                 C   s*   || _ || _t| ƒ| _tj | | j¡ dS )z~
        Set the object cache "notifyObjectCompiled" and "getBuffer"
        callbacks to the given Python functions.
        N)Ú_object_cache_notifyÚ_object_cache_getbufferÚ_ObjectCacheRefÚ_object_cacher   r   ÚLLVMPY_SetObjectCache)r*   Znotify_funcZgetbuffer_funcr   r   r   Úset_object_cache¥   s   
z ExecutionEngine.set_object_cachec                 C   s`   | j du rdS |jj}|jj}|jj}t||ƒ}|  |¡}|du r(td|f ƒ‚|   ||¡ dS )z(
        Low-level notify hook.
        Nú5object compilation notification for unknown module %s)rU   ÚcontentsrO   Úbuf_ptrÚbuf_lenr
   rP   r   )r*   ÚdatarO   r]   r^   Úbufr   r   r   r   Ú_raw_object_cache_notify²   s   


ÿz(ExecutionEngine._raw_object_cache_notifyc                 C   sv   | j du rdS |jj}|  |¡}|du rtd|f ƒ‚|   |¡}|dur9tj |t|ƒ¡|d _	t|ƒ|d _
dS dS )z+
        Low-level getbuffer hook.
        Nr[   r   )rV   r\   rO   rP   r   r   r   ÚLLVMPY_CreateByteStringÚlenr]   r^   )r*   r_   rO   r   r`   r   r   r   Ú_raw_object_cache_getbufferÄ   s   

ÿ
ýz+ExecutionEngine._raw_object_cache_getbufferc                 C   sH   | j D ]}| ¡  q| jd ur| j ¡  | j  ¡  d | _| j | ¡ d S r6   )r&   Údetachr'   ÚclearrX   Ú_capiZLLVMPY_DisposeExecutionEngine)r*   Úmodr   r   r   Ú_disposeØ   s   




zExecutionEngine._dispose)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rX   r)   r2   r5   r:   r>   rB   rD   rE   rH   ÚpropertyrJ   rL   rP   rT   rZ   ra   rd   ri   r   r   r   r   r   1   s*    	


	


r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )rW   zN
    Internal: an ObjectCache instance for use within an ExecutionEngine.
    c                 C   s"   t j tt|¡}t j | |¡ d S r6   )r   r   ÚLLVMPY_CreateObjectCacheÚ_notify_c_hookÚ_getbuffer_c_hookr(   r)   )r*   Úobjr+   r   r   r   r)   è   s
   þz_ObjectCacheRef.__init__c                 C   s   | j  | ¡ d S r6   )rg   ÚLLVMPY_DisposeObjectCacherA   r   r   r   ri   î   s   z_ObjectCacheRef._disposeN)rj   rk   rl   rm   r)   ri   r   r   r   r   rW   ã   s    rW   c                   @   s$   e Zd ZdejfdefdefgZdS )Ú_ObjectCacheDatarO   r]   r^   N)rj   rk   rl   r   ÚLLVMModuleRefr   r   Ú_fields_r   r   r   r   rt   *  s
    ýrt   r6   )7r   Úctypesr   r   r   r   r   r   r   r	   r
   r   r   r   Úllvmlite.bindingr   r   r   r   ZLLVMPY_LinkInMCJITr    r$   r(   r   rW   ru   ÚLLVMTargetMachineRefr   ÚargtypesÚLLVMExecutionEngineRefÚrestyperF   r<   ÚLLVMValueRefr7   r@   rI   ÚLLVMTargetDataRefr!   r.   r4   ÚLLVMObjectFileRefrS   rt   Z_ObjectCacheNotifyFuncZ_ObjectCacheGetBufferFuncra   rp   rd   rq   ro   ÚLLVMObjectCacheRefrs   rY   rb   r   r   r   r   Ú<module>   sˆ    8
 3
ü
ý

þ
þ
ÿ


þ

þ

þÿÿÿÿ
þ
ÿ
