ó
™^c           @   sÐ   g  a  d  e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d S(   t
   TextWriterc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s;   t  t |  ƒ j ƒ  | |  _ g  |  _ g  |  _ g  |  _ d  S(   N(   t   superR    t   __init__t   output_patht   prologuet   contentt   epilogue(   t   selfR   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR      s
    			c         C   s&   t  j |  ƒ t |  j d ƒ |  _ |  S(   Nt   w(   t   active_writerst   appendt   openR   t   output_file(   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyt	   __enter__   s    c         C   sw   t  j |  ƒ | d  k rH |  j j |  j ƒ  ƒ |  j j ƒ  d  |  _ n+ d d  l } | j |  j j	 ƒ d  |  _ ‚  d  S(   Niÿÿÿÿ(
   R	   t   removet   NoneR   t   writet	   serializet   closet   ost   unlinkt   name(   R   t   exc_typet	   exc_valuet	   tracebackR   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyt   __exit__   s    	c         C   sî   d d  l  } |  j } t | t ƒ sB | j j t t | ƒ ƒ } n  | r\ | | j d 7} n  |  j } t | t ƒ s’ | j j t t | ƒ ƒ } n  |  j } t | t ƒ sÈ | j j t t | ƒ ƒ } n  | râ | j d | } n  | | | S(   Niÿÿÿÿi   (	   R   R   t
   isinstancet   strt   linesept   joint   mapR   R   (   R   R   R   R   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   "   s    			(   t   __name__t
   __module__R   R   R   R   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR       s   			t   AssemblyWriterc           B   s   e  Z d d  „ Z d „  Z RS(   c      	   C   s7  t  t |  ƒ j | ƒ | d d d d h k rA t d | ƒ ‚ n  | |  _ i d d 6d d 6d d 6d d 6| |  _ | d k rŸ d	 d
 l m } d | |  _ n	 d |  _ d	 d  l	 } | d  k	 rð |  j d j d |  j d | j d | ƒ 7_ n' |  j d j d |  j d | j ƒ 7_ t |  j j ƒ  ƒ d |  _ d  S(   Nt   got   nasmt   masmt   gass   Unknown assembly format: %ss   //t   ;t   #iÿÿÿÿ(   R   s   // +build !noasmt    s7   {escape} Generated by PeachPy {version} from {filename}t   escapet   versiont   filenames'   {escape} Generated by PeachPy {version}i   (   R   R!   R   t
   ValueErrort   assembly_formatt   comment_prefixR   R   R   t   peachpyR   t   formatt   __version__t   lent
   splitlinest   prologue_lines(   R   R   R-   t
   input_pathR   R/   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   9   s*    	
	 c         C   sq   d d  l  } t | | j j j ƒ s0 t d ƒ ‚ | j |  j d d  d |  j	 t
 |  j ƒ ƒ} |  j | 7_ d  S(   NiÿÿÿÿsF   Function must be finalized with an ABI before its assembly can be usedt   line_separatort   line_number(   t   peachpy.x86_64.functionR   t   x86_64t   functiont   ABIFunctiont   AssertionErrorR0   R-   R   R4   R2   R   (   R   R:   R/   t   function_lines(    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyt   add_functionT   s
    	.N(   R   R    R   R   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR!   8   s   t   ImageWriterc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R   R?   R   R   (   R   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   ^   s    c         C   s,   t  j |  ƒ t |  j d d d ƒ|  _ |  S(   Nt   wbt	   bufferingi    (   R	   R
   R   R   R   (   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   b   s    c         C   sw   t  j |  ƒ | d  k rH |  j j |  j ƒ  ƒ |  j j ƒ  d  |  _ n+ d d  l } | j |  j j	 ƒ d  |  _ ‚  d  S(   Niÿÿÿÿ(
   R	   R   R   R   R   t   encodeR   R   R   R   (   R   R   R   R   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   h   s    	c         C   s   t  ƒ  S(   N(   t	   bytearray(   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRB   u   s    (   R   R    R   R   R   RB   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR?   ]   s   			t	   ELFWriterc           B   s&   e  Z d d  „ Z d „  Z d „  Z RS(   c         C   s´   t  t |  ƒ j | ƒ d d l m } d d l m } m } | |  _ | | | ƒ |  _	 | ƒ  |  _
 |  j	 j |  j
 ƒ | d d t ƒ|  _ |  j	 j |  j ƒ d  |  _ d  |  _ d  S(   Niÿÿÿÿ(   t   Image(   t   TextSectiont   ProgramBitsSections   .note.GNU-stackt   allocate(   R   RD   R   t   peachpy.formats.elf.imageRE   t   peachpy.formats.elf.sectionRF   RG   t   abit   imaget   text_sectiont   add_sectiont   Falset   gnu_stack_sectionR   t   text_rela_sectiont   rodata_section(   R   R   RK   R5   RE   RF   RG   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   z   s    		c         C   s
   |  j  j S(   N(   RL   t   as_bytearray(   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRB   ˆ   s    c         C   sÇ  d d  l  } d d l m } t | | j j j ƒ s@ t d ƒ ‚ | j ƒ  } t	 |  j
 j ƒ } t | j j g | | | j j ƒ | ƒ } |  j
 j | 7_ | t	 | ƒ 7} |  j
 j | j j 7_ t |  j
 j | j j ƒ |  j
 _ d } | j j r×|  j d  k r8d d l m } | ƒ  |  _ |  j j |  j ƒ n  |  j j |  j ƒ } t | j j g | | | j j ƒ | ƒ }	 |  j j |	 7_ | t	 |	 ƒ 7} |  j j | j j 7_ t |  j j | j j ƒ |  j _ n  d d l m }
 m } m } t ƒ  } x‘ | j j D]ƒ } |
 ƒ  } | j  d | j! | _! | | j" | _# | j$ | _$ |  j | _% | j& | _' | j( | _) |  j j* j+ | ƒ | | | <q	W| j j, r\|  j- d  k rìd d l m. } | |  j
 |  j j* ƒ |  _- |  j j |  j- ƒ n  d d	 l m/ } m0 } xW | j j, D]F } | | j1 | | j" | | j2 | j" | j3 ƒ } |  j- j+ | ƒ qWn  |
 ƒ  } | j  | _! | | _# t	 | j ƒ | _4 |  j
 | _% | j5 | _' | j | _) |  j j* j+ | ƒ d  S(
   Niÿÿÿÿ(   t   roundupsF   Function must be finalized with an ABI before its assembly can be usedi    (   t   ReadOnlyDataSection(   t   Symbolt   SymbolBindingt
   SymbolTypet   .(   t   RelocationsWithAddendSection(   t   RelocationWithAddendt   RelocationType(6   R8   t   peachpy.utilRT   R   R9   R:   R;   R<   RB   R2   RM   R   RC   t   code_sectiont   alignment_bytet	   alignmentt   maxt   const_sectionRR   R   RJ   RU   RL   RN   t   get_content_sizeRK   t   peachpy.formats.elf.symbolRV   RW   RX   t   dictt   symbolst   mangled_nameR   t   offsett   valuet   sizet   sectiont   localt   bindingt   data_objectt   typet   symtabt   addt   relocationsRQ   RZ   R[   R\   t   x86_64_pc32t   symbolt   program_countert   content_sizet   global_(   R   R:   R/   RT   t   encoded_functiont   code_offsett   code_paddingt   const_offsetRU   t   const_paddingRV   RW   RX   t
   symbol_mapRt   t   const_symbolRZ   R[   R\   t
   relocationt   elf_relocationt   function_symbol(    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR>   ‹   sr    	!$			

		N(   R   R    R   R   RB   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRD   y   s   	t   MachOWriterc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sB   t  t |  ƒ j | ƒ d d l m } | |  _ | | ƒ |  _ d  S(   Niÿÿÿÿ(   RE   (   R   R‚   R   t   peachpy.formats.macho.imageRE   RK   RL   (   R   R   RK   RE   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   Ð   s    	c         C   s   |  j  j ƒ  S(   N(   RL   RB   (   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRB   Ø   s    c         C   s§  d d  l  } t | | j j j ƒ s0 t d ƒ ‚ d d l m } m } m	 } m
 } m } m } d d l m }	 | j ƒ  }
 t |  j j j ƒ } t |
 j j g |	 | |
 j j ƒ | ƒ } |  j j j | 7_ | t | ƒ 7} |  j j j |
 j j 7_ t |  j j j |
 j j ƒ |  j j _ |  j j j } t |
 j j g |	 | |
 j j ƒ | ƒ } |  j j j | 7_ | t | ƒ 7} |  j j j |
 j j 7_ t |  j j j |
 j j ƒ |  j j _ t ƒ  } xt |
 j j D]f } | d | j d | j | j |  j j | | j  ƒ } | j! | _" |  j j# j$ | ƒ | | | <qÚWx	|
 j j% D]û } | | j& | | j  d | | j' d t( ƒ} | j  d | j) } | d	 k r6| d
 @|  j j j | | j  <| d ?d
 @|  j j j | | j  d <| d ?d
 @|  j j j | | j  d <| d ?d
 @|  j j j | | j  d <n  |  j j j% j* | ƒ qQW| d | j | j |  j j d | ƒ} | j! | _" | j+ | _, |  j j# j$ | ƒ d  S(   NiÿÿÿÿsF   Function must be finalized with an ABI before its assembly can be used(   RV   RX   t   SymbolDescriptiont   SymbolVisibilityt
   RelocationR\   (   RT   t   _RY   i   t   is_pc_relativei    iÿ   i   i   i   i   i   i   Ri   (-   R8   R   R9   R:   R;   R<   t   peachpy.formats.macho.symbolRV   RX   R„   R…   R†   R\   R]   RT   RB   R2   RL   RM   R   RC   R^   R_   R`   Ra   Rb   Rv   Re   Rf   Rg   R   t   section_relativeRh   t   definedt   descriptiont   symbol_tablet
   add_symbolRr   t   x86_64_signedRt   t   TrueRu   R
   t   externalt
   visibility(   R   R:   R/   RV   RX   R„   R…   R†   R\   RT   Rx   Ry   Rz   R{   R|   R}   Rt   t   macho_symbolR   t   macho_relocationt   relocation_addendR�   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR>   Û   sV    	.''	&&)	(   R   R    R   RB   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR‚   Ï   s   		t   MSCOFFWriterc           B   s&   e  Z d d  „ Z d „  Z d „  Z RS(   c         C   s˜   t  t |  ƒ j | ƒ d d l m } m } m } | |  _ | |  _ | | | ƒ |  _	 | ƒ  |  _
 |  j	 j |  j
 ƒ | ƒ  |  _ |  j	 j |  j ƒ d  S(   Niÿÿÿÿ(   RE   RF   RU   (   R   R–   R   t   peachpy.formats.mscoffRE   RF   RU   R   RK   RL   RM   RN   t   rdata_section(   R   R   RK   R5   RE   RF   RU   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR     s    		c         C   s   |  j  j ƒ  S(   N(   RL   RB   (   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRB   #  s    c         C   s  d d  l  } t | | j j j ƒ s0 t d ƒ ‚ d d l m } d d l m	 } m
 } m } m } m } | j ƒ  }	 t |  j j ƒ }
 t |	 j j g | |
 |	 j j ƒ |
 ƒ } |  j j | 7_ |
 t | ƒ 7}
 |  j j |	 j j 7_ t |  j j |	 j j ƒ |  j _ |  j j } t |	 j j g | | |	 j j ƒ | ƒ } |  j j | 7_ | t | ƒ 7} |  j j |	 j j 7_ t |  j j |	 j j ƒ |  j _ t ƒ  } xw |	 j j D]i } | ƒ  } | j | _ | | j | _ |  j | _ | j  | _! | j" | _# |  j$ j% | ƒ | | | <q¶Wx� |	 j j& D]� } i | j' d 6| j( d 6| j) d 6| j* d 6| j+ d	 6| j, d
 6} | | j- | j } | | |
 | j | | j. ƒ } |  j j& j/ | ƒ q0W| ƒ  } | j0 | _ |
 | _ |  j | _ | j | _! | j1 | _# |  j$ j% | ƒ d  S(   NiÿÿÿÿsF   Function must be finalized with an ABI before its assembly can be used(   RT   (   RV   RX   t   StorageClassR†   R\   i   i   i   i   i   i	   (2   R8   R   R9   R:   R;   R<   R]   RT   R—   RV   RX   R™   R†   R\   RB   R2   RM   R   RC   R^   R_   R`   Ra   R˜   Rv   Rb   Re   Rf   R   Rh   Ri   Rk   t   non_functiont   symbol_typet   statict   storage_classRL   RŽ   Rr   t   x86_64_relocation_offset32t!   x86_64_relocation_plus_1_offset32t!   x86_64_relocation_plus_2_offset32t!   x86_64_relocation_plus_3_offset32t!   x86_64_relocation_plus_4_offset32t!   x86_64_relocation_plus_5_offset32Ru   Rt   R
   Rg   R‘   (   R   R:   R/   RT   RV   RX   R™   R†   R\   Rx   Ry   Rz   t   rdata_offsett   rdata_paddingR}   Rt   t   mscoff_symbolR   t   relocation_type_mapt   relocation_typet   mscoff_relocationR�   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR>   &  sd    	(!!		





		N(   R   R    R   R   RB   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR–     s   	t   MetadataWriterc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s#   t  t |  ƒ j | ƒ g  |  _ d  S(   N(   R   Rª   R   t   metadata(   R   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   f  s    c         C   sG   d d  l  } t | | j j j ƒ s0 t d ƒ ‚ |  j j | j ƒ d  S(   NiÿÿÿÿsF   Function must be finalized with an ABI before its assembly can be used(   R8   R   R9   R:   R;   R<   R«   R
   (   R   R:   R/   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR>   j  s    	(   R   R    R   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyRª   e  s   	t   JSONMetadataWriterc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  t |  ƒ j | ƒ d  S(   N(   R   R¬   R   (   R   R   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   s  s    c         C   s   d d  l  } | j |  j ƒ S(   Niÿÿÿÿ(   t   jsont   dumpsR«   (   R   R­   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   v  s    (   R   R    R   R   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR¬   r  s   	t   CHeaderWriterc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s—   t  t |  ƒ j | ƒ d d  l } | d  k	 rJ d | j | f g |  _ n d | j g |  _ |  j d d d d d d g 7_ d d	 d d g |  _ d  S(
   Niÿÿÿÿs%   /* Generated by PeachPy %s from %s */s   /* Generated by PeachPy %s */R(   s   #pragma onces   #ifdef __cpluspluss   extern "C" {s   #endifs   } /* extern "C" */(   R   R¯   R   R/   R   R1   R   R   (   R   R   R5   R/   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR   |  s     c         C   s¸   d d  l  } t | | j j j ƒ s0 t d ƒ ‚ | j d  k rE d n t | j ƒ } g  | j	 D]  } t | j
 ƒ d | j ^ q^ } |  j j | d | j d d j | ƒ d ƒ d  S(   NiÿÿÿÿsF   Function must be finalized with an ABI before its assembly can be usedt   voidt    t   (s   , s   );(   R8   R   R9   R:   R;   R<   t   result_typeR   R   t	   argumentst   c_typeR   R   R
   Rg   R   (   R   R:   R/   t   return_typet   argR´   (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR>   “  s    	$0N(   R   R    R   R   R>   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyR¯   {  s   N(   R	   t   objectR    R!   R?   RD   R‚   R–   Rª   R¬   R¯   (    (    (    s;   /torch/pytorch/third_party/python-peachpy/peachpy/writer.pyt   <module>   s   1%VFP	