3
^              
   @   s   d Z ddlZddlmZ eddZyTdej_ dej_ dej_ d	ej_ d
ej	_ dej
_ dej_ dej_ dej_ dej_ W n   Y nX dZdZG dd deZdS )zjPython instruction class
Extracted from Python 3 dis module but generalized to
allow running on Python 2.
    N)
namedtuple_Instructionzlopname opcode optype inst_size arg argval argrepr has_arg offset starts_line is_jump_target has_extended_argz!Human readable name for operationzNumeric code for operationz6Numeric argument to operation (if any), otherwise Nonez4Resolved arg value (if known), otherwise same as argz0Human readable description of operation argumentz3True if instruction has an operand, otherwise Falsez1Start index of operation within bytecode sequencez4Line started by this opcode (if any), otherwise Nonez1True if other code jumps to here, otherwise FalsezATrue there were EXTENDED_ARG opcodes before this, otherwise False      c               @   s*   e Zd ZdZdddZdd Zdd	 Zd
S )Instructiona
  Details for a bytecode operation

       Defined fields:
         opname - human readable name for operation
         opcode - numeric code for operation
         optype - opcode classification. One of
            compare, const, free, jabs, jrel, local, name, nargs
         inst_size - number of bytes the instruction occupies
         arg - numeric argument to operation (if any), otherwise None
         argval - resolved arg value (if known), otherwise same as arg
         argrepr - human readable description of operation argument
         has_arg - True opcode takes an argument. In that case,
                   argval and argepr will have that value. False
                   if this opcode doesn't take an argument. In that case,
                   don't look at argval or argrepr.
         offset - start index of operation within bytecode sequence
         starts_line - line started by this opcode (if any), otherwise None
         is_jump_target - True if other code jumps to here,
                          'loop' if this is a loop beginning, which
                          in Python can be determined jump to an earlier offset.
                          Otherwise False
         has_extended_arg - True if the instruction was built from EXTENDED_ARG
                            opcodes
         fallthrough - True if the instruction can (not must) fall through to the next
                       instruction. Note conditionals are in this category, but
                       returns, raise, and unconditional jumps are not
       Fc             C   s  g }|rt ddddg}|r| jdk	r|rjd| }|j|| j  |jd|  | jr|jd|d   qd	| }|j|| j  n|jd|d   |r| r|jd
 n
|jd | jr|s|jd qd| j g| }| js|jd n
|jd |s|jt| jjd |rd| j }| jdkr8|d 7 }| jdkrj| j	r`|d| j
d  7 }n|d7 }n(| jdkr|d| j
d? | j
d f 7 }|j|d  |j| jjt | j
dk	r| j}	|r| jdkr|jdt| j
  n| jdkr| j| j
 | j }
|jdt|
  n| j|kr>|jd|	  d}	np| jdkrntjd|	 rn|jd|	  d}	n@| jdkrtjd|	 r|jd|	  d}	n|jt| j
 n"|o|	s|jt| j
jt |	r|jd|	  dj|j S )!zFormat instruction details for inclusion in disassembly output

        *lineno_width* sets the width of the line number field (0 omits it)
        *mark_as_current* inserts a '-->' marker arrow as part of the line
        namelocalZcomparefreeNz%%%dd:
    z%%%dd:z-->z   z>>zL%d:
z     z|%02x   r   z %02x   z 00z
 %02x %02x   |jabsLjrelz(%s)constz\sr   z      )setstarts_lineappendis_jump_targetoffsetreprrjustopcodeZ	inst_sizehas_argargopnameljust_OPNAME_WIDTHargreproptypestrresearch_OPARG_WIDTHjoinrstrip)selflineno_widthmark_as_currentZ
asm_formatZ
show_bytesfieldsZindexed_operand
lineno_fmtZhex_bytecoder#   argval r1   M/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/xdis/instruction.pydisassembleL   s    	





zInstruction.disassemblec             C   s
   | j dkS )zB
        Return True if instruction is some sort of jump.
        r   r   )r   r   )r$   )r+   r1   r1   r2   is_jump   s    zInstruction.is_jumpc             C   s   | j  o| j| jk S )z>
        Return True if instruction is jump backwards
        )r4   r   r0   )r+   r1   r1   r2   jumps_forward   s    zInstruction.jumps_forwardN)r   FFF)__name__
__module____qualname____doc__r3   r4   r5   r1   r1   r1   r2   r   .   s      
^r   )r9   r&   collectionsr   r   r    r   r   r0   r#   r   r   r   r   Zhas_extended_argr"   r(   r   r1   r1   r1   r2   <module>   s(   