7ec@sdZddlZddlZddlZddlmZddlmZmZm Z m Z dfdYZ dZ dfd YZ d Zd Zd Zd Zde fdYZdZdfdYZdZdZdfdYZdfdYZejZdS(s/A flow graph representation for Python bytecodeiN(tmisc(t CO_OPTIMIZEDt CO_NEWLOCALSt CO_VARARGStCO_VARKEYWORDSt FlowGraphcBs}eZdZdZd dZdZdZdZdZ dZ dZ d Z d Z d Zd ZRS(cCs[t|_|_td|_tj|_|jj|j|jj|jdS(Ntexit(tBlocktcurrenttentryRRtSettblockstadd(tself((s(/usr/lib64/python2.7/compiler/pyassem.pyt__init__ s cCsr|jre|jrWdGt|jGHdG|jjGHdG|jjGHdG|jjGHnt|GHn||_dS(Ntends nexts prevs (t_debugRtreprtnexttprevt get_children(R tblock((s(/usr/lib64/python2.7/compiler/pyassem.pyt startBlocks  cCs<|dkr|j}n|jj||j|dS(N(tNonetnewBlockRtaddNextR(R R((s(/usr/lib64/python2.7/compiler/pyassem.pyt nextBlocks cCst}|jj||S(N(RR R (R tb((s(/usr/lib64/python2.7/compiler/pyassem.pyR5s cCs|j|jdS(N(RR(R ((s(/usr/lib64/python2.7/compiler/pyassem.pytstartExitBlock:sicCs d|_dS(Ni(R(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt _enable_debug?scCs d|_dS(Ni(R(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt_disable_debugBscGse|jrdG|GHnt|dkrQt|dtrQ|jj|dn|jj|dS(Ns ii(Rtlent isinstanceRRt addOutEdgetemit(R tinst((s(/usr/lib64/python2.7/compiler/pyassem.pyR"Es   %cCst|j|j}|S(slReturn the blocks in reverse postorder i.e. each node appears before all of its successors (t order_blocksR R(R torder((s(/usr/lib64/python2.7/compiler/pyassem.pytgetBlocksInOrderLscCs |jjS(N(R telements(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt getBlocksTscCs|jS(s/Return nodes appropriate for use with dominator(R (R ((s(/usr/lib64/python2.7/compiler/pyassem.pytgetRootWscCs4g}x'|jD]}|j|jqW|S(N(R(textendtgetContainedGraphs(R tlR((s(/usr/lib64/python2.7/compiler/pyassem.pyR+[sN(t__name__t __module__RRRRRRRRRR"R&R(R)R+(((s(/usr/lib64/python2.7/compiler/pyassem.pyR s          csg}t|g}xh|r|j}|kr?qnj|x0|jD]"}|krY|j|qYqYWqWixD]}tr|jr||jdjdkst||jfnj |txd|j D]V}xMj |tj||jrH|jd|k rH|jd}qPqWqWqWfd}|}xv|j|j ||jr|jd}qpn)||k r|j r|j|nsPn|}qpW|S(s8Order blocks so that they are emitted in the right ordericsPx7D]/}x&|D]}|krPqqW|SqWdsLtddS(Nis+circular dependency, cannot find next block(tAssertionError(Rtc(t dominatorst remaining(s(/usr/lib64/python2.7/compiler/pyassem.pyt find_nexts   ( tsettpopR Rtappendt __debug__RRR/t setdefaultt get_followerstdiscardthas_unconditional_transfer(t start_blockt exit_blockR%ttodoRR0R3((R1R2s(/usr/lib64/python2.7/compiler/pyassem.pyR$bsH        2       RcBszeZdZddZdZdZdZdZdZdZ dZ dZ dZ dZ dZRS(itcCsPg|_t|_||_tj|_g|_g|_tjdt_dS(Ni( tinstsR4toutEdgestlabelRt_counttbidRR(R RB((s(/usr/lib64/python2.7/compiler/pyassem.pyRs      cCs,|jrd|j|jfSd|jSdS(Nss (RBRD(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt__repr__s cCs2tt|j}d|j|jdj|fS(Nss (tmaptstrR@RBRDtjoin(R R@((s(/usr/lib64/python2.7/compiler/pyassem.pyt__str__scCs|d}|jj|dS(Ni(R@R6(R R#top((s(/usr/lib64/python2.7/compiler/pyassem.pyR"s cCs|jS(N(R@(R ((s(/usr/lib64/python2.7/compiler/pyassem.pytgetInstructionsscCs|jj|dS(N(RAR (R R((s(/usr/lib64/python2.7/compiler/pyassem.pyR!scCs~|jj|t|jdks=ttt|j|jj|t|jdkszttt|jdS(Ni(RR6RR/RFRGR(R R((s(/usr/lib64/python2.7/compiler/pyassem.pyRs-t RETURN_VALUEt RAISE_VARARGSt JUMP_ABSOLUTEt JUMP_FORWARDt CONTINUE_LOOPcCs?y|jd\}}Wnttfk r1dSX||jkS(sReturns True if there is an unconditional transfer to an other block at the end of this block. This means there is no risk for the bytecode executer to go past this block's bytecode.iN(R@t IndexErrort ValueErrort_uncond_transfer(R RJtarg((s(/usr/lib64/python2.7/compiler/pyassem.pyR;s cCst|j|jS(N(tlistRAR(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyRscCsNt|j}x8|jD]-}|dtjkr|j|dqqW|S(s:Get the whole list of followers, including the next block.ii(R4RR@t PyFlowGraphthasjrelR (R t followersR#((s(/usr/lib64/python2.7/compiler/pyassem.pyR9s cCsbg}xU|jD]J}t|dkr.qn|d}t|dr|j|jqqW|S(sReturn all graphs contained within this block. For example, a MAKE_FUNCTION block will contain a reference to the graph for the function body. itgraph(R@RthasattrR6RY(R t containedR#RJ((s(/usr/lib64/python2.7/compiler/pyassem.pyR+s (RLRMRNRORP(R-R.RCRRERIR"RKR!RRSR;RR9R+(((s(/usr/lib64/python2.7/compiler/pyassem.pyRs        tRAWtFLATtCONVtDONERVcBsAeZejZddddZdZdZdZdZ dZ dZ ddZ d Z d ZeZx%ejD]ZejejeqWeZx%ejD]ZejejeqWd Zd Zd ZiZdZdZeZeZdZdZeZ eZ!eZ"eZ#eZ$eZ%eZ&eZ'eZ(eZ)dZ*e*Z+e*Z,dZ-e.ej/Z0dZ1xDe2j3D]3\Z4Z5e4d dkre4dZe5eet|j|jtks]t|j|jt ks|t|j S(sGet a Python code object( RrR\R/tcomputeStackDeptht flattenGraphR]t convertArgsR^t makeByteCodeR_t newCodeObject(R ((s(/usr/lib64/python2.7/compiler/pyassem.pytgetCode1s    cCs|rtj}|t_nd}x~|jD]s}|d}|dkrKHnt|dkr{dGd|G|GH|d}q+dGd|G|G|dGH|d}q+W|r|t_ndS(Nit SET_LINENOis s%3di(tsyststdoutR@R(R tiotsavetpctttopname((s(/usr/lib64/python2.7/compiler/pyassem.pytdump=s     cspid}x*jD]}t|j|s*   "W CT2  Bn