ó
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
 d d l m Z d d l m Z d d l m Z m Z d d l m Z m Z d d l m Z d d	 „ Z d d
 „ Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e j  e e e ƒ g e j! j" _# e j$ e j! j" _% e j  e e	 e e ƒ g e j! j& _# e j$ e j! j& _% e j$ g e j! j' _# e j$ e e ƒ g e j! j( _# e j$ e e ƒ e e	 ƒ g e j! j) _# e j$ e g e j! j* _# e j+ e j! j* _% e j$ e e ƒ g e j! j, _# e e j! j, _% e j$ e e ƒ g e j! j- _# e j$ e g e j! j. _# e j$ e e ƒ g e j! j/ _# e j$ e g e j! j0 _# e j$ e g e j! j1 _# e j+ e j! j1 _% e j$ e g e j! j2 _# e j3 e j! j2 _% e j$ g e j! j4 _# e j5 e j! j4 _% e j5 g e j! j6 _# e j5 g e j! j7 _# e j+ e j! j7 _% e j$ g e j! j8 _# e j9 e j! j8 _% e j$ g e j! j: _# e j; e j! j: _% e j9 g e j! j< _# e j; g e j! j= _# e j9 g e j! j> _# e j+ e j! j> _% e j; g e j! j? _# e j3 e j! j? _% e j$ g e j! j@ _# e j$ e j! j@ _% e j$ g e j! jA _# e e j! jA _% e j$ e g e j! jB _# d S(   i    (   t   print_functiont   absolute_import(   t   c_char_pt   byreft   POINTERt   c_boolt   create_string_buffert   c_size_tt	   string_ati   (   t   ffi(   t   link_modules(   t   _decode_stringt   _encode_string(   t   ValueReft   TypeRef(   t   get_global_contextc      	   C@ s’   | d k r t ƒ  } n  t |  ƒ }  t |  ƒ } t j ƒ  P } t t j j | | | ƒ | ƒ } | rˆ | j	 ƒ  t
 d j | ƒ ƒ ‚ n  Wd QX| S(   s-   
    Create Module from a LLVM IR string
    s   LLVM IR parsing error
{0}N(   t   NoneR   R   R   R	   t   OutputStringt	   ModuleReft   libt   LLVMPY_ParseAssemblyt   closet   RuntimeErrort   format(   t   llvmirt   contextt   strbuft   errmsgt   mod(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   parse_assembly   s    	
c      
   C@ s•   | d k r t ƒ  } n  t |  ƒ } t |  ƒ } t j ƒ  S } t t j j | | | | ƒ | ƒ } | r‹ | j	 ƒ  t
 d j | ƒ ƒ ‚ n  Wd QX| S(   s?   
    Create Module from a LLVM *bitcode* (a bytes object).
    s   LLVM bitcode parsing error
{0}N(   R   R   R   t   lenR	   R   R   R   t   LLVMPY_ParseBitcodeR   R   R   (   t   bitcodeR   t   buft   bufsizeR   R   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   parse_bitcode   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
 e d	 „  ƒ Z e j d
 „  ƒ Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e j d „  ƒ Z e d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   s'   
    A reference to a LLVM module.
    c         C@ s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   t   superR   t   __init__t   _context(   t   selft
   module_ptrR   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR%   5   s    c         C@ s6   t  j ƒ  $ } t  j j |  | ƒ t | ƒ SWd  QXd  S(   N(   R	   R   R   t   LLVMPY_PrintModuleToStringt   str(   R'   t   outstr(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   __str__9   s    c         C@ sŠ   t  d ƒ } t d ƒ } t j j |  t | ƒ t | ƒ ƒ | sI t ‚ n  z) | j d k sa t	 ‚ t
 | | j ƒ SWd t j j | ƒ Xd S(   sF   
        Return the module's LLVM bitcode, as a bytes object.
        iÿÿÿÿi    N(   R   R   R   R	   R   t   LLVMPY_WriteBitcodeToStringR   t   MemoryErrort   valuet   AssertionErrorR   t   LLVMPY_DisposeString(   R'   t   ptrt   size(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt
   as_bitcode>   s    "	c         C@ s   |  j  j |  ƒ d  S(   N(   t   _capit   LLVMPY_DisposeModule(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   _disposeM   s    c         C@ sI   t  j j |  t | ƒ ƒ } | s0 t | ƒ ‚ n  t | d t d |  ƒ ƒ S(   s~   
        Get a ValueRef pointing to the function named *name*.
        NameError is raised if the symbol isn't found.
        t   functiont   module(   R	   R   t   LLVMPY_GetNamedFunctionR   t	   NameErrorR   t   dict(   R'   t   namet   p(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   get_functionP   s    c         C@ sI   t  j j |  t | ƒ ƒ } | s0 t | ƒ ‚ n  t | d t d |  ƒ ƒ S(   s…   
        Get a ValueRef pointing to the global variable named *name*.
        NameError is raised if the symbol isn't found.
        t   globalR9   (   R	   R   t   LLVMPY_GetNamedGlobalVariableR   R;   R   R<   (   R'   R=   R>   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   get_global_variableZ   s    c         C@ s:   t  j j |  t | ƒ ƒ } | s0 t | ƒ ‚ n  t | ƒ S(   s†   
        Get a TypeRef pointing to a structure type named *name*.
        NameError is raised if the struct type isn't found.
        (   R	   R   t   LLVMPY_GetNamedStructTypeR   R;   R   (   R'   R=   R>   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   get_struct_typed   s    c         C@ sC   t  j ƒ  1 } t  j j |  | ƒ r9 t t | ƒ ƒ ‚ n  Wd QXd S(   sW   
        Verify the module IR's correctness.  RuntimeError is raised on error.
        N(   R	   R   R   t   LLVMPY_VerifyModuleR   R*   (   R'   t   outmsg(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   verifyn   s    c         C@ s   t  t j j |  ƒ ƒ S(   s*   
        The module's identifier.
        (   R   R	   R   t   LLVMPY_GetModuleName(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR=   v   s    c         C@ s   t  j j |  t | ƒ ƒ d  S(   N(   R	   R   t   LLVMPY_SetModuleNameR   (   R'   R/   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR=   }   s    c         C@ s<   t  j d t ƒ $ } t  j j |  | ƒ t | ƒ SWd QXd S(   sG   
        This module's data layout specification, as a string.
        t   ownedN(   R	   R   t   FalseR   t   LLVMPY_GetDataLayoutR*   (   R'   RF   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   data_layout   s    c         C@ s&   t  j j |  t | j d ƒ ƒ ƒ d  S(   Nt   utf8(   R	   R   t   LLVMPY_SetDataLayoutR   t   encode(   R'   t   strrep(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRM   ‹   s    c         C@ s<   t  j d t ƒ $ } t  j j |  | ƒ t | ƒ SWd QXd S(   sK   
        This module's target "triple" specification, as a string.
        RJ   N(   R	   R   RK   R   t   LLVMPY_GetTargetR*   (   R'   RF   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   triple‘   s    c         C@ s&   t  j j |  t | j d ƒ ƒ ƒ d  S(   NRN   (   R	   R   t   LLVMPY_SetTargetR   RP   (   R'   RQ   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRS   ›   s    c         C@ s&   | r | j  ƒ  } n  t |  | ƒ d S(   s   
        Link the *other* module into this one.  The *other* module will
        be destroyed unless *preserve* is true.
        N(   t   cloneR
   (   R'   t   othert   preserve(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   link_in¡   s    c         C@ s(   t  j j |  ƒ } t | t d |  ƒ ƒ S(   s)  
        Return an iterator over this module's global variables.
        The iterator will yield a ValueRef for each global variable.

        Note that global variables don't include functions
        (a function is a "global value" but not a "global variable" in
         LLVM parlance)
        R9   (   R	   R   t   LLVMPY_ModuleGlobalsItert   _GlobalsIteratorR<   (   R'   t   it(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   global_variablesª   s    
c         C@ s(   t  j j |  ƒ } t | t d |  ƒ ƒ S(   s€   
        Return an iterator over this module's functions.
        The iterator will yield a ValueRef for each function.
        R9   (   R	   R   t   LLVMPY_ModuleFunctionsItert   _FunctionsIteratorR<   (   R'   R[   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt	   functions·   s    c         C@ s(   t  j j |  ƒ } t | t d |  ƒ ƒ S(   s|   
        Return an iterator over the struct types defined in
        the module. The iterator will yield a TypeRef.
        R9   (   R	   R   t   LLVMPY_ModuleTypesItert   _TypesIteratorR<   (   R'   R[   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   struct_typesÀ   s    c         C@ s   t  t j j |  ƒ |  j ƒ S(   N(   R   R	   R   t   LLVMPY_CloneModuleR&   (   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRU   É   s    (   t   __name__t
   __module__t   __doc__R%   R,   R4   R7   R?   RB   RD   RG   t   propertyR=   t   setterRM   RS   RK   RX   R\   R_   Rb   RU   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR   0   s(   					
	
	
	

			t	   _Iteratorc           B@ s/   e  Z d Z d  „  Z d „  Z e Z d „  Z RS(   c         C@ s5   t  j j |  | ƒ | |  _ |  j d  k	 s1 t ‚ d  S(   N(   R	   t	   ObjectRefR%   t   _parentst   kindR   R0   (   R'   R2   t   parents(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR%   Ñ   s    	c         C@ s2   |  j  ƒ  } | r( t | |  j |  j ƒ St ‚ d  S(   N(   t   _nextR   Rl   Rk   t   StopIteration(   R'   t   vp(    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   __next__Ö   s    c         C@ s   |  S(   N(    (   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   __iter__ß   s    N(   Rd   Re   R   Rl   R%   Rq   t   nextRr   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRi   Í   s
   		RZ   c           B@ s    e  Z d  Z d „  Z d „  Z RS(   R@   c         C@ s   |  j  j |  ƒ d  S(   N(   R5   t   LLVMPY_DisposeGlobalsIter(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR7   ç   s    c         C@ s   t  j j |  ƒ S(   N(   R	   R   t   LLVMPY_GlobalsIterNext(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRn   ê   s    (   Rd   Re   Rl   R7   Rn   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRZ   ã   s   	R^   c           B@ s    e  Z d  Z d „  Z d „  Z RS(   R8   c         C@ s   |  j  j |  ƒ d  S(   N(   R5   t   LLVMPY_DisposeFunctionsIter(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR7   ò   s    c         C@ s   t  j j |  ƒ S(   N(   R	   R   t   LLVMPY_FunctionsIterNext(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRn   õ   s    (   Rd   Re   Rl   R7   Rn   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR^   î   s   	Ra   c           B@ s/   e  Z d  Z d „  Z d „  Z d „  Z e Z RS(   t   typec         C@ s   |  j  j |  ƒ d  S(   N(   R5   t   LLVMPY_DisposeTypesIter(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyR7   ý   s    c         C@ s&   |  j  ƒ  } | r t | ƒ St ‚ d  S(   N(   Rn   R   Ro   (   R'   Rp   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRq      s    
c         C@ s   t  j j |  ƒ S(   N(   R	   R   t   LLVMPY_TypesIterNext(   R'   (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRn     s    (   Rd   Re   Rl   R7   Rq   Rn   Rs   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyRa   ù   s
   			N(C   t
   __future__R    R   t   ctypesR   R   R   R   R   R   R   t    R	   t   linkerR
   t   commonR   R   R/   R   R   R   R   R   R   R#   Rj   R   Ri   RZ   R^   Ra   t   LLVMContextRefR   R   t   argtypest   LLVMModuleReft   restypeR   R6   R)   R-   R:   t   LLVMValueRefRE   RL   RO   RR   RT   RA   RC   t   LLVMTypeRefRY   t   LLVMGlobalsIteratorRt   Ru   R]   t   LLVMFunctionsIteratorR`   t   LLVMTypesIteratorRv   Ry   Rw   Rz   Rc   RH   RI   (    (    (    s6   lib/python2.7/site-packages/llvmlite/binding/module.pyt   <module>   sz   4	