ó o”þfc@sdZddlZddlZddlZddlmZddlmZmZm Z m Z dfd„ƒYZ d„Z dfd „ƒYZ d Zd Zd Zd Zde fd„ƒYZd„Zdfd„ƒYZd„Zd„Zdfd„ƒYZdfd„ƒYZeƒjZdS(s/A flow graph representation for Python bytecodeiÿÿÿÿN(tmisc(t CO_OPTIMIZEDt CO_NEWLOCALSt CO_VARARGStCO_VARKEYWORDSt FlowGraphcBs}eZd„Zd„Zd d„Zd„Zd„ZdZd„Z d„Z d„Z d „Z d „Z d „Zd „ZRS(cCs[tƒ|_|_tdƒ|_tjƒ|_|jj|jƒ|jj|jƒdS(Ntexit(tBlocktcurrenttentryRRtSettblockstadd(tself((s(/usr/lib64/python2.7/compiler/pyassem.pyt__init__ s cCsr|jre|jrWdGt|jƒGHdG|jjGHdG|jjGHdG|jjƒGHnt|ƒ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|jƒdS(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|dtƒrQ|jj|dƒn|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 |jjƒS(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'|jƒD]}|j|jƒƒqW|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          csèg}tƒ‰|g}xh|r‚|jƒ}|ˆkr?qnˆj|ƒx0|jƒD]"}|ˆkrY|j|ƒqYqYWqWi‰xȈD]À}tr×|jr×||jdjdks×t||jfƒ‚nˆj |tƒƒxc|j ƒD]U}xLˆj |tƒƒj|ƒ|jrH|jd|k rH|jd}qPqq÷WqW‡‡fd†}|}xu|j|ƒˆj |ƒ|jr¥|jd}qon)||k rÎ|j ƒ rÎ|j|ƒnˆsØPn|ƒ}qo|S(s8Order blocks so that they are emitted in the right ordericsPx7ˆD]/}x&ˆ|D]}|ˆkrPqqW|SqWdsLtdƒ‚dS(Nis+circular dependency, cannot find next block(tAssertionError(Rtc(t dominatorst remaining(s(/usr/lib64/python2.7/compiler/pyassem.pyt find_nextŒs   ( 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       RcBszeZdZdd„Zd„Zd„Zd„Zd„Zd„Zd„Z dZ d„Z d„Z d„Z d„ZRS(itcCsPg|_tƒ|_||_tj|_g|_g|_tjdt_dS(Ni( tinstsR4toutEdgestlabelRt_counttbidRR(R RB((s(/usr/lib64/python2.7/compiler/pyassem.pyR¨s      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.pytgetInstructionsÀscCs|jj|ƒdS(N(RAR (R R((s(/usr/lib64/python2.7/compiler/pyassem.pyR!ÃscCs~|jj|ƒt|jƒdks=ttt|jƒƒ‚|jj|ƒt|jƒdkszttt|jƒƒ‚dS(Ni(RR6RR/RFRGR(R R((s(/usr/lib64/python2.7/compiler/pyassem.pyRÆs-t RETURN_VALUEt RAISE_VARARGSt JUMP_ABSOLUTEt JUMP_FORWARDt CONTINUE_LOOPcCs?y|jd\}}Wnttfk r1dSX||jkS(sÆReturns 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.iÿÿÿÿN(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.pyRÚscCsNt|jƒ}x8|jD]-}|dtjkr|j|dƒqqW|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.pyR9Ýs cCsbg}xU|jD]J}t|ƒdkr.qn|d}t|dƒr|j|jƒqqW|S(s¨Return 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.pyR¥s        tRAWtFLATtCONVtDONERVcBsAeZejZdddd„Zd„Zd„Zd„Zd„Z d„Z d„Z dd„Z d „Z d „ZeƒZx%ejD]ZejejeƒqˆWeƒZx%ejD]Zejejeƒq¹Wd „Zd „Zd „ZiZd„Zd„ZeZeZd„Zd„ZeZ eZ!eZ"eZ#eZ$eZ%eZ&eZ'eZ(eZ)d„Z*e*Z+e*Z,d„Z-e.ej/ƒZ0d„Z1xDe2ƒj3ƒD]3\Z4Z5e4d dkrªe4dZe5eet‚|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     cspi‰d}x*ˆjƒD]}t|jƒƒˆ|s*   "W CTÿ2  Bn