{fc@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|jrnj|txd|jD]V}xMj|tj||j r|j d|k r|j d}qPqWqWqWfd}|}xv|j|j ||jrw|jd}qAn)||k r|j r|j|nsPn|}qAW|S(s8Order blocks so that they are emitted in the right orderics>x7D]/}x&|D]}|krPqqW|SqWdS(N((Rtc(t dominatorst remaining(s(/usr/lib64/python2.7/compiler/pyassem.pyt find_nexts   ( tsettpopR Rtappendt __debug__Rt setdefaultt get_followersRtdiscardthas_unconditional_transfer(t start_blockt exit_blockR%ttodoRR/R2((R0R1s(/usr/lib64/python2.7/compiler/pyassem.pyR$bsH               RcBszeZdZddZdZdZdZdZdZdZ dZ dZ dZ dZ dZRS(itcCsPg|_t|_||_tj|_g|_g|_tjdt_dS(Ni( tinstsR3toutEdgestlabelRt_counttbidRR(R RA((s(/usr/lib64/python2.7/compiler/pyassem.pyRs      cCs,|jrd|j|jfSd|jSdS(Nss (RARC(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt__repr__s cCs2tt|j}d|j|jdj|fS(Nss (tmaptstrR?RARCtjoin(R R?((s(/usr/lib64/python2.7/compiler/pyassem.pyt__str__scCs|d}|jj|dS(Ni(R?R5(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(R@R (R R((s(/usr/lib64/python2.7/compiler/pyassem.pyR!scCs$|jj||jj|dS(N(RR5R(R R((s(/usr/lib64/python2.7/compiler/pyassem.pyRst 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 RItarg((s(/usr/lib64/python2.7/compiler/pyassem.pyR:s cCst|j|jS(N(tlistR@R(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(R3RR?t PyFlowGraphthasjrelR (R t followersR#((s(/usr/lib64/python2.7/compiler/pyassem.pyR8s 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?RthasattrR5RX(R t containedR#RI((s(/usr/lib64/python2.7/compiler/pyassem.pyR+s (RKRLRMRNRO(R-R.RBRRDRHR"RJR!RRRR:RR8R+(((s(/usr/lib64/python2.7/compiler/pyassem.pyRs        tRAWtFLATtCONVtDONERUcBsAeZejZddddZdZdZdZdZ 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 dkre4dZe5ee(RGR(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyRscCsdjtt|jS(NR>(RGRERR(R ((s(/usr/lib64/python2.7/compiler/pyassem.pyRs(R-R.RRRRRR(((s(/usr/lib64/python2.7/compiler/pyassem.pyRKs     tStackDepthTrackercBseZddZi&dd6dd6dd6dd6dd 6dd 6dd 6dd 6dd 6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6dd!6dd"6dd#6dd$6dd%6dd&6dd'6d(d)6d(d*6dd+6dd,6Zd;d<gZd/Zd0Zd1Zd2Zd3Z d4Z d5Z d6Z d7Z d8Zd9Zd:ZRS(=ic Csd}d}x|D]}|d}|r0|Gn|jj|d}|dk r^||}nxA|jD]6\}} |t| |krh| }||}PqhqhW|dkrt||d} | dk r|| |d}qn||kr|}n|r|G|GHqqW|S(Nii(teffectRRtpatternsRtgetattr( R R?tdebugRtmaxDepthRsRtdeltatpatt pat_deltatmeth((s(/usr/lib64/python2.7/compiler/pyassem.pyRs.         itPOP_TOPitDUP_TOPt LIST_APPENDtSET_ADDitMAP_ADDsSLICE+1sSLICE+2sSLICE+3s STORE_SLICE+0s STORE_SLICE+1s STORE_SLICE+2is STORE_SLICE+3sDELETE_SLICE+0sDELETE_SLICE+1sDELETE_SLICE+2sDELETE_SLICE+3t STORE_SUBSCRt DELETE_SUBSCRt PRINT_ITEMRKt YIELD_VALUEt EXEC_STMTt BUILD_CLASSt STORE_NAMEt STORE_ATTRt DELETE_ATTRt STORE_GLOBALt BUILD_MAPt COMPARE_OPt STORE_FASTt IMPORT_STARt IMPORT_NAMEt IMPORT_FROMt LOAD_ATTRit SETUP_EXCEPTt SETUP_FINALLYtFOR_ITERt WITH_CLEANUPtBINARY_tLOAD_cCs|dS(Ni((R R((s(/usr/lib64/python2.7/compiler/pyassem.pytUNPACK_SEQUENCEscCs | dS(Ni((R R((s(/usr/lib64/python2.7/compiler/pyassem.pyt BUILD_TUPLEscCs | dS(Ni((R R((s(/usr/lib64/python2.7/compiler/pyassem.pyt BUILD_LISTscCs | dS(Ni((R R((s(/usr/lib64/python2.7/compiler/pyassem.pyt BUILD_SETscCs"t|d\}}||d S(Nii(R(R targcRR((s(/usr/lib64/python2.7/compiler/pyassem.pyt CALL_FUNCTIONscCs|j|dS(Ni(R (R R ((s(/usr/lib64/python2.7/compiler/pyassem.pytCALL_FUNCTION_VARscCs|j|dS(Ni(R (R R ((s(/usr/lib64/python2.7/compiler/pyassem.pytCALL_FUNCTION_KWscCs|j|dS(Ni(R (R R ((s(/usr/lib64/python2.7/compiler/pyassem.pytCALL_FUNCTION_VAR_KWscCs| S(N((R R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt MAKE_FUNCTIONscCs| S(N((R R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt MAKE_CLOSUREscCs$|dkrdS|dkr dSdS(Niiii((R R ((s(/usr/lib64/python2.7/compiler/pyassem.pyt BUILD_SLICEs  cCs|S(N((R R ((s(/usr/lib64/python2.7/compiler/pyassem.pytDUP_TOPXs(Ri(Ri(R-R.RRRRRRRR R R R RRRR(((s(/usr/lib64/python2.7/compiler/pyassem.pyRsl              (RRRRtcompilerRtcompiler.constsRRRRRR$RR[R\R]R^RURRoRdRRRR(((s(/usr/lib64/python2.7/compiler/pyassem.pyts*   "W CT2  Bn