_OPNAME_WIDTH = 20
_OPARG_WIDTH = 5
+def _get_cache_size(opname):
+ return _inline_cache_entries.get(opname, 0)
+
def _get_jump_target(op, arg, offset):
"""Gets the bytecode offset of the jump target if this is a jump instruction.
Otherwise return None.
"""
deop = _deoptop(op)
- caches = _inline_cache_entries[deop]
+ caches = _get_cache_size(_all_opname[deop])
if deop in hasjrel:
if _is_backward_jump(deop):
arg = -arg
@property
def end_offset(self):
"""End index of the cache entries following the operation."""
- return self.cache_offset + _inline_cache_entries[self.opcode]*2
+ return self.cache_offset + _get_cache_size(_all_opname[self.opcode])*2
@property
def jump_target(self):
argrepr = ''
positions = Positions(*next(co_positions, ()))
deop = _deoptop(op)
- caches = _inline_cache_entries[deop]
+ caches = _get_cache_size(_all_opname[deop])
op = code[offset]
if arg is not None:
# Set argval to the dereferenced value of the argument when
else:
# Each CACHE takes 2 bytes
is_current_instr = instr.offset <= lasti \
- <= instr.offset + 2 * _inline_cache_entries[_deoptop(instr.opcode)]
+ <= instr.offset + 2 * _get_cache_size(_all_opname[_deoptop(instr.opcode)])
print(instr._disassemble(lineno_width, is_current_instr, offset_width),
file=file)
if exception_entries:
continue
op = code[i]
deop = _deoptop(op)
- caches = _inline_cache_entries[deop]
+ caches = _get_cache_size(_all_opname[deop])
if deop in hasarg:
arg = code[i+1] | extended_arg
extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
},
}
-_inline_cache_entries = [
- sum(_cache_format.get(opname[opcode], {}).values()) for opcode in range(256)
-]
+_inline_cache_entries = {
+ name : sum(value.values()) for (name, value) in _cache_format.items()
+}
specialized_opcodes = [
op.lower()
for op in opcode._specializations
- if opcode._inline_cache_entries[opcode.opmap[op]]
+ if opcode._inline_cache_entries.get(op, 0)
]
self.assertIn('load_attr', specialized_opcodes)
self.assertIn('binary_subscr', specialized_opcodes)
iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")
iobj.write("\nconst uint8_t _PyOpcode_Caches[256] = {\n")
- for i, entries in enumerate(opcode["_inline_cache_entries"]):
- if entries:
- iobj.write(f" [{opname[i]}] = {entries},\n")
+ for name, entries in opcode["_inline_cache_entries"].items():
+ iobj.write(f" [{name}] = {entries},\n")
iobj.write("};\n")
deoptcodes = {}