
    J/Ph+                        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Zd Z G d dej                  Z G 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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j3        ej        j2        _        ej3        gej        j4        _        ej        ej3        g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                 8   |t          j                    dv }t          j                    5 }t          j                            | |||          }|st          t          |                    	 ddd           n# 1 swxY w Y   d|_        t          ||           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)arm64aarch64T)module)
platformmachiner   OutputStringlibLLVMPY_CreateMCJITCompilerRuntimeErrorstr_ownedExecutionEngine)r   target_machineuse_lmmouterrengines        `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/llvmlite/binding/executionengine.pycreate_mcjit_compilerr$      s     "$$(<<				 ,v33NGV5 5 	,s6{{+++	,, , , , , , , , , , , , , , , !N6&1111s   AA99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#   r1   zExecutionEngine.__init__8   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r2   names     r#   get_function_addressz$ExecutionEngine.get_function_addressA   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.
        r5   )r   r   LLVMPY_GetGlobalValueAddressr7   r8   s     r#   get_global_value_addressz(ExecutionEngine.get_global_value_addressI   s(     w33D$++g:N:NOOOr*   c                 H    t           j                            | ||           d S N)r   r   LLVMPY_AddGlobalMapping)r2   gvaddrs      r#   add_global_mappingz"ExecutionEngine.add_global_mappingQ   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)r2   r   s     r#   
add_modulezExecutionEngine.add_moduleT   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r2   s    r#   finalize_objectzExecutionEngine.finalize_object^   s     
 	%%d+++++r*   c                 D    t           j                            |            dS )zW
        Run static constructors which initialize module-level static objects.
        N)r   r   LLVMPY_RunStaticConstructorsrK   s    r#   run_static_constructorsz'ExecutionEngine.run_static_constructorse   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_RunStaticDestructorsrK   s    r#   run_static_destructorsz&ExecutionEngine.run_static_destructorsk   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   )r2   r   r!   s      r#   remove_modulezExecutionEngine.remove_moduler   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   )r2   r3   s     r#   target_datazExecutionEngine.target_data|   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)r2   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)r2   
module_ptrr3   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)r2   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)r2   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 )rl   contentsrb   buf_ptrbuf_lenr   rc   r   )r2   datarb   rw   rx   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.
        Nru   r   )rm   rv   rb   rc   r   r   r   LLVMPY_CreateByteStringlenrw   rx   )r2   ry   rb   r   rz   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/   clearro   _capiLLVMPY_DisposeExecutionEngine)r2   mods     r#   _disposezExecutionEngine._dispose   st    = 	 	CJJLLLL8HOO!
0066666r*   )NN)__name__
__module____qualname____doc__ro   r1   r:   r=   rC   rH   rL   rO   rR   rV   propertyrZ   r^   rc   rj   rs   r{   r   r    r*   r#   r   r   1   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 )rn   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_hookr0   r1   )r2   objr3   s      r#   r1   z_ObjectCacheRef.__init__   sA    g..~/@/24 4 	tS)))))r*   c                 :    | j                             |            d S r?   )r   LLVMPY_DisposeObjectCacherK   s    r#   r   z_ObjectCacheRef._dispose   s    
,,T22222r*   N)r   r   r   r   r1   r   r   r*   r#   rn   rn      s<         * * *3 3 3 3 3r*   rn   c                   .    e Zd Zdej        fdefdefgZdS )_ObjectCacheDatarb   rw   rx   N)r   r   r   r   LLVMModuleRefr   r	   _fields_r   r*   r#   r   r   *  s0        	s()	H	HHHHr*   r   r?   )7r   ctypesr   r   r   r   r   r   r	   r
   r   r   r   r   llvmlite.bindingr   r   r   r   LLVMPY_LinkInMCJITr$   r)   r0   r   rn   r   LLVMTargetMachineRefr   argtypesLLVMExecutionEngineRefrestyperT   rF   LLVMValueRefr@   rJ   rX   LLVMTargetDataRefr&   r6   r<   LLVMObjectFileRefrh   r   _ObjectCacheNotifyFunc_ObjectCacheGetBufferFuncr{   r   r   r   r   LLVMObjectCacheRefr   rp   r}   r   r*   r#   <module>r      s   * * * * * * * * * * * * * * * * * * * * * * * * * * * * 7 6 6 6 6 6 6 6 6 6   2 2 2 2,  o7 o7 o7 o7 o7cm o7 o7 o7d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*   