codekingpro/portable-devtools
114k
1 2"""3opcode module - potentially shared between dis and other modules which4operate on bytecodes (e.g. peephole optimizers).5"""6 7 8__all__ = ["cmp_op", "stack_effect", "hascompare", "opname", "opmap",9 "HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",10 "hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]11 12import builtins13import _opcode14from _opcode import stack_effect15 16from _opcode_metadata import (_specializations, _specialized_opmap, opmap, # noqa: F40117 HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa: F40118EXTENDED_ARG = opmap['EXTENDED_ARG']19 20opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]21for m in (opmap, _specialized_opmap):22 for op, i in m.items():23 opname[i] = op24 25cmp_op = ('<', '<=', '==', '!=', '>', '>=')26 27# These lists are documented as part of the dis module's API28hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]29hasconst = [op for op in opmap.values() if _opcode.has_const(op)]30hasname = [op for op in opmap.values() if _opcode.has_name(op)]31hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]32hasjrel = hasjump # for backward compatibility33hasjabs = []34hasfree = [op for op in opmap.values() if _opcode.has_free(op)]35haslocal = [op for op in opmap.values() if _opcode.has_local(op)]36hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]37 38 39_intrinsic_1_descs = _opcode.get_intrinsic1_descs()40_intrinsic_2_descs = _opcode.get_intrinsic2_descs()41_special_method_names = _opcode.get_special_method_names()42_common_constants = [builtins.AssertionError, builtins.NotImplementedError,43 builtins.tuple, builtins.all, builtins.any]44_nb_ops = _opcode.get_nb_ops()45 46hascompare = [opmap["COMPARE_OP"]]47 48_cache_format = {49 "LOAD_GLOBAL": {50 "counter": 1,51 "index": 1,52 "module_keys_version": 1,53 "builtin_keys_version": 1,54 },55 "BINARY_OP": {56 "counter": 1,57 "descr": 4,58 },59 "UNPACK_SEQUENCE": {60 "counter": 1,61 },62 "COMPARE_OP": {63 "counter": 1,64 },65 "CONTAINS_OP": {66 "counter": 1,67 },68 "FOR_ITER": {69 "counter": 1,70 },71 "LOAD_SUPER_ATTR": {72 "counter": 1,73 },74 "LOAD_ATTR": {75 "counter": 1,76 "version": 2,77 "keys_version": 2,78 "descr": 4,79 },80 "STORE_ATTR": {81 "counter": 1,82 "version": 2,83 "index": 1,84 },85 "CALL": {86 "counter": 1,87 "func_version": 2,88 },89 "CALL_KW": {90 "counter": 1,91 "func_version": 2,92 },93 "STORE_SUBSCR": {94 "counter": 1,95 },96 "SEND": {97 "counter": 1,98 },99 "JUMP_BACKWARD": {100 "counter": 1,101 },102 "TO_BOOL": {103 "counter": 1,104 "version": 2,105 },106 "POP_JUMP_IF_TRUE": {107 "counter": 1,108 },109 "POP_JUMP_IF_FALSE": {110 "counter": 1,111 },112 "POP_JUMP_IF_NONE": {113 "counter": 1,114 },115 "POP_JUMP_IF_NOT_NONE": {116 "counter": 1,117 },118}119 120_inline_cache_entries = {121 name : sum(value.values()) for (name, value) in _cache_format.items()122}123 