ó
C]c           @@ sõ  d  d l  m Z m Z d  d l 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 m Z d „  Z d e f d	 „  ƒ  YZ d
 „  Z d „  Z d „  Z i d d 6d d 6d d 6Z d d „ Z d „  Z d e j f d „  ƒ  YZ e d d d d g ƒ Z e d d d d d d g ƒ Z d e j f d  „  ƒ  YZ  d! e j f d" „  ƒ  YZ! d# „  Z" e e ƒ g e j# j$ _% e e ƒ g e j# j& _% e e j# j& _' e e ƒ g e j# j( _% e e ƒ g e j# j) _% e g e j# j* _% e e j# j* _' e g e j# j+ _% e j, e j# j+ _' e j, e e ƒ g e j# j- _% e j, g e j# j. _% e j, e j/ g e j# j0 _% e e j# j0 _' e j, e j/ e g e j# j1 _% e e j# j1 _' e j, e j/ g e j# j2 _% e e j# j2 _' e j, e j/ g e j# j3 _% e e j# j3 _' e e e ƒ g e j# j4 _% e j5 e j# j4 _' e j5 g e j# j6 _% e e j# j6 _' e j5 g e j# j7 _% e e j# j7 _' e j5 e e e e e e g e j# j8 _% e j9 e j# j8 _' e j9 g e j# j: _% e j9 e e ƒ g e j# j; _% e j9 e g e j# j< _% e j9 e j= g e j# j> _% e j9 e j? e e e ƒ g e j# j@ _% e jA e j# j@ _' e jA g e j# jB _% e
 e j# jB _' e jA g e j# jC _% e	 e j# jC _' e jA g e j# jD _% e j9 g e j# jE _% e j, e j# jE _' g  e j# jF _% e e j# jF _' d S($   i    (   t   print_functiont   absolute_importN(   t   POINTERt   c_char_pt
   c_longlongt   c_intt   c_size_tt   c_void_pt	   string_ati   (   t   ffi(   t   _decode_stringt   _encode_stringc          C@ s3   t  j ƒ  ! }  t  j j |  ƒ t |  ƒ SWd QXd S(   s  
    Return a target triple suitable for generating code for the current process.
    An example when the default triple from ``get_default_triple()`` is not be
    suitable is when LLVM is compiled for 32-bit but the process is executing
    in 64-bit mode.
    N(   R	   t   OutputStringt   libt   LLVMPY_GetProcessTriplet   str(   t   out(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_process_triple   s    t
   FeatureMapc           B@ s   e  Z d  Z e d „ Z RS(   s…   
    Maps feature name to a boolean indicating the availability of the feature.
    Extends ``dict`` to add `.flatten()` method.
    c         @ s[   | r t  |  j ƒ  ƒ n t |  j ƒ  ƒ } i d t 6d t 6‰  d j ‡  f d †  | Dƒ ƒ S(   sp  
        Args
        ----
        sort: bool
            Optional.  If True, the features are sorted by name; otherwise,
            the ordering is unstable between python session due to hash
            randomization.  Defaults to True.

        Returns a string suitable for use as the ``features`` argument to
        ``Target.create_target_machine()``.

        t   +t   -t   ,c         3@ s+   |  ]! \ } } d  j  ˆ  | | ƒ Vq d S(   s   {0}{1}N(   t   format(   t   .0t   kt   v(   t   flag_map(    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pys	   <genexpr>+   s   (   t   sortedt   itemst   itert   Truet   Falset   join(   t   selft   sortt   iterator(    (   R   s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   flatten   s    *(   t   __name__t
   __module__t   __doc__R   R$   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR      s   c       	   C@ s©   t  j ƒ  — }  t ƒ  } t  j j |  ƒ s9 t d ƒ ‚ n  i t d 6t d 6} t |  ƒ } | r› x9 | j	 d ƒ D]% } | ro | | d | | d <qo qo Wn  | SWd QXd S(   sc  
    Returns a dictionary-like object indicating the CPU features for current
    architecture and whether they are enabled for this CPU.  The key-value pairs
    are the feature name as string and a boolean indicating whether the feature
    is available.  The returned value is an instance of ``FeatureMap`` class,
    which adds a new method ``.flatten()`` for returning a string suitable for
    use as the "features" argument to ``Target.create_target_machine()``.

    If LLVM has not implemented this feature or it fails to get the information,
    this function will raise a RuntimeError exception.
    s    failed to get host cpu features.R   R   R   i    i   N(
   R	   R   R   R   t   LLVMPY_GetHostCPUFeaturest   RuntimeErrorR   R   R   t   split(   R   t   outdictR   t   contentt   feat(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_host_cpu_features/   s    	 c          C@ s3   t  j ƒ  ! }  t  j j |  ƒ t |  ƒ SWd QXd S(   sR   
    Return the default target triple LLVM is configured to produce code for.
    N(   R	   R   R   t   LLVMPY_GetDefaultTargetTripleR   (   R   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_default_tripleH   s    c          C@ s3   t  j ƒ  ! }  t  j j |  ƒ t |  ƒ SWd QXd S(   sm   
    Get the name of the host's CPU, suitable for using with
    :meth:`Target.create_target_machine()`.
    N(   R	   R   R   t   LLVMPY_GetHostCPUNameR   (   R   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_host_cpu_nameP   s    t   COFFt   ELFi   t   MachOi   c         C@ s8   |  d k r t ƒ  }  n  t j j t |  ƒ ƒ } t | S(   s~   
    Get the object format for the given *triple* string (or the default
    triple if omitted).
    A string is returned
    N(   t   NoneR0   R	   R   t   LLVMPY_GetTripleObjectFormatR   t   _object_formats(   t   triplet   res(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_object_format_   s    c         C@ s   t  t j j t |  ƒ ƒ ƒ S(   sE   
    Create a TargetData instance for the given *layout* string.
    (   t
   TargetDataR	   R   t   LLVMPY_CreateTargetDataR   (   t   layout(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   create_target_datak   s    R<   c           B@ sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s{   
    A TargetData provides structured access to a data layout.
    Use :func:`create_target_data` to create instances.
    c         C@ sC   |  j  r d St j ƒ  $ } t j j |  | ƒ t | ƒ SWd  QXd  S(   Ns   <dead TargetData>(   t   _closedR	   R   R   t    LLVMPY_CopyStringRepOfTargetDataR   (   R!   R   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   __str__x   s
    	c         C@ s   |  j  j |  ƒ d  S(   N(   t   _capit   LLVMPY_DisposeTargetData(   R!   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   _dispose   s    c         C@ s   t  j j |  | ƒ S(   s1   
        Get ABI size of LLVM type *ty*.
        (   R	   R   t   LLVMPY_ABISizeOfType(   R!   t   ty(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_abi_size‚   s    c         C@ sI   t  j j |  | | ƒ } | d k rE t d j | t | ƒ ƒ ƒ ‚ n  | S(   sL   
        Get byte offset of type's ty element at the given position
        iÿÿÿÿsR   Could not determined offset of {}th element of the type '{}'. Is it a struct type?(   R	   R   t   LLVMPY_OffsetOfElementt
   ValueErrorR   R   (   R!   RG   t   positiont   offset(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_element_offsetˆ   s
    	c         C@ s;   t  j j |  | ƒ } | d k r7 t d | f ƒ ‚ n  | S(   sI   
        Get ABI size of pointee type of LLVM pointer type *ty*.
        iÿÿÿÿs   Not a pointer type: %s(   R	   R   t   LLVMPY_ABISizeOfElementTypeR)   (   R!   RG   t   size(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_pointee_abi_size”   s    c         C@ s;   t  j j |  | ƒ } | d k r7 t d | f ƒ ‚ n  | S(   sV   
        Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
        iÿÿÿÿs   Not a pointer type: %s(   R	   R   t    LLVMPY_ABIAlignmentOfElementTypeR)   (   R!   RG   RO   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   get_pointee_abi_alignment   s    (	   R%   R&   R'   RB   RE   RH   RM   RP   RR   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR<   r   s   						t   defaultt   statict   pict   dynamicnopict
   jitdefaultt   smallt   kernelt   mediumt   larget   Targetc           B@ s€   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 d  d  d d d	 e e d
 „ Z RS(   t    c         C@ s   t  ƒ  } |  j | ƒ S(   sB   
        Create a Target instance for the default triple.
        (   R0   t   from_triple(   t   clsR9   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   from_default_triple²   s    	c         C@ sk   t  j ƒ  Y } t  j j | j d ƒ | ƒ } | sH t t | ƒ ƒ ‚ n  |  | ƒ } | | _ | SWd QXd S(   sK   
        Create a Target instance for the given triple (a string).
        t   utf8N(   R	   R   R   t   LLVMPY_GetTargetFromTriplet   encodeR)   R   t   _triple(   R_   R9   t   outerrt   target(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR^   º   s    		c         C@ s   t  j j |  ƒ } t | ƒ S(   N(   R	   R   t   LLVMPY_GetTargetNameR
   (   R!   t   s(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   nameÈ   s    c         C@ s   t  j j |  ƒ } t | ƒ S(   N(   R	   R   t   LLVMPY_GetTargetDescriptionR
   (   R!   Rh   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   descriptionÍ   s    c         C@ s   |  j  S(   N(   Rd   (   R!   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR9   Ò   s    c         C@ s   d j  |  j |  j ƒ S(   Ns   <Target {0} ({1})>(   R   Ri   Rk   (   R!   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyRB   Ö   s    i   RS   RW   c   
      C@ së   d | k o d k n s" t  ‚ | t k s4 t  ‚ | t k sF t  ‚ |  j } t j d k rw | d k rw | d 7} n  t j j |  t	 | ƒ t	 | ƒ t	 | ƒ | t	 | ƒ t	 | ƒ t
 | ƒ t
 | ƒ ƒ	 }	 |	 rÛ t |	 ƒ St d ƒ ‚ d S(   s>  
        Create a new TargetMachine for this target and the given options.

        Specifying codemodel='default' will result in the use of the "small"
        code model. Specifying codemodel='jitdefault' will result in the code
        model being picked based on platform bitness (32="small", 64="large").
        i    i   t   ntRW   s   -elfs   Cannot create target machineN(   t   AssertionErrort   RELOCt	   CODEMODELRd   t   osRi   R	   R   t   LLVMPY_CreateTargetMachineR   t   intt   TargetMachineR)   (
   R!   t   cput   featurest   optt   reloct	   codemodelt   jitdebugt   printmcR9   t   tm(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   create_target_machineÙ   s$    
"							
(   R%   R&   Rd   t   classmethodR`   R^   t   propertyRi   Rk   R9   RB   R   R|   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR\   ¬   s   		Rs   c           B@ s_   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z e	 d „  ƒ Z
 e	 d „  ƒ Z RS(   c         C@ s   |  j  j |  ƒ d  S(   N(   RC   t   LLVMPY_DisposeTargetMachine(   R!   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyRE   þ   s    c         C@ s   t  j j |  | ƒ d S(   sW   
        Register analysis passes for this target machine with a pass manager.
        N(   R	   R   t   LLVMPY_AddAnalysisPasses(   R!   t   pm(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   add_analysis_passes  s    c         C@ s   t  j j |  | ƒ d S(   s    
        Set whether this target machine will emit assembly with human-readable
        comments describing control flow, debug information, and so on.
        N(   R	   R   t#   LLVMPY_SetTargetMachineAsmVerbosity(   R!   t   verbose(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   set_asm_verbosity  s    c         C@ s   |  j  | d t ƒS(   s…   
        Represent the module as a code object, suitable for use with
        the platform's linker.  Returns a byte string.
        t
   use_object(   t   _emit_to_memoryR   (   R!   t   module(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   emit_object  s    c         C@ s   t  |  j | d t ƒƒ S(   s   
        Return the raw assembler of the module, as a string.

        llvm.initialize_native_asmprinter() must have been called first.
        R†   (   R
   R‡   R   (   R!   Rˆ   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   emit_assembly  s    c      	   C@ sž   t  j ƒ  C } t  j j |  | t | ƒ | ƒ } | sK t t | ƒ ƒ ‚ n  Wd QXt  j j | ƒ } t  j j | ƒ } z t	 | | ƒ SWd t  j j
 | ƒ Xd S(   s¨   Returns bytes of object code of the module.

        Args
        ----
        use_object : bool
            Emit object code or (if False) emit assembly code.
        N(   R	   R   R   t    LLVMPY_TargetMachineEmitToMemoryRr   R)   R   t   LLVMPY_GetBufferStartt   LLVMPY_GetBufferSizeR   t   LLVMPY_DisposeMemoryBuffer(   R!   Rˆ   R†   Re   t   mbt   bufptrt   bufsz(    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR‡     s    		c         C@ s   t  t j j |  ƒ ƒ S(   N(   R<   R	   R   t   LLVMPY_CreateTargetMachineData(   R!   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   target_data3  s    c         C@ s6   t  j ƒ  $ } t  j j |  | ƒ t | ƒ SWd  QXd  S(   N(   R	   R   R   t   LLVMPY_GetTargetMachineTripleR   (   R!   R   (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyR9   7  s    (   R%   R&   RE   R‚   R…   R‰   RŠ   R   R‡   R~   R“   R9   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyRs   ü   s   					c           C@ s!   t  j j ƒ  d k r t St Sd S(   sG   
    Returns True if SVML was enabled at FFI support compile time.
    i    N(   R	   R   t   LLVMPY_HasSVMLSupportR   R   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   has_svml=  s    (G   t
   __future__R    R   Rp   t   ctypesR   R   R   R   R   R   R   R]   R	   t   commonR
   R   R   t   dictR   R.   R0   R2   R8   R6   R;   R?   t	   ObjectRefR<   t	   frozensetRn   Ro   R\   Rs   R–   R   R   t   argtypesR(   t   restypeR/   R1   R7   R=   t   LLVMTargetDataRefRA   RD   t   LLVMTypeRefRF   RI   RN   RQ   Rb   t   LLVMTargetRefRg   Rj   Rq   t   LLVMTargetMachineRefR   R”   Rƒ   t   LLVMPassManagerRefR€   t   LLVMModuleRefR‹   t   LLVMMemoryBufferRefRŒ   R   RŽ   R’   R•   (    (    (    s7   lib/python2.7/site-packages/llvmlite/binding/targets.pyt   <module>   s¤   4					
	5PA	