σ
C]c           @@ s)  d  d l  m Z m 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 Z d d l m Z m Z m Z e j j d   Z d   Z d e j f d	     YZ d
 e j f d     YZ 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- _ d e f d     YZ. e d e e e.   Z0 e d e e e.   Z1 e0 e j2  Z3 e1 e j4  Z5 e0 e1 e g e j j6 _ e j7 e j j6 _! e j7 g e j j8 _ e j  e j7 g e j j9 _ e e j j: _! e e
 g e j j: _ d S(   i    (   t   print_functiont   absolute_import(   t   POINTERt   c_char_pt   c_boolt   c_void_pt   c_intt   c_uint64t   c_size_tt	   CFUNCTYPEt	   string_att   castt	   py_objectt	   StructureNi   (   t   ffit   targetst   object_filec         C@ sa   t  j   : } t  j j |  | |  } | sB t t |    n  Wd QXt | _ t | d |  S(   sZ   
    Create a MCJIT ExecutionEngine from the given *module* and
    *target_machine*.
    Nt   module(	   R   t   OutputStringt   libt   LLVMPY_CreateMCJITCompilert   RuntimeErrort   strt   Truet   _ownedt   ExecutionEngine(   R   t   target_machinet   outerrt   engine(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   create_mcjit_compiler   s    		c          C@ s1   t  j j   }  |  d k r- t |  d   n  d S(   sp   
    Check the system allows execution of in-memory JITted functions.
    An exception is raised otherwise.
    i    s   cannot allocate executable memory. This may be due to security restrictions on your system, such as SELinux or similar mechanisms.N(   R   R   t"   LLVMPY_TryAllocateExecutableMemoryt   OSError(   t   errno(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   check_jit_execution   s    R   c           B@ sΉ   e  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 d  Z d   Z d   Z d   Z RS(   s­   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.
    c         C@ s;   t  | g  |  _ d |  _ t | _ t j j |  |  d S(   s;   
        Module ownership is transferred to the EE
        N(	   t   sett   _modulest   Nonet   _tdR   R   R   t	   ObjectReft   __init__(   t   selft   ptrR   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyR'   3   s    		c         C@ s   t  j j |  | j d   S(   s   
        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.
        t   ascii(   R   R   t   LLVMPY_GetFunctionAddresst   encode(   R(   t   name(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   get_function_address<   s    c         C@ s   t  j j |  | j d   S(   s   
        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   t   LLVMPY_GetGlobalValueAddressR,   (   R(   R-   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   get_global_value_addressD   s    c         C@ s   t  j j |  | |  d  S(   N(   R   R   t   LLVMPY_AddGlobalMapping(   R(   t   gvt   addr(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   add_global_mappingL   s    c         C@ sN   | |  j  k r t d   n  t j j |  |  t | _ |  j  j |  d S(   sL   
        Ownership of module is transferred to the execution engine
        s#   module already added to this engineN(   R#   t   KeyErrorR   R   t   LLVMPY_AddModuleR   R   t   add(   R(   R   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt
   add_moduleP   s
    	c         C@ s   t  j j |   d S(   s}   
        Make sure all modules owned by the execution engine are fully processed
        and "usable" for execution.
        N(   R   R   t   LLVMPY_FinalizeObject(   R(   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   finalize_objectZ   s    c         C@ s   t  j j |   d S(   sE   Run static constructors which initialize module-level static objects.N(   R   R   t   LLVMPY_RunStaticConstructors(   R(   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   run_static_constructorsa   s    c         C@ s   t  j j |   d S(   sN   Run static destructors which perform module-level cleanup of static resources.N(   R   R   t   LLVMPY_RunStaticDestructors(   R(   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   run_static_destructorse   s    c         C@ s_   t  j   4 } t  j j |  | |  r< t t |    n  Wd QX|  j j |  t | _	 d S(   s1   
        Ownership of module is returned
        N(
   R   R   R   t   LLVMPY_RemoveModuleR   R   R#   t   removet   FalseR   (   R(   R   R   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   remove_modulei   s
    c         C@ sM   |  j  d k	 r |  j  St j j |   } t j |  |  _  t |  j  _ |  j  S(   s;   
        The TargetData for this execution engine.
        N(	   R%   R$   R   R   t#   LLVMPY_GetExecutionEngineTargetDataR   t
   TargetDataR   R   (   R(   R)   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   target_datas   s    c         C@ s   t  j j |   } | S(   s    
        Enable JIT events for profiling of generated code.
        Return value indicates whether connection to profiling tool
        was successful.
        (   R   R   t   LLVMPY_EnableJITEvents(   R(   t   ret(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   enable_jit_events   s    c         C@ sI   t  | t  j } x0 |  j D]% } t  | j t  j | k r | Sq Wd S(   sH   
        Find the ModuleRef corresponding to the given pointer.
        N(   R   R   t   valueR#   t   _ptrR$   (   R(   t
   module_ptrR)   R   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   _find_module_ptr   s
    c         C@ s;   t  | t  r$ t j j |  } n  t j j |  |  d S(   s   
        Add object file to the jit. object_file can be instance of
        :class:ObjectFile or a string representing file system path
        N(   t
   isinstanceR   R   t   ObjectFileReft	   from_pathR   R   t   LLVMPY_MCJITAddObjectFile(   R(   t   obj_file(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   add_object_file   s    c         C@ s;   | |  _  | |  _ t |   |  _ t j j |  |  j  d S(   s~   
        Set the object cache "notifyObjectCompiled" and "getBuffer"
        callbacks to the given Python functions.
        N(   t   _object_cache_notifyt   _object_cache_getbuffert   _ObjectCacheReft   _object_cacheR   R   t   LLVMPY_SetObjectCache(   R(   t   notify_funct   getbuffer_func(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   set_object_cache   s    		c         C@ s   |  j  d k r d S| j j } | j j } | j j } t | |  } |  j |  } | d k rw t d | f   n  |  j  | |  d S(   s(   
        Low-level notify hook.
        Ns5   object compilation notification for unknown module %s(	   RS   R$   t   contentsRK   t   buf_ptrt   buf_lenR
   RL   R   (   R(   t   dataRK   R\   R]   t   bufR   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   _raw_object_cache_notifyͺ   s    c         C@ s§   |  j  d k r d S| j j } |  j |  } | d k rP t d | f   n  |  j  |  } | d k	 r£ t j j | t	 |   | d _
 t	 |  | d _ n  d S(   s+   
        Low-level getbuffer hook.
        Ns5   object compilation notification for unknown module %si    (   RT   R$   R[   RK   RL   R   R   R   t   LLVMPY_CreateByteStringt   lenR\   R]   (   R(   R^   RK   R   R_   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   _raw_object_cache_getbufferΌ   s    "c         C@ sg   x |  j  D] } | j   q
 W|  j d  k	 r= |  j j   n  |  j  j   d  |  _ |  j j |   d  S(   N(   R#   t   detachR%   R$   t   clearRV   t   _capit   LLVMPY_DisposeExecutionEngine(   R(   t   mod(    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   _disposeΠ   s    	N(   t   __name__t
   __module__t   __doc__R$   RV   R'   R.   R0   R4   R8   R:   R<   R>   RB   t   propertyRE   RH   RL   RR   RZ   R`   Rc   Ri   (    (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyR   ,   s&   						
				
			
			RU   c           B@ s    e  Z d  Z d   Z d   Z RS(   sN   
    Internal: an ObjectCache instance for use within an ExecutionEngine.
    c         C@ s/   t  j j t t |  } t  j j |  |  d  S(   N(   R   R   t   LLVMPY_CreateObjectCachet   _notify_c_hookt   _getbuffer_c_hookR&   R'   (   R(   t   objR)   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyR'   ΰ   s    	c         C@ s   |  j  j |   d  S(   N(   Rf   t   LLVMPY_DisposeObjectCache(   R(   (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyRi   ζ   s    (   Rj   Rk   Rl   R'   Ri   (    (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyRU   Ϋ   s   	t   _ObjectCacheDatac           B@ s,   e  Z d  e j f d e f d e f g Z RS(   RK   R\   R]   (   Rj   Rk   R   t   LLVMModuleRefR   R   t   _fields_(    (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyRs      s   	(;   t
   __future__R    R   t   ctypesR   R   R   R   R   R   R   R	   R
   R   R   R   t   warningst    R   R   R   R   t   LLVMPY_LinkInMCJITR   R!   R&   R   RU   Rt   t   LLVMTargetMachineRefR   t   argtypest   LLVMExecutionEngineReft   restypeR?   R6   t   LLVMValueRefR1   R9   RC   t   LLVMTargetDataRefR   R+   R/   t   LLVMObjectFileRefRP   Rs   R$   t   _ObjectCacheNotifyFunct   _ObjectCacheGetBufferFuncR`   Ro   Rc   Rp   Rn   t   LLVMObjectCacheRefRr   RW   Ra   (    (    (    s?   lib/python2.7/site-packages/llvmlite/binding/executionengine.pyt   <module>   sd   R
		―		