How to use the xdis.opcodes.base.varargs_op function in xdis

To help you get started, we’ve selected a few xdis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rocky / python-xdis / xdis / opcodes / opcode_36.py View on Github external
# annotations and the closure are pushed on the stack if corresponding
# bit (0-3) is set. They are followed by the code object and the
# qualified name of the function.


# These are new since Python 3.6
#          OP NAME                OPCODE POP PUSH
#---------------------------------------------------
store_op(l,   'STORE_ANNOTATION', 127, 1, 0, is_type="name") # Stores TOS index in name list;
jrel_op(l,    'SETUP_ASYNC_WITH', 154, 2, 8)  # pops __aenter__ and __aexit__; pushed results on stack
def_op(l,     'FORMAT_VALUE',     155, 1, 1)
varargs_op(l, 'BUILD_CONST_KEY_MAP', 156, -2, 1) # TOS is count of kwargs
nargs_op(l,   'CALL_FUNCTION_EX', 142, -2, 1)
def_op(l,     'SETUP_ANNOTATIONS', 85, 1, 1)
varargs_op(l,  'BUILD_STRING',     157, -2, 2)
varargs_op(l,  'BUILD_TUPLE_UNPACK_WITH_CALL', 158)

MAKE_FUNCTION_FLAGS = tuple("default keyword-only annotation closure".split())

def format_MAKE_FUNCTION_flags(flags):
    if flags == 0:
        return "Neither defaults, keyword-only args, annotations, nor closures"
    pattr = ''
    for flag in MAKE_FUNCTION_FLAGS:
        bit = flags & 1
        if bit:
            if pattr:
                pattr += ", " + flag
            else:
                pattr = flag
                pass
            pass
github rocky / python-xdis / xdis / opcodes / opcode_14.py View on Github external
update_pj2,
)

version = 1.4
python_implementation = "CPython"

l = locals()
init_opdata(l, opcode_15, version)

# 1.4 Bytecodes not in 1.5
def_op(l, "UNARY_CALL", 14)
def_op(l, "BINARY_CALL", 26)
def_op(l, "RAISE_EXCEPTION", 81)
def_op(l, "BUILD_FUNCTION", 86)
varargs_op(l, "UNPACK_ARG", 94)  # Number of arguments expected
varargs_op(l, "UNPACK_VARARG", 99)  # Minimal number of arguments
name_op(l, "LOAD_LOCAL", 115)
varargs_op(l, "SET_FUNC_ARGS", 117)  # Argcount
varargs_op(l, "RESERVE_FAST", 123)  # Number of local variables

update_pj2(globals(), l)

opcode_arg_fmt = {"EXTENDED_ARG": format_extended_arg}

finalize_opcodes(l)

def findlinestarts(co, dup_lines=False):
    code = co.co_code
    n = len(code)
    offset = 0
    while offset < n:
        op = code[offset]
github rocky / python-xdis / xdis / opcodes / opcode_35pypy.py View on Github external
l = locals()
init_opdata(l, opcode_35, version, is_pypy=True)

## FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
def_op(l, "FORMAT_VALUE", 155)
def_op(l, "BUILD_STRING", 157)
name_op(l, "LOOKUP_METHOD", 201, 1, 2)
nargs_op(l, "CALL_METHOD", 202, -1, 1)
l["hasvargs"].append(202)

# Used only in single-mode compilation list-comprehension generators
varargs_op(l, "BUILD_LIST_FROM_ARG", 203)

# Used only in assert statements
jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)

# There are no opcodes to remove or change.
# If there were, they'd be listed below.

# FIXME remove (fix uncompyle6)
update_pj3(globals(), l)

finalize_opcodes(l)
github rocky / python-xdis / xdis / opcodes / opcode_35.py View on Github external
# These are new since Python 3.5
#          OP NAME                   OPCODE POP PUSH
#---------------------------------------------------
def_op(l, "BINARY_MATRIX_MULTIPLY",      16,  2,  1)
def_op(l, "INPLACE_MATRIX_MULTIPLY",     17,  2,  1)
def_op(l, "GET_AITER",                   50,  1,  1)
def_op(l, "GET_ANEXT",                   51,  0,  1)
def_op(l, "BEFORE_ASYNC_WITH",           52,  0,  1)
def_op(l, "GET_YIELD_FROM_ITER",         69,  1,  1)
def_op(l, "GET_AWAITABLE",               73,  0,  0)
def_op(l, "WITH_CLEANUP_START",          81,  0,  1)
def_op(l, "WITH_CLEANUP_FINISH",         82,  1,  0)

varargs_op(l, "BUILD_LIST_UNPACK",          149, -1,  1)
varargs_op(l, "BUILD_MAP_UNPACK",           150, -1,  1)
varargs_op(l, "BUILD_MAP_UNPACK_WITH_CALL", 151, -1,  1)
varargs_op(l, "BUILD_TUPLE_UNPACK",         152, -1,  1)
varargs_op(l, "BUILD_SET_UNPACK",           153, -1,  1)

jrel_op(l, "SETUP_ASYNC_WITH",          154,  0,  6)

update_pj3(globals(), l)

def format_BUILD_MAP_UNPACK_WITH_CALL(oparg):
    """The lowest byte of oparg is the count of mappings, the relative
    position of the corresponding callable f is encoded in the second byte
    of oparg."""
    rel_func_pos, count = divmod(oparg, 256)
    return ("%d mappings, function at %d" % (count, count + rel_func_pos))

opcode_arg_fmt = {
github rocky / python-xdis / xdis / opcodes / opcode_3x.py View on Github external
name_op(l, 'DELETE_NAME',           91,  0,  0)   # ""
varargs_op(l, 'UNPACK_SEQUENCE',    92,  0, -1)  # unpacks TOS, arg is the count
jrel_op(l,    'FOR_ITER',           93,  0,  1)

varargs_op(l, 'UNPACK_EX',          94,  0,  0)  # assignment with a starred target; arg is count
store_op(l, 'STORE_ATTR',           95,  2,  0, is_type="name")   # Operand is in name list
name_op(l, 'DELETE_ATTR',           96,  1,  0)   # ""
store_op(l, 'STORE_GLOBAL',         97,  1,  0, is_type="name")   # ""
name_op(l, 'DELETE_GLOBAL',         98,  0,  0)   # ""

# Python 2's DUP_TOPX is gone starting in Python 3.2

const_op(l,   'LOAD_CONST',        100,  0,  1)  # Operand is in const list
name_op(l,    'LOAD_NAME',         101,  0,  1)  # Operand is in name list
varargs_op(l, 'BUILD_TUPLE',       102, -1,  1)  # TOS is count of tuple items
varargs_op(l, 'BUILD_LIST',        103, -1,  1)  # TOS is count of list items
varargs_op(l, 'BUILD_SET',         104, -1,  1)  # TOS is count of set items
def_op(l, 'BUILD_MAP',             105,  0,  1)  # argument is dictionary count to be pushed
name_op(l, 'LOAD_ATTR',            106,  1,  1)  # Operand is in name list
compare_op(l, 'COMPARE_OP',        107,  2,  1)  # Comparison operator
name_op(l, 'IMPORT_NAME',          108,  2,  1)  # Imports TOS and TOS1; module pushed
name_op(l, 'IMPORT_FROM',          109,  0,  1)  # Operand is in name list

jrel_op(l, 'JUMP_FORWARD',         110,  0,  0, fallthrough=False)  # Number of bytes to skip
jabs_op(l, 'JUMP_IF_FALSE_OR_POP', 111, conditional=True)  # Target byte offset from beginning of code
jabs_op(l, 'JUMP_IF_TRUE_OR_POP',  112, conditional=True) # ""
jabs_op(l, 'JUMP_ABSOLUTE',        113,  0,  0, fallthrough=False)  # Target byte offset from beginning of code
jabs_op(l, 'POP_JUMP_IF_FALSE',    114,  2,  1, conditional=True) # ""
jabs_op(l, 'POP_JUMP_IF_TRUE',     115,  2,  1, conditional=True) # ""

name_op(l, 'LOAD_GLOBAL',          116,  0,  1)  # Operand is in name list
github rocky / python-xdis / xdis / opcodes / opcode_2x.py View on Github external
HAVE_ARGUMENT = 90              # Opcodes from here have an argument:

store_op(l, "STORE_NAME",          90,  1,  0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_NAME",          91,  0,  0)  # ""
varargs_op(l, "UNPACK_SEQUENCE",   92, -1,  1)  # TOS is number of tuple items
jrel_op(l, "FOR_ITER",             93,  0,  1)  # TOS is read

store_op(l, "STORE_ATTR",          95,  2,  0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_ATTR",          96,  1,  0)  # ""
store_op(l, "STORE_GLOBAL",        97,  1,  0, is_type="name")  # ""
name_op(l, "DELETE_GLOBAL",        98,  0,  0)  # ""
nargs_op(l, "DUP_TOPX",            99, -1,  2)  # number of items to duplicate
const_op(l, "LOAD_CONST",         100,  0,  1)  # Operand is in const list
name_op(l, "LOAD_NAME",           101,  0,  1)  # Operand is in name list
varargs_op(l, "BUILD_TUPLE",      102, -1,  1)  # TOS is number of tuple items
varargs_op(l, "BUILD_LIST",       103, -1,  1)  # TOS is number of list items
varargs_op(l, "BUILD_MAP",        104,  0,  1)  # TOS is number of kwarg items. Always zero for now
name_op(l, "LOAD_ATTR",           105,  1,  1)  # Operand is in name list
compare_op(l, "COMPARE_OP",       106,  2,  1)  # Comparison operator

name_op(l, "IMPORT_NAME",         107,  2,  2)  # Imports TOS and TOS1; module pushed
name_op(l, "IMPORT_FROM",         108,  0,  1)  # Operand is in name list

jrel_op(l, "JUMP_FORWARD",        110,  0,  0, fallthrough=False)
                                                # Number of bytes to skip
jrel_op(l, "JUMP_IF_FALSE",       111,  1,  1, True)  # ""

jrel_op(l, "JUMP_IF_TRUE",        112,  1,  1, True)  # ""
jabs_op(l, "JUMP_ABSOLUTE",       113,  0,  0, fallthrough=False)
                                                # Target byte offset from beginning of code

name_op(l, "LOAD_GLOBAL",         116,  0,  1)  # Operand is in name list
github rocky / python-xdis / xdis / opcodes / opcode_15.py View on Github external
def_op(l, "BUILD_CLASS", 89, 3, 0)

# HAVE_ARGUMENT = 90               # Opcodes from here have an argument:

store_op(l, "STORE_NAME", 90, 1, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_NAME", 91, 0, 0)  # ""
varargs_op(l, "UNPACK_TUPLE", 92)  # Number of tuple items
def_op(l, "UNPACK_LIST", 93)  # Number of list items
store_op(l, "STORE_ATTR", 95, 2, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_ATTR", 96, 1, 0)  # ""
store_op(l, "STORE_GLOBAL", 97, 1, 0, is_type="name")  # ""
name_op(l, "DELETE_GLOBAL", 98, 0, 0)  # ""

const_op(l, "LOAD_CONST", 100, 0, 1)  # Operand is in const list
name_op(l, "LOAD_NAME", 101, 0, 1)  # Operand is in name list
varargs_op(l, "BUILD_TUPLE", 102, -1, 1)  # Number of tuple items
varargs_op(l, "BUILD_LIST", 103, -1, 1)  # Number of list items
varargs_op(l, "BUILD_MAP", 104, -1, 1)  # Always zero for now
name_op(l, "LOAD_ATTR", 105, 1, 1)  # Operand is in name list
compare_op(l, "COMPARE_OP", 106, 2, 1)  # Comparison operator

name_op(l, "IMPORT_NAME", 107, 2, 1)  # Operand is in name list
name_op(l, "IMPORT_FROM", 108, 0, 1)  # Operand is in name list

jrel_op(l, "JUMP_FORWARD", 110, 0, 0, fallthrough=False)  # Number of bytes to skip
jrel_op(l, "JUMP_IF_FALSE", 111, 1, 1, True)  # ""
jrel_op(l, "JUMP_IF_TRUE", 112, 1, 1, True)  # ""
jabs_op(l, "JUMP_ABSOLUTE", 113, 0, 0, fallthrough=False)  # Target byte offset from beginning of code
def_op(l, "FOR_LOOP", 114)  # Number of bytes to skip

name_op(l, "LOAD_GLOBAL", 116, 0, 1)  # Operand is in name list
github rocky / python-xdis / xdis / opcodes / opcode_35.py View on Github external
version = 3.5
python_implementation = "CPython"

l = locals()

init_opdata(l, opcode_34, version)

# These are removed since Python 3.5.
# Removals happen before adds since
# some opcodes are reused
rm_op(l, "STORE_MAP",                    54)
rm_op(l, "WITH_CLEANUP",                 81)

# Stack effects are change from 3.4
varargs_op(l, "BUILD_MAP",              105, -1, -1)  # arg is count of kwarg items

# These are new since Python 3.5
#          OP NAME                   OPCODE POP PUSH
#---------------------------------------------------
def_op(l, "BINARY_MATRIX_MULTIPLY",      16,  2,  1)
def_op(l, "INPLACE_MATRIX_MULTIPLY",     17,  2,  1)
def_op(l, "GET_AITER",                   50,  1,  1)
def_op(l, "GET_ANEXT",                   51,  0,  1)
def_op(l, "BEFORE_ASYNC_WITH",           52,  0,  1)
def_op(l, "GET_YIELD_FROM_ITER",         69,  1,  1)
def_op(l, "GET_AWAITABLE",               73,  0,  0)
def_op(l, "WITH_CLEANUP_START",          81,  0,  1)
def_op(l, "WITH_CLEANUP_FINISH",         82,  1,  0)

varargs_op(l, "BUILD_LIST_UNPACK",          149, -1,  1)
varargs_op(l, "BUILD_MAP_UNPACK",           150, -1,  1)
github rocky / python-xdis / xdis / opcodes / opcode_15.py View on Github external
# HAVE_ARGUMENT = 90               # Opcodes from here have an argument:

store_op(l, "STORE_NAME", 90, 1, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_NAME", 91, 0, 0)  # ""
varargs_op(l, "UNPACK_TUPLE", 92)  # Number of tuple items
def_op(l, "UNPACK_LIST", 93)  # Number of list items
store_op(l, "STORE_ATTR", 95, 2, 0, is_type="name")  # Operand is in name list
name_op(l, "DELETE_ATTR", 96, 1, 0)  # ""
store_op(l, "STORE_GLOBAL", 97, 1, 0, is_type="name")  # ""
name_op(l, "DELETE_GLOBAL", 98, 0, 0)  # ""

const_op(l, "LOAD_CONST", 100, 0, 1)  # Operand is in const list
name_op(l, "LOAD_NAME", 101, 0, 1)  # Operand is in name list
varargs_op(l, "BUILD_TUPLE", 102, -1, 1)  # Number of tuple items
varargs_op(l, "BUILD_LIST", 103, -1, 1)  # Number of list items
varargs_op(l, "BUILD_MAP", 104, -1, 1)  # Always zero for now
name_op(l, "LOAD_ATTR", 105, 1, 1)  # Operand is in name list
compare_op(l, "COMPARE_OP", 106, 2, 1)  # Comparison operator

name_op(l, "IMPORT_NAME", 107, 2, 1)  # Operand is in name list
name_op(l, "IMPORT_FROM", 108, 0, 1)  # Operand is in name list

jrel_op(l, "JUMP_FORWARD", 110, 0, 0, fallthrough=False)  # Number of bytes to skip
jrel_op(l, "JUMP_IF_FALSE", 111, 1, 1, True)  # ""
jrel_op(l, "JUMP_IF_TRUE", 112, 1, 1, True)  # ""
jabs_op(l, "JUMP_ABSOLUTE", 113, 0, 0, fallthrough=False)  # Target byte offset from beginning of code
def_op(l, "FOR_LOOP", 114)  # Number of bytes to skip

name_op(l, "LOAD_GLOBAL", 116, 0, 1)  # Operand is in name list

jrel_op(l, "SETUP_LOOP", 120, 0, 0, conditional=True)  # Distance to target address
github rocky / python-xdis / xdis / opcodes / opcode_26pypy.py View on Github external
version = 2.6
python_implementation = "PyPy"

l = locals()
init_opdata(l, opcode_26, version, is_pypy=True)

# FIXME: DRY common PYPY opcode additions

# PyPy only
# ----------
name_op(l,   'LOOKUP_METHOD',   201,  1, 2)
nargs_op(l,  'CALL_METHOD',     202, -1, 1)
l['hasnargs'].append(202)

# Used only in single-mode compilation list-comprehension generators
varargs_op(l, 'BUILD_LIST_FROM_ARG', 203)

# Used only in assert statements
jrel_op(l, 'JUMP_IF_NOT_DEBUG',      204, conditional=True)

# FIXME remove (fix uncompyle6)
update_pj2(globals(), l)

finalize_opcodes(l)