3
^H                 @   sL   d Z ddlmZmZ ddlmZ ddlmZ dd Zdd Zdd	 ZeZ	d
S )zCPython disassembly functions specific to wordcode from Python 3.6+
    )PYTHON3PYTHON_VERSION)op_has_argumentc             c   s  d}yt | }W n" tk
r2   | j} t | }Y nX t| d trxtd|dD ]V}t| | }t||rt| |d  |B }||jkr|d> nd}nd }|||fV  qPW n`x^td|dD ]N}| | }t||r| |d  |B }||jkr|d> nd}nd }|||fV  qW d S )Nr            )	len	TypeErrorco_code
isinstancestrrangeordr   EXTENDED_ARG)codeopcextended_argnioparg r   J/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/xdis/wordcode.pyunpack_opargs_wordcode   s*    

r   c             C   sf   g }x\t | |D ]N\}}}|dk	r||jkr:|d | }n||jkr|}nq||kr|j| qW |S )zReturns a list of instruction offsets in the supplied bytecode
    which are the targets of some sort of jump instruction.
    Nr   )r   JREL_OPSJABS_OPSappend)r   r   Zoffsetsoffsetr   r   jump_offsetr   r   r   get_jump_targets5   s    

r   c       	      C   s   i }d}xt | |D ]\}}}|dkrD|j|g }|j| |||< |}||jkrVd}|dk	rd}||jkrz|d | }n||jkr|}|dkr|j|g }|j| |||< qW |S )am  Returns a dictionary where the key is an offset and the values are
    a list of instruction offsets which can get run before that
    instruction. This includes jump instructions as well as non-jump
    instructions. Therefore, the keys of the dictionary are reachible
    instructions. The values of the dictionary may be useful in control-flow
    analysis.
    r   r   Nr   r    r    )r   getr   ZNOFOLLOWr   r   )	r   r   Zoffset2prevZprev_offsetr   r   r   Z	prev_listr   r   r   r   get_jump_target_mapsG   s*    




r"   N)
__doc__xdisr   r   Zxdis.bytecoder   r   r   r"   
findlabelsr   r   r   r   <module>   s   