σ
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 d e	 f d     YZ
 d S(   i    (   t   print_functiont   absolute_importNi   (   t   contextt   valuest   typest   _utilst   Modulec           B@ sΧ   e  Z d  e j d  Z d   Z d   Z d   Z e d  Z	 d d  Z d   Z e d    Z e d	    Z d
   Z d   Z d  d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   t    c         C@ sa   | |  _  | |  _ d |  _ t j   |  _ d |  _ t j   |  _	 g  |  _
 i  |  _ i  |  _ d  S(   NR   s   unknown-unknown-unknown(   R   t   namet   data_layoutR   t	   NameScopet   scopet   triplet   collectionst   OrderedDictt   globalst   metadatat   namedmetadatat   _metadatacache(   t   selfR   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   __init__	   s    						c         C@ s   g  } x | D] } | d  k r4 t j   d   } nK t | t  rX t j |  |  } n' t | t t f  r |  j	 |  } n  | j
 |  q W| S(   N(   t   NoneR   t   MetaDataTypet
   isinstancet   strR   t   MetaDataStringt   listt   tuplet   add_metadatat   append(   R   t   operandst	   fixed_opst   op(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _fix_metadata_operands   s    c         C@ s[   g  } xN | D]F \ } } t  | t t f  r@ |  j |  } n  | j | | f  q W| S(   N(   R   R   R   R   R   (   R   R   R   R   R    (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _fix_di_operands&   s    c         C@ s£   t  | t t f  s+ t d | f   n  |  j |  } t |  } | |  j k r t |  j  } t j	 |  | d t
 |  } | |  j | <n |  j | } | S(   sό   
        Add an unnamed metadata to the module with the given *operands*
        (a sequence of values) or return a previous equivalent metadata.
        A MDValue instance is returned, it can then be associated to
        e.g. an instruction.
        s3   expected a list or tuple of metadata values, got %rR   (   R   R   R   t	   TypeErrorR!   R   t   lenR   R   t   MDValueR   (   R   R   t   keyt   nt   md(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyR   /   s    c         C@ s   t  t |  j | j      } | | | f } | |  j k r t |  j  } t j |  | | | d t	 |  } | |  j | <n |  j | } | S(   sk  
        Add debug information metadata to the module with the given
        *operands* (a dict of values with string keys) or return
        a previous equivalent metadata.  *kind* is a string of the
        debug information kind (e.g. "DICompileUnit").

        A DIValue instance is returned, it can then be associated to e.g.
        an instruction.
        R   (
   R   t   sortedR"   t   itemsR   R$   R   R   t   DIValueR   (   R   t   kindR   t   is_distinctR&   R'   t   di(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   add_debug_infoC   s    
!$c         C@ s¨   | |  j  k r |  j  | } n t j |   } |  j  | <| d k	 r€ t | t j  si |  j |  } n  t | j t j	  s t
 d | f   n  | j |  n  | S(   s­  
        Add a named metadata node to the module, if it doesn't exist,
        or return the existing node.
        If *element* is given, it will append a new element to
        the named metadata node.  If *element* is a sequence of values
        (rather than a metadata value), a new unnamed node will first be
        created.

        Example::
            module.add_named_metadata("llvm.ident", ["llvmlite/1.0"])
        s'   wrong type for metadata element: got %rN(   R   R   t   NamedMetaDataR   R   t   ValueR   t   typeR   R   R#   t   add(   R   R   t   elementt   nmd(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   add_named_metadataW   s    c         C@ s   |  j  | S(   s   
        Return the metadata node with the given *name*.  KeyError is raised
        if no such node exists (contrast with add_named_metadata()).
        (   R   (   R   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   get_named_metadatap   s    c         C@ s2   g  |  j  j   D] } t | t j  r | ^ q S(   sI   
        A list of functions declared or defined in this module.
        (   R   R   R   t   Function(   R   t   v(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt	   functionsw   s    c         C@ s   |  j  j   S(   s>   
        An iterable of global values in this module.
        (   R   R   (   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   global_values   s    c         C@ s   |  j  | S(   s-   
        Get a global value by name.
        (   R   (   R   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt
   get_global   s    c         C@ s,   | j  |  j k s t  | |  j | j  <d S(   s)   
        Add a new global value.
        N(   R   R   t   AssertionError(   R   t   globalvalue(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt
   add_global   s    c         C@ s   |  j  j |  S(   sJ   
        Get a unique global name with the following *name* hint.
        (   R   t   deduplicate(   R   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   get_unique_name   s    c         @ sέ     f d   }   d d d h k r:  d j  g } n g   D] } | j  ^ qA } d j   g |  } | |  j k r |  j | S| d  k	 r n2t   d k rΪ   d k rΪ t j t j   t j d  g  } nνt   d k rf  d	 k r$t j  d  d t j d
  g  } qΗ  d k rMt j  d  d  } qΗt j  d   } nat   d k r%  d k rΧ d t j d   d t j d
  t j d  g  t j t j     } qΗ  d d h k r d t j d  g  t j  d   } qΗ|   n’ t   d k rΐ  d k r t j d
  t j d  g  t j t j     } qΗ  d k rΆ d g d  t j  d   } qΗ|   n |   t	 j
 |  | d | S(   Nc           @ s    t  d   t   f   d  S(   Ns"   unknown intrinsic %r with %d types(   t   NotImplementedErrorR$   (    (   t	   intrinsict   tys(    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _error   s    s	   llvm.cttzs	   llvm.ctlzs   llvm.fmai    t   .s   llvm.assumei   s	   llvm.powii    s   llvm.powi   s   llvm.memseti   i   s   llvm.memcpys   llvm.memmoveR   (   s   llvm.memcpys   llvm.memmove(   t   intrinsic_namet   joinR   R   R$   R   t   FunctionTypet   VoidTypet   IntTypeR   R8   (   R   RC   RD   t   fntyRE   t   suffixest   tR   (    (   RC   RD   s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   declare_intrinsic   sH    ',
"
c         C@ s
   |  j  j S(   N(   R   t   identified_types(   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   get_identified_typesΚ   s    c         C@ s[   g  |  j    j   D] } | j   ^ q } | g  |  j j   D] } t |  ^ q> 7} | S(   N(   RQ   R   t   get_declarationR   R   (   R   t   itt   linesR9   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _get_body_linesΝ   s    (,c      	   C@ s   g  } xR |  j  j   D]A \ } } | j d j d | d d j d   | j D    q Wx$ |  j D] } | j t |   qe W| S(   Ns   !{name} = !{{ {operands} }}R   R   s   , c         s@ s   |  ] } | j    Vq d  S(   N(   t   get_reference(   t   .0t   i(    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pys	   <genexpr>Ω   s   (   R   R*   R   t   formatRH   R   R   R   (   R   t   mdbuft   kR9   R(   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _get_metadata_linesΥ   s    c         C@ s   d j  |  j    S(   Ns   
(   RH   RU   (   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _stringify_bodyί   s    c         C@ s   d j  |  j    S(   Ns   
(   RH   R\   (   R   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   _stringify_metadataγ   s    c         C@ sg   g  } | d |  j  f d |  j f d |  j f d g 7} | |  j   7} | |  j   7} d j |  S(   Ns   ; ModuleID = "%s"s   target triple = "%s"s   target datalayout = "%s"R   s   
(   R   R   R	   RU   R\   RH   (   R   RT   (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   __repr__η   s    
N(    (   t   __name__t
   __module__R   t   global_contextR   R!   R"   R   t   FalseR/   R   R6   R7   t   propertyR:   R;   R<   R?   RA   RO   RQ   RU   R\   R]   R^   R_   (    (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyR      s&   							1			
		(   t
   __future__R    R   R   R   R   R   R   R   t   objectR   (    (    (    s1   lib/python2.7/site-packages/llvmlite/ir/module.pyt   <module>   s   "