
    d)                        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 Zd Z G d dej                  Z G d dej                  Zej        ej         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
e          Z* ede ee*                    Z+ ede ee*                    Z, e+ej-                  Z. e,ej/                  Z0e+e,egej        j1        _        ej2        ej        j1        _        ej2        gej        j3        _        ej        ej2        gej        j4        _        eej        j5        _        eegej        j5        _        dS )    )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                    t          j                    5 }t           j                            | ||          }|st	          t          |                    	 ddd           n# 1 swxY w Y   d|_        t          ||           S )zZ
    Create a MCJIT ExecutionEngine from the given *module* and
    *target_machine*.
    NT)module)r   OutputStringlibLLVMPY_CreateMCJITCompilerRuntimeErrorstr_ownedExecutionEngine)r   target_machineouterrengines       @lib/python3.11/site-packages/llvmlite/binding/executionengine.pycreate_mcjit_compilerr      s    
 
			 ,v33NF, , 	,s6{{+++	,, , , , , , , , , , , , , , , !N6&1111s   A A!!A%(A%c                  n    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   zcannot 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)errnos    r   check_jit_executionr$      sA    
 G6688EzzeG  	 z    c                       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ed             Zd Zd Zd ZddZd Zd Zd ZdS )r   zAn 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                     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   s      r   r,   zExecutionEngine.__init__0   s?     VHtS)))))r%   c                 h    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-   names     r   get_function_addressz$ExecutionEngine.get_function_address9   s(     w00t{{77K7KLLLr%   c                 h    t           j                            | |                    d                    S )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.
        r0   )r   r   LLVMPY_GetGlobalValueAddressr2   r3   s     r   get_global_value_addressz(ExecutionEngine.get_global_value_addressA   s(     w33D$++g:N:NOOOr%   c                 H    t           j                            | ||           d S N)r   r   LLVMPY_AddGlobalMapping)r-   gvaddrs      r   add_global_mappingz"ExecutionEngine.add_global_mappingI   s"    ''b$77777r%   c                     || 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   s     r   
add_modulezExecutionEngine.add_moduleM   s[     T]""@AAA  v...&!!!!!r%   c                 D    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-   s    r   finalize_objectzExecutionEngine.finalize_objectW   s     
 	%%d+++++r%   c                 D    t           j                            |            dS )zW
        Run static constructors which initialize module-level static objects.
        N)r   r   LLVMPY_RunStaticConstructorsrF   s    r   run_static_constructorsz'ExecutionEngine.run_static_constructors^   s      	,,T22222r%   c                 D    t           j                            |            dS )zh
        Run static destructors which perform module-level cleanup of static
        resources.
        N)r   r   LLVMPY_RunStaticDestructorsrF   s    r   run_static_destructorsz&ExecutionEngine.run_static_destructorsd   s     
 	++D11111r%   c                    t          j                    5 }t           j                            | ||          rt	          t          |                    	 ddd           n# 1 swxY w Y   | j                            |           d|_        dS )z1
        Ownership of module is returned
        NF)	r   r   r   LLVMPY_RemoveModuler   r   r)   remover   )r-   r   r   s      r   remove_modulezExecutionEngine.remove_modulek   s      	06w**4@@ 0"3v;;///0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	V$$$s   >AA#&A#c                     | j         | j         S t          j                            |           }t	          j        |          | _         d| j         _        | j         S )z;
        The TargetData for this execution engine.
        NT)r*   r   r   #LLVMPY_GetExecutionEngineTargetDatar   
TargetDatar   )r-   r.   s     r   target_datazExecutionEngine.target_datau   sJ    
 88Og99$??%c**xr%   c                 D    t           j                            |           }|S )z
        Enable JIT events for profiling of generated code.
        Return value indicates whether connection to profiling tool
        was successful.
        )r   r   LLVMPY_EnableJITEvents)r-   rets     r   enable_jit_eventsz!ExecutionEngine.enable_jit_events   s     g,,T22
r%   c                     t          |t                    j        }| j        D ])}t          |j        t                    j        |k    r|c S *dS )zH
        Find the ModuleRef corresponding to the given pointer.
        N)r   r   valuer)   _ptr)r-   
module_ptrr.   r   s       r   _find_module_ptrz ExecutionEngine._find_module_ptr   sT     :x((.m 	 	FFK**0C77 8tr%   c                     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   ObjectFileRef	from_pathr   r   LLVMPY_MCJITAddObjectFile)r-   obj_files     r   add_object_filezExecutionEngine.add_object_file   sK    
 h$$ 	E"0::8DDH))$99999r%   c                     || _         || _        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-   notify_funcgetbuffer_funcs      r   set_object_cachez ExecutionEngine.set_object_cache   sG    
 %0!'5$,T22 	%%dD,>?????r%   c                     | j         dS |j        j        }|j        j        }|j        j        }t          ||          }|                     |          }|t          d|          |                      ||           dS )z(
        Low-level notify hook.
        N3object compilation notification for unknown module )rg   contentsr]   buf_ptrbuf_lenr   r^   r   )r-   datar]   rr   rs   bufr   s          r   _raw_object_cache_notifyz(ExecutionEngine._raw_object_cache_notify   s     $,F]-
-'-'))&&z22> ,:D* G H H H!!&#.....r%   c                 X   | j         dS |j        j        }|                     |          }|t	          d|          |                      |          }|Tt
          j                            |t          |                    |d         _	        t          |          |d         _
        dS dS )z+
        Low-level getbuffer hook.
        Nrp   r   )rh   rq   r]   r^   r   r   r   LLVMPY_CreateByteStringlenrr   rs   )r-   rt   r]   r   ru   s        r   _raw_object_cache_getbufferz+ExecutionEngine._raw_object_cache_getbuffer   s     '/F]-
&&z22> ,:D* G H H H **622?!g==c3s88LLDGO!#hhDGOOO ?r%   c                     | j         D ]}|                                 | j        | j                                         | j                                          d | _        | j                            |            d S r:   )r)   detachr*   clearrj   _capiLLVMPY_DisposeExecutionEngine)r-   mods     r   _disposezExecutionEngine._dispose   st    = 	 	CJJLLLL8HOO!
0066666r%   )NN)__name__
__module____qualname____doc__rj   r,   r5   r8   r>   rC   rG   rJ   rM   rQ   propertyrU   rY   r^   re   rn   rv   rz   r    r%   r   r   r   )   s?         M* * *M M MP P P8 8 8" " ", , ,3 3 32 2 2   	 	 X	    : : :@ @ @ @/ / /$' ' '(7 7 7 7 7r%   r   c                       e Zd ZdZd Zd ZdS )ri   zN
    Internal: an ObjectCache instance for use within an ExecutionEngine.
    c                     t           j                            t          t          |          }t           j                            | |           d S r:   )r   r   LLVMPY_CreateObjectCache_notify_c_hook_getbuffer_c_hookr+   r,   )r-   objr.   s      r   r,   z_ObjectCacheRef.__init__   sA    g..~/@/24 4 	tS)))))r%   c                 :    | j                             |            d S r:   )r~   LLVMPY_DisposeObjectCacherF   s    r   r   z_ObjectCacheRef._dispose   s    
,,T22222r%   N)r   r   r   r   r,   r   r   r%   r   ri   ri      s<         * * *3 3 3 3 3r%   ri   c                   .    e Zd Zdej        fdefdefgZdS )_ObjectCacheDatar]   rr   rs   N)r   r   r   r   LLVMModuleRefr   r	   _fields_r   r%   r   r   r   "  s0        	s()	H	HHHHr%   r   N)6ctypesr   r   r   r   r   r   r	   r
   r   r   r   r   llvmlite.bindingr   r   r   r   LLVMPY_LinkInMCJITr   r$   r+   r   ri   r   LLVMTargetMachineRefr   argtypesLLVMExecutionEngineRefrestyperO   rA   LLVMValueRefr;   rE   rS   LLVMTargetDataRefr!   r1   r7   LLVMObjectFileRefrc   r   _ObjectCacheNotifyFunc_ObjectCacheGetBufferFuncrv   r   rz   r   r   LLVMObjectCacheRefr   rk   rx   r   r%   r   <module>r      s  * * * * * * * * * * * * * * * * * * * * * * * * * * * * 7 6 6 6 6 6 6 6 6 6   2 2 2  p7 p7 p7 p7 p7cm p7 p7 p7f3 3 3 3 3cm 3 3 3( GH/ " +
 .1-G " * GH(  $
 '-  # %  !
 -0,F,/,<,4,6  ( +.*D)E  & 8 + 4 7:6K + 368 * 35: * 2 . ! * -5 ! ) 1 $ - 08 $ , . ! *    y    #4#*7+;#<#<> > %IdI&-g.>&?&?A A  (',. .--/1 1  .D-F-6-8   ) ,/+A   (.1.D-E ! **-*D*-*@*B  & +3  ',4h+?  ( ( (r%   