
    sKg+                        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j2                  ej4                  e ee      gej$                  j6                  _        ej:                  ej$                  j6                  _        ej:                  ej2                   ee      gej$                  j>                  _        eej$                  j>                  _        ej:                  ej2                  gej$                  j@                  _        ej:                  ejB                  egej$                  jD                  _        ej:                  gej$                  jF                  _        ej:                  gej$                  jH                  _        ejJ                  ej$                  jH                  _        g ej$                  jL                  _        eej$                  jL                  _        ej:                  egej$                  jN                  _        eej$                  jN                  _        ej:                  egej$                  jP                  _        eej$                  jP                  _        ej:                  ejR                  gej$                  jT                  _         G d
 de      Z+ e	de ee+            Z, e	de ee+            Z- e,ej\                        Z/ e-ej`                        Z1e,e-egej$                  jd                  _        ejf                  ej$                  jd                  _        ejf                  gej$                  jh                  _        ej:                  ejf                  gej$                  jj                  _        eej$                  jl                  _        eegej$                  jl                  _        y)    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                    |t        j                         dv }t        j                         5 }t        j                  j                  | |||      }|st        t        |            	 ddd       d|_        t        |       S # 1 sw Y   xY w)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        d/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/llvmlite/binding/executionengine.pycreate_mcjit_compilerr$      s     ""$(<<				v33NGV5s6{++  
 !N6&11 
	s   9BBc                  b    t         j                  j                         } | dk7  rt        | d      y)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)   #   s7    
 GG668EzeG 	     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y)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
                  j                  | |       y)z;
        Module ownership is transferred to the EE
        NT)set_modules_tdr   r   	ObjectRef__init__)selfptrr   s      r#   r1   zExecutionEngine.__init__8   s3     VHtS)r*   c                 `    t         j                  j                  | |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$     ww00t{{77KLLr*   c                 `    t         j                  j                  | |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$     ww33D$++g:NOOr*   c                 F    t         j                  j                  | ||       y N)r   r   LLVMPY_AddGlobalMapping)r2   gvaddrs      r#   add_global_mappingz"ExecutionEngine.add_global_mappingQ   s    ''b$7r*   c                     || j                   v rt        d      t        j                  j	                  | |       d|_        | j                   j                  |       y)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   sI     T]]"@AA  v.&!r*   c                 B    t         j                  j                  |        y)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                 B    t         j                  j                  |        y)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2r*   c                 B    t         j                  j                  |        y)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1r*   c                    t        j                         5 }t         j                  j                  | ||      rt	        t        |            	 ddd       | j                  j                  |       d|_        y# 1 sw Y   ,xY w)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   sf     6ww**4@"3v;// A   	V$	  s   6A77B c                     | j                   | j                   S t        j                  j                  |       }t	        j
                  |      | _         d| j                   _        | j                   S )z;
        The TargetData for this execution engine.
        T)r/   r   r   #LLVMPY_GetExecutionEngineTargetDatar   
TargetDatar   )r2   r3   s     r#   target_datazExecutionEngine.target_data|   sQ    
 8888Ogg99$?%%c*xxr*   c                 D    t         j                  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     gg,,T2
r*   c                     t        |t              j                  }| j                  D ]-  }t        |j                  t              j                  |k(  s+|c S  y)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   sG     :x(..mmFFKK*00C7 $ r*   c                     t        |t              rt        j                  j	                  |      }t
        j                  j                  | |       y)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   s8    
 h$"00::8DH))$9r*   c                     || _         || _        t        |       | _        t        j
                  j                  | | j                         y)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   s=    
 %0!'5$,T2 	%%dD,>,>?r*   c                     | j                   y|j                  j                  }|j                  j                  }|j                  j                  }t        ||      }| j                  |      }|t        d|      | j                  ||       y)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     $$,]]--
--''--'')&&z2> :D G H H!!&#.r*   c                 <   | j                   y|j                  j                  }| j                  |      }|t	        d|      | j                  |      }|Et
        j                  j                  |t        |            |d   _	        t        |      |d   _
        yy)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     ''/]]--
&&z2> :D G H H **62?!gg==c3s8LDGO!#hDGO r*   c                 
   | j                   D ]  }|j                           | j                  | j                  j                          | j                   j                          d | _        | j
                  j                  |        y r?   )r.   detachr/   clearro   _capiLLVMPY_DisposeExecutionEngine)r2   mods     r#   _disposezExecutionEngine._dispose   s[    ==CJJL !88HHOO!

00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   su     M*MP8",32 	 	:@/$'(7r*   r   c                       e Zd ZdZd Zd Zy)rn   zN
    Internal: an ObjectCache instance for use within an ExecutionEngine.
    c                     t         j                  j                  t        t        |      }t         j
                  j                  | |       y r?   )r   r   LLVMPY_CreateObjectCache_notify_c_hook_getbuffer_c_hookr0   r1   )r2   objr3   s      r#   r1   z_ObjectCacheRef.__init__   s4    gg..~/@/24 	tS)r*   c                 :    | j                   j                  |        y r?   )r   LLVMPY_DisposeObjectCacherK   s    r#   r   z_ObjectCacheRef._dispose   s    

,,T2r*   N)r   r   r   r   r1   r   r   r*   r#   rn   rn      s    *3r*   rn   c                   6    e Zd Zdej                  fdefdefgZy)_ObjectCacheDatarb   rw   rx   N)r   r   r   r   LLVMModuleRefr   r	   _fields_r   r*   r#   r   r   *  s'    	s(()	H	HHr*   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      sa   * * * * 7 6   2,o7cmm o7d3cmm 3( 
H	/ " " + .1-G-G " " * H(   $
 '-   # %   !
 -0,F,F,/,<,<,4,6   ( +.*D*D)E   & 8 + + 4 7:6K6K + + 368 * * 35: * * 2 . ! ! * -5 ! ! ) 1 $ $ - 08 $ $ , . ! ! *y  #4#*+;#<> %dI&-.>&?A  (,,.-//1  .D-F-6-8     ) ,/+A+A     (.1.D.D-E ! ! **-*D*D*-*@*@*B   & +3   ',4h+?   (r*   