mň
­fIc           @   sť   d  Z  d k Z d k Z d k Td k l Z d d d d g e Z [ d d  Z d d	  Z d
 d  Z	 d
 d d d d  Z
 e	 Z d   Z d   Z d   Z e d j o e   n d S(   s0   Disassembler of Python byte code into mnemonics.N(   t   *(   s   __all__t   dist   disassemblet   distbt   discoc         C   s{  |  d j o t   d Sn t |   t i j o |  i }  n t |  d  o |  i }  n t |  d  o |  i	 }  n t |  d  o |  i
 i   } | i   xŇ | D]t \ } } t |  t i t i t i t i f j o= d | GHy t |  Wn t j
 o } d G| GHn XHqŠ qŠ WnS t |  d  o t |   n5 t |  t  o t |   n t d t |   i  d S(	   sn   Disassemble classes, methods, functions, or code.

    With no argument, disassemble the last traceback.

    Nt   im_funct	   func_codet   __dict__s   Disassembly of %s:s   Sorry:t   co_codes(   don't know how to disassemble %s objects(   t   xt   NoneR   t   typet   typest   InstanceTypet	   __class__t   hasattrR   R   R   t   itemst   sortt   namet   x1t
   MethodTypet   FunctionTypet   CodeTypet	   ClassTypeR   t	   TypeErrort   msgR   t
   isinstancet   strt   disassemble_stringt   __name__(   R	   R   R   R   R   (    (    t    /mit/python/lib/python2.4/dis.pyR      s6     
 +	c         C   sr   |  d j oK y t i }  Wn t j
 o t d  n Xx |  i o |  i }  q< Wn t |  i i	 |  i
  d S(   s2   Disassemble a traceback (default: last traceback).s    no last traceback to disassembleN(   t   tbR
   t   syst   last_tracebackt   AttributeErrort   RuntimeErrort   tb_nextR   t   tb_framet   f_codet   tb_lasti(   R   (    (    R   R   2   s      
 i˙˙˙˙c         C   s}  |  i } t |  } t t |    } t |  }
 d }	 d } d } x1|	 |
 j  o#| |	 } t |  } |	 | j o" |	 d j o Hn d | |	 Gn d G|	 | j o d Gn d G|	 | j o d Gn d Gt |	  i d  Gt | i d  G|	 d	 }	 | t j oht | |	  t | |	 d	  d
 | } d } |	 d }	 | t j o | d } n t |  i d  G| t j o d t |  i |  d Gqs| t j o d |  i | d Gqs| t j o d t |	 |  d Gqs| t j o d |  i | d Gqs| t  j o d t! | d Gqs| t" j o5 | d j o |  i# |  i$ } n d | | d Gqsn HqH Wd S(   s   Disassemble a code object.i    s   %3ds      s   -->s   >>s     i   i   i   i   i   l      i   t   (t   )s   (to N(%   t   coR   t   codet
   findlabelst   labelst   dictt   findlinestartst
   linestartst   lent   nt   it   extended_argR
   t   freet   ct   ordt   opt   lastit   reprt   rjustt   opnamet   ljustt   HAVE_ARGUMENTt   opargt   EXTENDED_ARGt   hasconstt	   co_constst   hasnamet   co_namest   hasjrelt   haslocalt   co_varnamest
   hascomparet   cmp_opt   hasfreet   co_cellvarst   co_freevars(   R*   R9   R4   R+   R-   R0   R6   R?   R5   R3   R2   R8   (    (    R   R   <   s`     	 
  
*
c         C   sň  t  |   } t |   }	 d } xÍ| |	 j  oż|  | } t |  }
 | | j o d Gn d G| | j o d Gn d Gt
 |  i d  Gt |
 i d  G| d } |
 t j o7t |  |  t |  | d  d	 } | d
 } t
 |  i d  G|
 t j o- | o d t
 | |  d Gqäd | Gqč|
 t j o- | d  j	 o d | | d Gqäd | Gqč|
 t j o d t
 | |  d Gqč|
 t j o' | o d | | d Gqäd | Gqč|
 t j o d t | d Gqčn Hq! Wd  S(   Ni    s   -->s      s   >>s     i   i   i   i   i   i   R(   R)   s   (%d)s   (to (   R,   R+   R-   R1   R2   R3   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   RA   t	   constantsRC   t   namesR
   RE   RF   t   varnamesRH   RI   (   R+   R9   RO   RN   RM   R-   R?   R6   R3   R2   R8   (    (    R   R   m   sJ     
  
&
c         C   sů   g  } t |   } d } xÚ | | j  oĚ |  | } t |  } | d } | t j o t |  |  t |  | d  d } | d } d } | t j o | | } n | t j o
 | } n | d j o" | | j o | i |  qě qđ q q W| S(   s`   Detect all offsets in a byte code which are jump targets.

    Return the list of offsets.

    i    i   i   i   i˙˙˙˙N(   R-   R1   R+   R2   R3   R6   R7   R8   R>   R?   t   labelRE   t   hasjabst   append(   R+   R6   R3   R-   R2   R?   RP   R8   (    (    R   R,      s*      

&

c   
      c   s  g  } |  i d d d  D] } | t |  q ~ } g  } |  i d d d  D] } | t |  qR ~ } d } |  i	 } d } x] t | |  D]L \ }	 } |	 o/ | | j o | | f V| } n | |	 7} n | | 7} q W| | j o | | f Vn d S(   s   Find the offsets in a byte code which are start of lines in the source.

    Generate pairs (offset, lineno) as described in Python/compile.c.

    i    Ni   i   (   t   _[1]R+   t	   co_lnotabR6   R7   t   byte_incrementst   line_incrementsR
   t
   lastlinenot   co_firstlinenot   linenot   addrt   zipt	   byte_incrt	   line_incr(
   R+   R6   RZ   RS   RV   R]   RY   RU   RW   R\   (    (    R   R/   ą   s      77	 

c          C   sć   t  i d o_ t  i d o! t  i i d  t  i d  n t  i d } | p | d j o
 d } qs n d } | d j o t  i } n t	 |  } | i
   } | d j	 o | i   n d } t | | d  }  t |   d S(   s*   Simple test program to disassemble a file.i   i   s   usage: python dis.py [-|file]
t   -s   <stdin>t   execN(   R    t   argvt   stderrt   writet   exitt   fnR
   t   stdint   ft   opent   readt   sourcet   closet   compileR+   R   (   R+   Rf   Ri   Rd   (    (    R   t   _testÇ   s$     t   __main__(   t   __doc__R    R   t   opcodet   __all__t   _opcodes_allR
   R   R   R   R   R   R,   R/   Rl   R   (   Rp   R   R,   R   R   R    Rq   R/   R   Rl   R   R   (    (    R   t   ?   s    		&
1(			