ó
C]c           @   s  d  d l  Z  d  d l Z d  d l Z d d l m Z m Z d d l m Z d d l m	 Z	 d „  Z
 e
 d ƒ Z e
 d	 ƒ Z e
 d
 ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z  e
 d ƒ Z! e
 d ƒ Z" d  e# f d! „  ƒ  YZ$ d" e# f d# „  ƒ  YZ% e j& j' e( ƒ Z) e j* d$ k rêe j+ d% c d& e) 7<n  e ƒ  Z, e j& j- e) e, ƒ e, e j& j- d' e, ƒ g Z. y d  d( l/ m0 Z0 Wn e1 k
 rGn Xe. j2 e0 e3 e, ƒ ƒ xN e. D]1 Z4 y e  j5 e4 ƒ Z6 Wn e7 k
 r”qeqeXPqeWe7 d) j8 e, ƒ ƒ ‚ e$ e6 ƒ Z6 d* e# f d+ „  ƒ  YZ9 d, e# f d- „  ƒ  YZ: d. e# f d/ „  ƒ  YZ; d S(0   iÿÿÿÿNi   (   t   _decode_stringt   _is_shutting_downi   (   t   get_library_name(   t   PY2c         C   s%   t  |  t j f i  ƒ } t j | ƒ S(   N(   t   typet   ctypest	   Structuret   POINTER(   t   namet   newcls(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   _make_opaque_ref
   s    t   LLVMContextt
   LLVMModulet	   LLVMValuet   LLVMTypet   LLVMExecutionEnginet   LLVMPassManagerBuildert   LLVMPassManagert   LLVMTargetDatat   LLVMTargetLibraryInfot
   LLVMTargett   LLVMTargetMachinet   LLVMMemoryBuffert   LLVMAttributeListIteratort   LLVMAttributeSetIteratort   LLVMGlobalsIteratort   LLVMFunctionsIteratort   LLVMBlocksIteratort   LLVMArgumentsIteratort   LLVMInstructionsIteratort   LLVMOperandsIteratort   LLVMTypesIteratort   LLVMObjectCachet   LLVMObjectFilet   LLVMSectionIteratort   _lib_wrapperc           B   sM   e  Z d  Z d d d g Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   s{   Wrap libllvmlite with a lock such that only one thread may access it at
    a time.

    This class duck-types a CDLL.
    t   _libt   _fntabt   _lockc         C   s%   | |  _  i  |  _ t j ƒ  |  _ d  S(   N(   R$   R%   t	   threadingt   RLockR&   (   t   selft   lib(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __init__1   s    		c         C   sY   y |  j  | SWnC t k
 rT t |  j | ƒ } t |  j | ƒ } | |  j  | <| SXd  S(   N(   R%   t   KeyErrort   getattrR$   t   _lib_fn_wrapperR&   (   R)   R   t   cfnt   wrapped(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __getattr__8   s    c         C   s
   |  j  j S(   sg   The name of the library passed in the CDLL constructor.

        For duck-typing a ctypes.CDLL
        (   R$   t   _name(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR2   B   s    c         C   s
   |  j  j S(   s]   The system handle used to access the library.

        For duck-typing a ctypes.CDLL
        (   R$   t   _handle(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR3   J   s    (	   t   __name__t
   __module__t   __doc__t	   __slots__R+   R1   t   propertyR2   R3   (    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR#   )   s   		
R.   c           B   sn   e  Z d  Z d d g Z d „  Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e j d „  ƒ Z d „  Z	 RS(	   sî   Wraps and duck-types a ctypes.CFUNCTYPE to provide
    automatic locking when the wrapped function is called.

    TODO: we can add methods to mark the function as threadsafe
          and remove the locking-step on call when marked.
    R&   t   _cfnc         C   s   | |  _  | |  _ d  S(   N(   R&   R9   (   R)   t   lockR/   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR+   \   s    	c         C   s
   |  j  j S(   N(   R9   t   argtypes(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR;   `   s    c         C   s   | |  j  _ d  S(   N(   R9   R;   (   R)   R;   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR;   d   s    c         C   s
   |  j  j S(   N(   R9   t   restype(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR<   h   s    c         C   s   | |  j  _ d  S(   N(   R9   R<   (   R)   R<   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR<   l   s    c         O   s$   |  j   |  j | | Ž  SWd  QXd  S(   N(   R&   R9   (   R)   t   argst   kwargs(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __call__p   s    
(
   R4   R5   R6   R7   R+   R8   R;   t   setterR<   R?   (    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR.   S   s   	t   ntt   PATHt   ;t   .(   t   resource_filenames%   Could not load shared object file: {}t   _DeadPointerc           B   s   e  Z d  Z RS(   s:   
    Dummy class to make error messages more helpful.
    (   R4   R5   R6   (    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRF       s   t   OutputStringc           B   sb   e  Z d  Z e ƒ  Z e d „ Z d „  Z d „  Z d „  Z	 e
 d „ Z d „  Z d „  Z e Z RS(   s<   
    Object for managing the char* output of LLVM APIs.
    c         C   s4   t  j d  ƒ |  _ t  j |  j ƒ |  _ | |  _ d  S(   N(   R   t   c_char_pt   Nonet   _ptrt   byreft   _as_parameter_t   _owned(   R)   t   owned(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR+   ¬   s    c         C   sA   |  j  d  k	 r= |  j r+ t j |  j  ƒ n  d  |  _  |  ` n  d  S(   N(   RJ   RI   RM   R*   t   LLVMPY_DisposeStringRL   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   close±   s
    		c         C   s   |  S(   N(    (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt	   __enter__¸   s    c         C   s   |  j  ƒ  d  S(   N(   RP   (   R)   t   exc_typet   exc_valt   exc_tb(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __exit__»   s    c         C   s,   | ƒ  s( |  j  d  k	 r( |  j  ƒ  q( n  d  S(   N(   RP   RI   (   R)   R   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __del__¾   s    	c         C   s;   |  j  d  k r d S|  j  j } | d  k	 s1 t ‚ t | ƒ S(   Ns   <dead OutputString>(   RJ   RI   t   valuet   AssertionErrorR    (   R)   t   s(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __str__Å   s
    c         C   s   t  |  j ƒ S(   N(   t   boolRJ   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __bool__Ì   s    (   R4   R5   R6   RF   RL   t   TrueR+   RP   RQ   RU   R   RV   RZ   R\   t   __nonzero__(    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRG   ¦   s   						t	   ObjectRefc           B   s•   e  Z d  Z e Z e ƒ  Z e Z d „  Z d „  Z	 d „  Z
 d „  Z e d „  ƒ Z d „  Z d „  Z e d „ Z d	 „  Z d
 „  Z e Z d „  Z RS(   sJ   
    A wrapper around a ctypes pointer to a LLVM object ("resource").
    c         C   s:   | d  k r t d ƒ ‚ n  | |  _ | |  _ t |  _ d  S(   Ns   NULL pointer(   RI   t
   ValueErrorRJ   RL   R*   t   _capi(   R)   t   ptr(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR+   Û   s
    		c         C   s7   z% |  j  r$ |  j r$ |  j ƒ  n  Wd |  j ƒ  Xd S(   sI   
        Close this object and do any required clean-up actions.
        N(   t   _closedRM   t   _disposet   detach(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRP   â   s    c         C   s(   |  j  s$ |  ` t |  _  d |  _ n  d S(   sN   
        Detach the underlying LLVM resource without disposing of it.
        N(   Rc   RL   R]   RI   RJ   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRe   ì   s    		c         C   s   d S(   sÒ   
        Dispose of the underlying LLVM resource.  Should be overriden
        by subclasses.  Automatically called by close(), __del__() and
        __exit__() (unless the resource has been detached).
        N(    (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRd   õ   t    c         C   s   |  j  S(   sf   
        Whether this object has been closed.  A closed object can't
        be used anymore.
        (   Rc   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   closedü   s    c         C   s;   t  |  d ƒ s t ‚ |  j r7 t d |  j f ƒ ‚ n  |  S(   NRP   s   %s instance already closed(   t   hasattrRX   Rc   t   RuntimeErrort	   __class__(   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRQ     s    	c         C   s   |  j  ƒ  d  S(   N(   RP   (   R)   RR   RS   RT   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRU   
  s    c         C   s,   | ƒ  s( |  j  d  k	 r( |  j  ƒ  q( n  d  S(   N(   RP   RI   (   R)   R   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyRV     s    	c         C   s   t  |  j ƒ S(   N(   R[   RJ   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR\     s    c         C   s=   t  | d ƒ s t St j |  j d ƒ t j | j d ƒ k S(   NRJ   i    (   Rh   t   FalseR   t	   addressofRJ   (   R)   t   other(    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __eq__  s    c         C   s   t  t j |  j t j ƒ j ƒ S(   N(   t   hashR   t   castRJ   t   c_void_pRW   (   R)   (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   __hash__  s    (   R4   R5   R6   Rk   Rc   RF   RL   RM   R+   RP   Re   Rd   R8   Rg   RQ   RU   R   RV   R\   Rn   R^   Rr   (    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyR_   Ò   s    			
							(<   R   t   osR'   t   commonR    R   t   utilsR   t   sixR   R
   t   LLVMContextReft   LLVMModuleReft   LLVMValueReft   LLVMTypeReft   LLVMExecutionEngineReft   LLVMPassManagerBuilderReft   LLVMPassManagerReft   LLVMTargetDataReft   LLVMTargetLibraryInfoReft   LLVMTargetReft   LLVMTargetMachineReft   LLVMMemoryBufferRefR   R   R   R   R   R   R   R   R   t   LLVMObjectCacheReft   LLVMObjectFileReft   LLVMSectionIteratorReft   objectR#   R.   t   patht   dirnamet   __file__t   _lib_dirR   t   environt	   _lib_namet   joint
   _lib_pathst   pkg_resourcesRE   t   ImportErrort   appendR4   t	   _lib_patht   CDLLR*   t   OSErrort   formatRF   RG   R_   (    (    (    s3   lib/python2.7/site-packages/llvmlite/binding/ffi.pyt   <module>   sn   	*"	,