compiler.pyassem
index
/usr/lib/python2.2/compiler/pyassem.py

A flow graph representation for Python bytecode

 
Modules
            
dis
compiler.misc
new
string
sys
types
 
Classes
            
Block
FlowGraph
PyFlowGraph
LineAddrTable
StackDepthTracker
TupleArg
 
class Block
       
   Methods defined here:
__init__(self, label='')
__repr__(self)
__str__(self)
addInEdge(self, block)
addNext(self, block)
addOutEdge(self, block)
emit(self, inst)
getContainedGraphs(self)
Return all graphs contained within this block.
 
For example, a MAKE_FUNCTION block will contain a reference to
the graph for the function body.
getInstructions(self)
get_children(self)
pruneNext(self)
Remove bogus edge for unconditional transfers
 
Each block has a next edge that accounts for implicit control
transfers, e.g. from a JUMP_IF_FALSE to the block that will be
executed if the test is true.
 
These edges must remain for the current assembler code to
work. If they are removed, the dfs_postorder gets things in
weird orders.  However, they shouldn't be there for other
purposes, e.g. conversion to SSA form.  This method will
remove the next edge when it follows an unconditional control
transfer.

Data and non-method functions defined here:
__doc__ = None
__module__ = 'compiler.pyassem'
_count = 0
_uncond_transfer = ('RETURN_VALUE', 'RAISE_VARARGS', 'JUMP_ABSOLUTE', 'JUMP_FORWARD', 'CONTINUE_LOOP')
 
class FlowGraph
       
   Methods defined here:
__init__(self)
_disable_debug(self)
_enable_debug(self)
emit(self, *inst)
fixupOrder(self, blocks, default_next)
Fixup bad order introduced by DFS.
fixupOrderForward(self, blocks, default_next)
Make sure all JUMP_FORWARDs jump forward
fixupOrderHonorNext(self, blocks, default_next)
Fix one problem with DFS.
 
The DFS uses child block, but doesn't know about the special
"next" block.  As a result, the DFS can order blocks so that a
block isn't next to the right block for implicit control
transfers.
getBlocks(self)
getBlocksInOrder(self)
Return the blocks in reverse postorder
 
i.e. each node appears before all of its successors
getContainedGraphs(self)
getRoot(self)
Return nodes appropriate for use with dominator
newBlock(self)
nextBlock(self, block=None)
startBlock(self, block)
startExitBlock(self)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'compiler.pyassem'
_debug = 0
 
class LineAddrTable
      lnotab
 
This class builds the lnotab, which is documented in compile.c.
Here's a brief recap:
 
For each SET_LINENO instruction after the first one, two bytes are
added to lnotab.  (In some cases, multiple two-byte entries are
added.)  The first byte is the distance in bytes between the
instruction for the last SET_LINENO and the current SET_LINENO.
The second byte is offset in line numbers.  If either offset is
greater than 255, multiple two-byte entries are added -- see
compile.c for the delicate details.
 
   Methods defined here:
__init__(self)
addCode(self, *args)
getCode(self)
getTable(self)
nextLine(self, lineno)

Data and non-method functions defined here:
__doc__ = 'lnotab\n\n This class builds the lnotab, whi...e\n compile.c for the delicate details.\n '
__module__ = 'compiler.pyassem'
 
class PyFlowGraph(FlowGraph)
       
   Methods defined here:
__init__(self, name, filename, args=(), optimized=0, klass=None)
_convert_COMPARE_OP(self, arg)
_convert_DELETE_ATTR = _convert_NAME(self, arg)
_convert_DELETE_FAST = _convert_LOAD_FAST(self, arg)
_convert_DELETE_GLOBAL = _convert_NAME(self, arg)
_convert_DELETE_NAME = _convert_NAME(self, arg)
_convert_DEREF(self, arg)
_convert_IMPORT_FROM = _convert_NAME(self, arg)
_convert_IMPORT_NAME = _convert_NAME(self, arg)
_convert_LOAD_ATTR = _convert_NAME(self, arg)
_convert_LOAD_CLOSURE(self, arg)
_convert_LOAD_CONST(self, arg)
_convert_LOAD_DEREF = _convert_DEREF(self, arg)
_convert_LOAD_FAST(self, arg)
_convert_LOAD_GLOBAL = _convert_NAME(self, arg)
_convert_LOAD_NAME(self, arg)
_convert_NAME(self, arg)
_convert_STORE_ATTR = _convert_NAME(self, arg)
_convert_STORE_DEREF = _convert_DEREF(self, arg)
_convert_STORE_FAST = _convert_LOAD_FAST(self, arg)
_convert_STORE_GLOBAL = _convert_NAME(self, arg)
_convert_STORE_NAME = _convert_NAME(self, arg)
_lookupName(self, name, list)
Return index of name in list, appending if necessary
 
This routine uses a list instead of a dictionary, because a
dictionary can't store two different keys if the keys have the
same value but different types, e.g. 2 and 2L.  The compiler
must treat these two separately, so it does an explicit type
comparison before comparing the values.
checkFlag(self, flag)
computeStackDepth(self)
Compute the max stack depth.
 
Approach is to compute the stack effect of each basic block.
Then find the path through the code with the largest total
effect.
convertArgs(self)
Convert arguments from symbolic to concrete form
dump(self, io=None)
flattenGraph(self)
Arrange the blocks in order and resolve jumps
getCode(self)
Get a Python code object
getConsts(self)
Return a tuple for the const slot of the code object
 
Must convert references to code (MAKE_FUNCTION) to code
objects recursively.
makeByteCode(self)
newCodeObject(self)
setCellVars(self, names)
setDocstring(self, doc)
setFlag(self, flag)
setFreeVars(self, names)
sort_cellvars(self)
Sort cellvars in the order of varnames and prune from freevars.
super_init = __init__(self)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'compiler.pyassem'
_cmp = ['<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is', 'is not', 'exception match', 'BAD']
_converters = {'COMPARE_OP': <function _convert_COMPARE_OP>, 'DELETE_ATTR': <function _convert_NAME>, 'DELETE_FAST': <function _convert_LOAD_FAST>, 'DELETE_GLOBAL': <function _convert_NAME>, 'DELETE_NAME': <function _convert_NAME>, 'DEREF': <function _convert_DEREF>, 'IMPORT_FROM': <function _convert_NAME>, 'IMPORT_NAME': <function _convert_NAME>, 'LOAD_ATTR': <function _convert_NAME>, 'LOAD_CLOSURE': <function _convert_LOAD_CLOSURE>, ...}
hasjabs = <compiler.misc.Set instance>
hasjrel = <compiler.misc.Set instance>
i = 119
opnum = {'<109>': 109, '<115>': 115, '<117>': 117, '<118>': 118, '<123>': 123, '<128>': 128, '<129>': 129, '<138>': 138, '<139>': 139, '<144>': 144, ...}

Methods inherited from FlowGraph:
_disable_debug(self)
_enable_debug(self)
emit(self, *inst)
fixupOrder(self, blocks, default_next)
Fixup bad order introduced by DFS.
fixupOrderForward(self, blocks, default_next)
Make sure all JUMP_FORWARDs jump forward
fixupOrderHonorNext(self, blocks, default_next)
Fix one problem with DFS.
 
The DFS uses child block, but doesn't know about the special
"next" block.  As a result, the DFS can order blocks so that a
block isn't next to the right block for implicit control
transfers.
getBlocks(self)
getBlocksInOrder(self)
Return the blocks in reverse postorder
 
i.e. each node appears before all of its successors
getContainedGraphs(self)
getRoot(self)
Return nodes appropriate for use with dominator
newBlock(self)
nextBlock(self, block=None)
startBlock(self, block)
startExitBlock(self)

Data and non-method functions inherited from FlowGraph:
_debug = 0
 
class StackDepthTracker
       
   Methods defined here:
BUILD_LIST(self, count)
BUILD_SLICE(self, argc)
BUILD_TUPLE(self, count)
CALL_FUNCTION(self, argc)
CALL_FUNCTION_KW(self, argc)
CALL_FUNCTION_VAR(self, argc)
CALL_FUNCTION_VAR_KW(self, argc)
DUP_TOPX(self, argc)
MAKE_CLOSURE(self, argc)
MAKE_FUNCTION(self, argc)
UNPACK_SEQUENCE(self, count)
findDepth(self, insts, debug=0)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'compiler.pyassem'
effect = {'BUILD_CLASS': -2, 'BUILD_MAP': 1, 'COMPARE_OP': -1, 'DELETE_ATTR': -1, 'DELETE_SLICE+0': -1, 'DELETE_SLICE+1': -2, 'DELETE_SLICE+2': -2, 'DELETE_SLICE+3': -3, 'DELETE_SUBSCR': -2, 'DUP_TOP': 1, ...}
patterns = [('BINARY_', -1), ('LOAD_', 1)]
 
class TupleArg
      Helper for marking func defs with nested tuples in arglist
 
   Methods defined here:
__init__(self, count, names)
__repr__(self)
getName(self)

Data and non-method functions defined here:
__doc__ = 'Helper for marking func defs with nested tuples in arglist'
__module__ = 'compiler.pyassem'
 
Functions
            
dfs_postorder(b, seen)
Depth-first search of tree rooted at b, return in postorder
findDepth(self, insts, debug=0) method of StackDepthTracker instance
getArgCount(args)
isJump(opname)
twobyte(val)
Convert an int argument into high and low bytes
xxx_sort(l)
 
Data
             CONV = 'CONV'
CO_NEWLOCALS = 2
CO_OPTIMIZED = 1
CO_VARARGS = 4
CO_VARKEYWORDS = 8
DONE = 'DONE'
FLAT = 'FLAT'
RAW = 'RAW'
__file__ = '/usr/lib/python2.2/compiler/pyassem.pyc'
__name__ = 'compiler.pyassem'