mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
gh-105481: add flags to each instr in the opcode metadata table, to replace opcode.hasarg/hasname/hasconst (#105482)
This commit is contained in:
parent
2211454fe2
commit
be2779c0cb
6 changed files with 681 additions and 625 deletions
|
@ -210,7 +210,7 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(LOAD_CONST, (-- value)) {
|
inst(LOAD_CONST, (-- value)) {
|
||||||
value = GETITEM(frame->f_code->co_consts, oparg);
|
value = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(RETURN_CONST, (--)) {
|
inst(RETURN_CONST, (--)) {
|
||||||
PyObject *retval = GETITEM(frame->f_code->co_consts, oparg);
|
PyObject *retval = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||||
Py_INCREF(retval);
|
Py_INCREF(retval);
|
||||||
assert(EMPTY());
|
assert(EMPTY());
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||||
|
@ -727,7 +727,7 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(INSTRUMENTED_RETURN_CONST, (--)) {
|
inst(INSTRUMENTED_RETURN_CONST, (--)) {
|
||||||
PyObject *retval = GETITEM(frame->f_code->co_consts, oparg);
|
PyObject *retval = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||||
int err = _Py_call_instrumentation_arg(
|
int err = _Py_call_instrumentation_arg(
|
||||||
tstate, PY_MONITORING_EVENT_PY_RETURN,
|
tstate, PY_MONITORING_EVENT_PY_RETURN,
|
||||||
frame, next_instr-1, retval);
|
frame, next_instr-1, retval);
|
||||||
|
@ -924,6 +924,7 @@ dummy_func(
|
||||||
|
|
||||||
inst(INSTRUMENTED_YIELD_VALUE, (retval -- unused)) {
|
inst(INSTRUMENTED_YIELD_VALUE, (retval -- unused)) {
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
|
assert(oparg >= 0); /* make the generator identify this as HAS_ARG */
|
||||||
PyGenObject *gen = _PyFrame_GetGenerator(frame);
|
PyGenObject *gen = _PyFrame_GetGenerator(frame);
|
||||||
gen->gi_frame_state = FRAME_SUSPENDED;
|
gen->gi_frame_state = FRAME_SUSPENDED;
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer - 1);
|
_PyFrame_SetStackPointer(frame, stack_pointer - 1);
|
||||||
|
@ -945,6 +946,7 @@ dummy_func(
|
||||||
// NOTE: It's important that YIELD_VALUE never raises an exception!
|
// NOTE: It's important that YIELD_VALUE never raises an exception!
|
||||||
// The compiler treats any exception raised here as a failed close()
|
// The compiler treats any exception raised here as a failed close()
|
||||||
// or throw() call.
|
// or throw() call.
|
||||||
|
assert(oparg >= 0); /* make the generator identify this as HAS_ARG */
|
||||||
assert(frame != &entry_frame);
|
assert(frame != &entry_frame);
|
||||||
PyGenObject *gen = _PyFrame_GetGenerator(frame);
|
PyGenObject *gen = _PyFrame_GetGenerator(frame);
|
||||||
gen->gi_frame_state = FRAME_SUSPENDED;
|
gen->gi_frame_state = FRAME_SUSPENDED;
|
||||||
|
@ -1040,7 +1042,7 @@ dummy_func(
|
||||||
|
|
||||||
|
|
||||||
inst(STORE_NAME, (v -- )) {
|
inst(STORE_NAME, (v -- )) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
PyObject *ns = LOCALS();
|
PyObject *ns = LOCALS();
|
||||||
int err;
|
int err;
|
||||||
if (ns == NULL) {
|
if (ns == NULL) {
|
||||||
|
@ -1058,7 +1060,7 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(DELETE_NAME, (--)) {
|
inst(DELETE_NAME, (--)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
PyObject *ns = LOCALS();
|
PyObject *ns = LOCALS();
|
||||||
int err;
|
int err;
|
||||||
if (ns == NULL) {
|
if (ns == NULL) {
|
||||||
|
@ -1150,7 +1152,7 @@ dummy_func(
|
||||||
inst(STORE_ATTR, (counter/1, unused/3, v, owner --)) {
|
inst(STORE_ATTR, (counter/1, unused/3, v, owner --)) {
|
||||||
#if ENABLE_SPECIALIZATION
|
#if ENABLE_SPECIALIZATION
|
||||||
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
|
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
next_instr--;
|
next_instr--;
|
||||||
_Py_Specialize_StoreAttr(owner, next_instr, name);
|
_Py_Specialize_StoreAttr(owner, next_instr, name);
|
||||||
DISPATCH_SAME_OPARG();
|
DISPATCH_SAME_OPARG();
|
||||||
|
@ -1161,28 +1163,28 @@ dummy_func(
|
||||||
#else
|
#else
|
||||||
(void)counter; // Unused.
|
(void)counter; // Unused.
|
||||||
#endif /* ENABLE_SPECIALIZATION */
|
#endif /* ENABLE_SPECIALIZATION */
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
int err = PyObject_SetAttr(owner, name, v);
|
int err = PyObject_SetAttr(owner, name, v);
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
ERROR_IF(err, error);
|
ERROR_IF(err, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(DELETE_ATTR, (owner --)) {
|
inst(DELETE_ATTR, (owner --)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
|
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
ERROR_IF(err, error);
|
ERROR_IF(err, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(STORE_GLOBAL, (v --)) {
|
inst(STORE_GLOBAL, (v --)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
int err = PyDict_SetItem(GLOBALS(), name, v);
|
int err = PyDict_SetItem(GLOBALS(), name, v);
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
ERROR_IF(err, error);
|
ERROR_IF(err, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(DELETE_GLOBAL, (--)) {
|
inst(DELETE_GLOBAL, (--)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
int err;
|
int err;
|
||||||
err = PyDict_DelItem(GLOBALS(), name);
|
err = PyDict_DelItem(GLOBALS(), name);
|
||||||
// Can't use ERROR_IF here.
|
// Can't use ERROR_IF here.
|
||||||
|
@ -1208,7 +1210,7 @@ dummy_func(
|
||||||
macro(LOAD_LOCALS) = _LOAD_LOCALS;
|
macro(LOAD_LOCALS) = _LOAD_LOCALS;
|
||||||
|
|
||||||
op(_LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
|
op(_LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
if (PyDict_CheckExact(mod_or_class_dict)) {
|
if (PyDict_CheckExact(mod_or_class_dict)) {
|
||||||
v = PyDict_GetItemWithError(mod_or_class_dict, name);
|
v = PyDict_GetItemWithError(mod_or_class_dict, name);
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
|
@ -1280,7 +1282,7 @@ dummy_func(
|
||||||
#if ENABLE_SPECIALIZATION
|
#if ENABLE_SPECIALIZATION
|
||||||
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
|
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
|
||||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
|
||||||
next_instr--;
|
next_instr--;
|
||||||
_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name);
|
_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name);
|
||||||
DISPATCH_SAME_OPARG();
|
DISPATCH_SAME_OPARG();
|
||||||
|
@ -1288,7 +1290,7 @@ dummy_func(
|
||||||
STAT_INC(LOAD_GLOBAL, deferred);
|
STAT_INC(LOAD_GLOBAL, deferred);
|
||||||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||||
#endif /* ENABLE_SPECIALIZATION */
|
#endif /* ENABLE_SPECIALIZATION */
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
|
||||||
if (PyDict_CheckExact(GLOBALS())
|
if (PyDict_CheckExact(GLOBALS())
|
||||||
&& PyDict_CheckExact(BUILTINS()))
|
&& PyDict_CheckExact(BUILTINS()))
|
||||||
{
|
{
|
||||||
|
@ -1630,7 +1632,7 @@ dummy_func(
|
||||||
};
|
};
|
||||||
|
|
||||||
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
|
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
|
||||||
int load_method = oparg & 1;
|
int load_method = oparg & 1;
|
||||||
#if ENABLE_SPECIALIZATION
|
#if ENABLE_SPECIALIZATION
|
||||||
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
|
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
|
||||||
|
@ -1695,7 +1697,7 @@ dummy_func(
|
||||||
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
||||||
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
||||||
STAT_INC(LOAD_SUPER_ATTR, hit);
|
STAT_INC(LOAD_SUPER_ATTR, hit);
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
|
||||||
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
|
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
|
@ -1706,7 +1708,7 @@ dummy_func(
|
||||||
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
|
||||||
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
|
||||||
STAT_INC(LOAD_SUPER_ATTR, hit);
|
STAT_INC(LOAD_SUPER_ATTR, hit);
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
|
||||||
PyTypeObject *cls = (PyTypeObject *)class;
|
PyTypeObject *cls = (PyTypeObject *)class;
|
||||||
int method_found = 0;
|
int method_found = 0;
|
||||||
res2 = _PySuper_Lookup(cls, self, name,
|
res2 = _PySuper_Lookup(cls, self, name,
|
||||||
|
@ -1744,7 +1746,7 @@ dummy_func(
|
||||||
#if ENABLE_SPECIALIZATION
|
#if ENABLE_SPECIALIZATION
|
||||||
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
|
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
|
||||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
|
||||||
next_instr--;
|
next_instr--;
|
||||||
_Py_Specialize_LoadAttr(owner, next_instr, name);
|
_Py_Specialize_LoadAttr(owner, next_instr, name);
|
||||||
DISPATCH_SAME_OPARG();
|
DISPATCH_SAME_OPARG();
|
||||||
|
@ -1752,7 +1754,7 @@ dummy_func(
|
||||||
STAT_INC(LOAD_ATTR, deferred);
|
STAT_INC(LOAD_ATTR, deferred);
|
||||||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||||
#endif /* ENABLE_SPECIALIZATION */
|
#endif /* ENABLE_SPECIALIZATION */
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
|
||||||
if (oparg & 1) {
|
if (oparg & 1) {
|
||||||
/* Designed to work in tandem with CALL, pushes two values. */
|
/* Designed to work in tandem with CALL, pushes two values. */
|
||||||
PyObject* meth = NULL;
|
PyObject* meth = NULL;
|
||||||
|
@ -1834,7 +1836,7 @@ dummy_func(
|
||||||
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
|
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
|
||||||
DEOPT_IF(dict == NULL, LOAD_ATTR);
|
DEOPT_IF(dict == NULL, LOAD_ATTR);
|
||||||
assert(PyDict_CheckExact((PyObject *)dict));
|
assert(PyDict_CheckExact((PyObject *)dict));
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
|
||||||
uint16_t hint = index;
|
uint16_t hint = index;
|
||||||
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
|
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
|
||||||
if (DK_IS_UNICODE(dict->ma_keys)) {
|
if (DK_IS_UNICODE(dict->ma_keys)) {
|
||||||
|
@ -1922,7 +1924,7 @@ dummy_func(
|
||||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
|
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
|
||||||
STAT_INC(LOAD_ATTR, hit);
|
STAT_INC(LOAD_ATTR, hit);
|
||||||
|
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
|
||||||
Py_INCREF(f);
|
Py_INCREF(f);
|
||||||
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
|
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
|
||||||
// Manipulate stack directly because we exit with DISPATCH_INLINED().
|
// Manipulate stack directly because we exit with DISPATCH_INLINED().
|
||||||
|
@ -1966,7 +1968,7 @@ dummy_func(
|
||||||
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
|
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
|
||||||
DEOPT_IF(dict == NULL, STORE_ATTR);
|
DEOPT_IF(dict == NULL, STORE_ATTR);
|
||||||
assert(PyDict_CheckExact((PyObject *)dict));
|
assert(PyDict_CheckExact((PyObject *)dict));
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR);
|
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR);
|
||||||
PyObject *old_value;
|
PyObject *old_value;
|
||||||
uint64_t new_version;
|
uint64_t new_version;
|
||||||
|
@ -2126,14 +2128,14 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(IMPORT_NAME, (level, fromlist -- res)) {
|
inst(IMPORT_NAME, (level, fromlist -- res)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
res = import_name(tstate, frame, name, fromlist, level);
|
res = import_name(tstate, frame, name, fromlist, level);
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(IMPORT_FROM, (from -- from, res)) {
|
inst(IMPORT_FROM, (from -- from, res)) {
|
||||||
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
|
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||||
res = import_from(tstate, from, name);
|
res = import_from(tstate, from, name);
|
||||||
ERROR_IF(res == NULL, error);
|
ERROR_IF(res == NULL, error);
|
||||||
}
|
}
|
||||||
|
@ -2637,8 +2639,8 @@ dummy_func(
|
||||||
|
|
||||||
inst(KW_NAMES, (--)) {
|
inst(KW_NAMES, (--)) {
|
||||||
assert(kwnames == NULL);
|
assert(kwnames == NULL);
|
||||||
assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts));
|
assert(oparg < PyTuple_GET_SIZE(FRAME_CO_CONSTS));
|
||||||
kwnames = GETITEM(frame->f_code->co_consts, oparg);
|
kwnames = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(INSTRUMENTED_CALL, ( -- )) {
|
inst(INSTRUMENTED_CALL, ( -- )) {
|
||||||
|
|
|
@ -219,6 +219,11 @@ GETITEM(PyObject *v, Py_ssize_t i) {
|
||||||
#define STACK_SHRINK(n) BASIC_STACKADJ(-(n))
|
#define STACK_SHRINK(n) BASIC_STACKADJ(-(n))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Data access macros */
|
||||||
|
#define FRAME_CO_CONSTS (frame->f_code->co_consts)
|
||||||
|
#define FRAME_CO_NAMES (frame->f_code->co_names)
|
||||||
|
|
||||||
/* Local variable macros */
|
/* Local variable macros */
|
||||||
|
|
||||||
#define GETLOCAL(i) (frame->localsplus[i])
|
#define GETLOCAL(i) (frame->localsplus[i])
|
||||||
|
|
|
@ -248,6 +248,8 @@ instr_sequence_use_label(instr_sequence *seq, int lbl) {
|
||||||
static int
|
static int
|
||||||
instr_sequence_addop(instr_sequence *seq, int opcode, int oparg, location loc)
|
instr_sequence_addop(instr_sequence *seq, int opcode, int oparg, location loc)
|
||||||
{
|
{
|
||||||
|
assert(!HAS_ARG(opcode) == !OPCODE_HAS_ARG(opcode));
|
||||||
|
assert(!HAS_CONST(opcode) == !OPCODE_HAS_CONST(opcode));
|
||||||
assert(0 <= opcode && opcode <= MAX_OPCODE);
|
assert(0 <= opcode && opcode <= MAX_OPCODE);
|
||||||
assert(IS_PSEUDO_OPCODE(opcode) == IS_PSEUDO_INSTR(opcode));
|
assert(IS_PSEUDO_OPCODE(opcode) == IS_PSEUDO_INSTR(opcode));
|
||||||
assert(IS_WITHIN_OPCODE_RANGE(opcode));
|
assert(IS_WITHIN_OPCODE_RANGE(opcode));
|
||||||
|
|
768
Python/generated_cases.c.h
generated
768
Python/generated_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -855,9 +855,16 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC000 };
|
||||||
|
#define HAS_ARG_FLAG (1)
|
||||||
|
#define HAS_CONST_FLAG (2)
|
||||||
|
#define HAS_NAME_FLAG (4)
|
||||||
|
#define OPCODE_HAS_ARG(OP) (_PyOpcode_opcode_metadata[(OP)].flags & (HAS_ARG_FLAG))
|
||||||
|
#define OPCODE_HAS_CONST(OP) (_PyOpcode_opcode_metadata[(OP)].flags & (HAS_CONST_FLAG))
|
||||||
|
#define OPCODE_HAS_NAME(OP) (_PyOpcode_opcode_metadata[(OP)].flags & (HAS_NAME_FLAG))
|
||||||
struct opcode_metadata {
|
struct opcode_metadata {
|
||||||
bool valid_entry;
|
bool valid_entry;
|
||||||
enum InstructionFormat instr_format;
|
enum InstructionFormat instr_format;
|
||||||
|
int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define OPCODE_METADATA_FMT(OP) (_PyOpcode_opcode_metadata[(OP)].instr_format)
|
#define OPCODE_METADATA_FMT(OP) (_PyOpcode_opcode_metadata[(OP)].instr_format)
|
||||||
|
@ -868,208 +875,208 @@ struct opcode_metadata {
|
||||||
extern const struct opcode_metadata _PyOpcode_opcode_metadata[512];
|
extern const struct opcode_metadata _PyOpcode_opcode_metadata[512];
|
||||||
#else
|
#else
|
||||||
const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {
|
const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {
|
||||||
[NOP] = { true, INSTR_FMT_IX },
|
[NOP] = { true, INSTR_FMT_IX, 0 },
|
||||||
[RESUME] = { true, INSTR_FMT_IB },
|
[RESUME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_RESUME] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_RESUME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_CLOSURE] = { true, INSTR_FMT_IB },
|
[LOAD_CLOSURE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_FAST_CHECK] = { true, INSTR_FMT_IB },
|
[LOAD_FAST_CHECK] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_FAST] = { true, INSTR_FMT_IB },
|
[LOAD_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_FAST_AND_CLEAR] = { true, INSTR_FMT_IB },
|
[LOAD_FAST_AND_CLEAR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_FAST_LOAD_FAST] = { true, INSTR_FMT_IB },
|
[LOAD_FAST_LOAD_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_CONST] = { true, INSTR_FMT_IB },
|
[LOAD_CONST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_CONST_FLAG },
|
||||||
[STORE_FAST] = { true, INSTR_FMT_IB },
|
[STORE_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_FAST_MAYBE_NULL] = { true, INSTR_FMT_IB },
|
[STORE_FAST_MAYBE_NULL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_FAST_LOAD_FAST] = { true, INSTR_FMT_IB },
|
[STORE_FAST_LOAD_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_FAST_STORE_FAST] = { true, INSTR_FMT_IB },
|
[STORE_FAST_STORE_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_TOP] = { true, INSTR_FMT_IX },
|
[POP_TOP] = { true, INSTR_FMT_IX, 0 },
|
||||||
[PUSH_NULL] = { true, INSTR_FMT_IX },
|
[PUSH_NULL] = { true, INSTR_FMT_IX, 0 },
|
||||||
[END_FOR] = { true, INSTR_FMT_IB },
|
[END_FOR] = { true, INSTR_FMT_IB, 0 },
|
||||||
[INSTRUMENTED_END_FOR] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_END_FOR] = { true, INSTR_FMT_IX, 0 },
|
||||||
[END_SEND] = { true, INSTR_FMT_IX },
|
[END_SEND] = { true, INSTR_FMT_IX, 0 },
|
||||||
[INSTRUMENTED_END_SEND] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_END_SEND] = { true, INSTR_FMT_IX, 0 },
|
||||||
[UNARY_NEGATIVE] = { true, INSTR_FMT_IX },
|
[UNARY_NEGATIVE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[UNARY_NOT] = { true, INSTR_FMT_IX },
|
[UNARY_NOT] = { true, INSTR_FMT_IX, 0 },
|
||||||
[UNARY_INVERT] = { true, INSTR_FMT_IX },
|
[UNARY_INVERT] = { true, INSTR_FMT_IX, 0 },
|
||||||
[BINARY_OP_MULTIPLY_INT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_MULTIPLY_INT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_ADD_INT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_ADD_INT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_SUBTRACT_INT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_SUBTRACT_INT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_MULTIPLY_FLOAT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_MULTIPLY_FLOAT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_ADD_FLOAT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_ADD_FLOAT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_SUBTRACT_FLOAT] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_SUBTRACT_FLOAT] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_ADD_UNICODE] = { true, INSTR_FMT_IBC },
|
[BINARY_OP_ADD_UNICODE] = { true, INSTR_FMT_IBC, 0 },
|
||||||
[BINARY_OP_INPLACE_ADD_UNICODE] = { true, INSTR_FMT_IB },
|
[BINARY_OP_INPLACE_ADD_UNICODE] = { true, INSTR_FMT_IB, 0 },
|
||||||
[BINARY_SUBSCR] = { true, INSTR_FMT_IXC },
|
[BINARY_SUBSCR] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[BINARY_SLICE] = { true, INSTR_FMT_IX },
|
[BINARY_SLICE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[STORE_SLICE] = { true, INSTR_FMT_IX },
|
[STORE_SLICE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[BINARY_SUBSCR_LIST_INT] = { true, INSTR_FMT_IXC },
|
[BINARY_SUBSCR_LIST_INT] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[BINARY_SUBSCR_TUPLE_INT] = { true, INSTR_FMT_IXC },
|
[BINARY_SUBSCR_TUPLE_INT] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[BINARY_SUBSCR_DICT] = { true, INSTR_FMT_IXC },
|
[BINARY_SUBSCR_DICT] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[BINARY_SUBSCR_GETITEM] = { true, INSTR_FMT_IXC },
|
[BINARY_SUBSCR_GETITEM] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[LIST_APPEND] = { true, INSTR_FMT_IB },
|
[LIST_APPEND] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[SET_ADD] = { true, INSTR_FMT_IB },
|
[SET_ADD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_SUBSCR] = { true, INSTR_FMT_IXC },
|
[STORE_SUBSCR] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[STORE_SUBSCR_LIST_INT] = { true, INSTR_FMT_IXC },
|
[STORE_SUBSCR_LIST_INT] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[STORE_SUBSCR_DICT] = { true, INSTR_FMT_IXC },
|
[STORE_SUBSCR_DICT] = { true, INSTR_FMT_IXC, 0 },
|
||||||
[DELETE_SUBSCR] = { true, INSTR_FMT_IX },
|
[DELETE_SUBSCR] = { true, INSTR_FMT_IX, 0 },
|
||||||
[CALL_INTRINSIC_1] = { true, INSTR_FMT_IB },
|
[CALL_INTRINSIC_1] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[CALL_INTRINSIC_2] = { true, INSTR_FMT_IB },
|
[CALL_INTRINSIC_2] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[RAISE_VARARGS] = { true, INSTR_FMT_IB },
|
[RAISE_VARARGS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INTERPRETER_EXIT] = { true, INSTR_FMT_IX },
|
[INTERPRETER_EXIT] = { true, INSTR_FMT_IX, 0 },
|
||||||
[RETURN_VALUE] = { true, INSTR_FMT_IX },
|
[RETURN_VALUE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[INSTRUMENTED_RETURN_VALUE] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_RETURN_VALUE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[RETURN_CONST] = { true, INSTR_FMT_IB },
|
[RETURN_CONST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_CONST_FLAG },
|
||||||
[INSTRUMENTED_RETURN_CONST] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_RETURN_CONST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_CONST_FLAG },
|
||||||
[GET_AITER] = { true, INSTR_FMT_IX },
|
[GET_AITER] = { true, INSTR_FMT_IX, 0 },
|
||||||
[GET_ANEXT] = { true, INSTR_FMT_IX },
|
[GET_ANEXT] = { true, INSTR_FMT_IX, 0 },
|
||||||
[GET_AWAITABLE] = { true, INSTR_FMT_IB },
|
[GET_AWAITABLE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[SEND] = { true, INSTR_FMT_IBC },
|
[SEND] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[SEND_GEN] = { true, INSTR_FMT_IBC },
|
[SEND_GEN] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_YIELD_VALUE] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_YIELD_VALUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[YIELD_VALUE] = { true, INSTR_FMT_IX },
|
[YIELD_VALUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_EXCEPT] = { true, INSTR_FMT_IX },
|
[POP_EXCEPT] = { true, INSTR_FMT_IX, 0 },
|
||||||
[RERAISE] = { true, INSTR_FMT_IB },
|
[RERAISE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[END_ASYNC_FOR] = { true, INSTR_FMT_IX },
|
[END_ASYNC_FOR] = { true, INSTR_FMT_IX, 0 },
|
||||||
[CLEANUP_THROW] = { true, INSTR_FMT_IX },
|
[CLEANUP_THROW] = { true, INSTR_FMT_IX, 0 },
|
||||||
[LOAD_ASSERTION_ERROR] = { true, INSTR_FMT_IX },
|
[LOAD_ASSERTION_ERROR] = { true, INSTR_FMT_IX, 0 },
|
||||||
[LOAD_BUILD_CLASS] = { true, INSTR_FMT_IX },
|
[LOAD_BUILD_CLASS] = { true, INSTR_FMT_IX, 0 },
|
||||||
[STORE_NAME] = { true, INSTR_FMT_IB },
|
[STORE_NAME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[DELETE_NAME] = { true, INSTR_FMT_IB },
|
[DELETE_NAME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[UNPACK_SEQUENCE] = { true, INSTR_FMT_IBC },
|
[UNPACK_SEQUENCE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[UNPACK_SEQUENCE_TWO_TUPLE] = { true, INSTR_FMT_IBC },
|
[UNPACK_SEQUENCE_TWO_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[UNPACK_SEQUENCE_TUPLE] = { true, INSTR_FMT_IBC },
|
[UNPACK_SEQUENCE_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[UNPACK_SEQUENCE_LIST] = { true, INSTR_FMT_IBC },
|
[UNPACK_SEQUENCE_LIST] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[UNPACK_EX] = { true, INSTR_FMT_IB },
|
[UNPACK_EX] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_ATTR] = { true, INSTR_FMT_IBC000 },
|
[STORE_ATTR] = { true, INSTR_FMT_IBC000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[DELETE_ATTR] = { true, INSTR_FMT_IB },
|
[DELETE_ATTR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[STORE_GLOBAL] = { true, INSTR_FMT_IB },
|
[STORE_GLOBAL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[DELETE_GLOBAL] = { true, INSTR_FMT_IB },
|
[DELETE_GLOBAL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_LOCALS] = { true, INSTR_FMT_IB },
|
[LOAD_LOCALS] = { true, INSTR_FMT_IB, 0 },
|
||||||
[LOAD_NAME] = { true, INSTR_FMT_IB },
|
[LOAD_NAME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_FROM_DICT_OR_GLOBALS] = { true, INSTR_FMT_IB },
|
[LOAD_FROM_DICT_OR_GLOBALS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_GLOBAL] = { true, INSTR_FMT_IBC000 },
|
[LOAD_GLOBAL] = { true, INSTR_FMT_IBC000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_GLOBAL_MODULE] = { true, INSTR_FMT_IBC000 },
|
[LOAD_GLOBAL_MODULE] = { true, INSTR_FMT_IBC000, HAS_ARG_FLAG },
|
||||||
[LOAD_GLOBAL_BUILTIN] = { true, INSTR_FMT_IBC000 },
|
[LOAD_GLOBAL_BUILTIN] = { true, INSTR_FMT_IBC000, HAS_ARG_FLAG },
|
||||||
[DELETE_FAST] = { true, INSTR_FMT_IB },
|
[DELETE_FAST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[MAKE_CELL] = { true, INSTR_FMT_IB },
|
[MAKE_CELL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[DELETE_DEREF] = { true, INSTR_FMT_IB },
|
[DELETE_DEREF] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_FROM_DICT_OR_DEREF] = { true, INSTR_FMT_IB },
|
[LOAD_FROM_DICT_OR_DEREF] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LOAD_DEREF] = { true, INSTR_FMT_IB },
|
[LOAD_DEREF] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[STORE_DEREF] = { true, INSTR_FMT_IB },
|
[STORE_DEREF] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[COPY_FREE_VARS] = { true, INSTR_FMT_IB },
|
[COPY_FREE_VARS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BUILD_STRING] = { true, INSTR_FMT_IB },
|
[BUILD_STRING] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BUILD_TUPLE] = { true, INSTR_FMT_IB },
|
[BUILD_TUPLE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BUILD_LIST] = { true, INSTR_FMT_IB },
|
[BUILD_LIST] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[LIST_EXTEND] = { true, INSTR_FMT_IB },
|
[LIST_EXTEND] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[SET_UPDATE] = { true, INSTR_FMT_IB },
|
[SET_UPDATE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BUILD_SET] = { true, INSTR_FMT_IB },
|
[BUILD_SET] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BUILD_MAP] = { true, INSTR_FMT_IB },
|
[BUILD_MAP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[SETUP_ANNOTATIONS] = { true, INSTR_FMT_IX },
|
[SETUP_ANNOTATIONS] = { true, INSTR_FMT_IX, 0 },
|
||||||
[BUILD_CONST_KEY_MAP] = { true, INSTR_FMT_IB },
|
[BUILD_CONST_KEY_MAP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[DICT_UPDATE] = { true, INSTR_FMT_IB },
|
[DICT_UPDATE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[DICT_MERGE] = { true, INSTR_FMT_IB },
|
[DICT_MERGE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[MAP_ADD] = { true, INSTR_FMT_IB },
|
[MAP_ADD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
[INSTRUMENTED_LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC },
|
[LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_SUPER_METHOD] = { true, INSTR_FMT_IBC },
|
[LOAD_SUPER_METHOD] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_ZERO_SUPER_METHOD] = { true, INSTR_FMT_IBC },
|
[LOAD_ZERO_SUPER_METHOD] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_ZERO_SUPER_ATTR] = { true, INSTR_FMT_IBC },
|
[LOAD_ZERO_SUPER_ATTR] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_SUPER_ATTR_ATTR] = { true, INSTR_FMT_IBC },
|
[LOAD_SUPER_ATTR_ATTR] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_SUPER_ATTR_METHOD] = { true, INSTR_FMT_IBC },
|
[LOAD_SUPER_ATTR_METHOD] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_METHOD] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_METHOD] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_MODULE] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_MODULE] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_WITH_HINT] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_WITH_HINT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[LOAD_ATTR_SLOT] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_SLOT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_CLASS] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_CLASS] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_PROPERTY] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_PROPERTY] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[STORE_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IXC000 },
|
[STORE_ATTR_INSTANCE_VALUE] = { true, INSTR_FMT_IXC000, 0 },
|
||||||
[STORE_ATTR_WITH_HINT] = { true, INSTR_FMT_IBC000 },
|
[STORE_ATTR_WITH_HINT] = { true, INSTR_FMT_IBC000, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[STORE_ATTR_SLOT] = { true, INSTR_FMT_IXC000 },
|
[STORE_ATTR_SLOT] = { true, INSTR_FMT_IXC000, 0 },
|
||||||
[COMPARE_OP] = { true, INSTR_FMT_IBC },
|
[COMPARE_OP] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[COMPARE_OP_FLOAT] = { true, INSTR_FMT_IBC },
|
[COMPARE_OP_FLOAT] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[COMPARE_OP_INT] = { true, INSTR_FMT_IBC },
|
[COMPARE_OP_INT] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[COMPARE_OP_STR] = { true, INSTR_FMT_IBC },
|
[COMPARE_OP_STR] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[IS_OP] = { true, INSTR_FMT_IB },
|
[IS_OP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[CONTAINS_OP] = { true, INSTR_FMT_IB },
|
[CONTAINS_OP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[CHECK_EG_MATCH] = { true, INSTR_FMT_IX },
|
[CHECK_EG_MATCH] = { true, INSTR_FMT_IX, 0 },
|
||||||
[CHECK_EXC_MATCH] = { true, INSTR_FMT_IX },
|
[CHECK_EXC_MATCH] = { true, INSTR_FMT_IX, 0 },
|
||||||
[IMPORT_NAME] = { true, INSTR_FMT_IB },
|
[IMPORT_NAME] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[IMPORT_FROM] = { true, INSTR_FMT_IB },
|
[IMPORT_FROM] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_NAME_FLAG },
|
||||||
[JUMP_FORWARD] = { true, INSTR_FMT_IB },
|
[JUMP_FORWARD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[JUMP_BACKWARD] = { true, INSTR_FMT_IB },
|
[JUMP_BACKWARD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[JUMP] = { true, INSTR_FMT_IB },
|
[JUMP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[JUMP_NO_INTERRUPT] = { true, INSTR_FMT_IB },
|
[JUMP_NO_INTERRUPT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[ENTER_EXECUTOR] = { true, INSTR_FMT_IB },
|
[ENTER_EXECUTOR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB },
|
[POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB },
|
[POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB },
|
[POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[POP_JUMP_IF_NONE] = { true, INSTR_FMT_IB },
|
[POP_JUMP_IF_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[JUMP_BACKWARD_NO_INTERRUPT] = { true, INSTR_FMT_IB },
|
[JUMP_BACKWARD_NO_INTERRUPT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[GET_LEN] = { true, INSTR_FMT_IX },
|
[GET_LEN] = { true, INSTR_FMT_IX, 0 },
|
||||||
[MATCH_CLASS] = { true, INSTR_FMT_IB },
|
[MATCH_CLASS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[MATCH_MAPPING] = { true, INSTR_FMT_IX },
|
[MATCH_MAPPING] = { true, INSTR_FMT_IX, 0 },
|
||||||
[MATCH_SEQUENCE] = { true, INSTR_FMT_IX },
|
[MATCH_SEQUENCE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[MATCH_KEYS] = { true, INSTR_FMT_IX },
|
[MATCH_KEYS] = { true, INSTR_FMT_IX, 0 },
|
||||||
[GET_ITER] = { true, INSTR_FMT_IX },
|
[GET_ITER] = { true, INSTR_FMT_IX, 0 },
|
||||||
[GET_YIELD_FROM_ITER] = { true, INSTR_FMT_IX },
|
[GET_YIELD_FROM_ITER] = { true, INSTR_FMT_IX, 0 },
|
||||||
[FOR_ITER] = { true, INSTR_FMT_IBC },
|
[FOR_ITER] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_FOR_ITER] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_FOR_ITER] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[FOR_ITER_LIST] = { true, INSTR_FMT_IBC },
|
[FOR_ITER_LIST] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[FOR_ITER_TUPLE] = { true, INSTR_FMT_IBC },
|
[FOR_ITER_TUPLE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[FOR_ITER_RANGE] = { true, INSTR_FMT_IBC },
|
[FOR_ITER_RANGE] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[FOR_ITER_GEN] = { true, INSTR_FMT_IBC },
|
[FOR_ITER_GEN] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[BEFORE_ASYNC_WITH] = { true, INSTR_FMT_IX },
|
[BEFORE_ASYNC_WITH] = { true, INSTR_FMT_IX, 0 },
|
||||||
[BEFORE_WITH] = { true, INSTR_FMT_IX },
|
[BEFORE_WITH] = { true, INSTR_FMT_IX, 0 },
|
||||||
[WITH_EXCEPT_START] = { true, INSTR_FMT_IX },
|
[WITH_EXCEPT_START] = { true, INSTR_FMT_IX, 0 },
|
||||||
[SETUP_FINALLY] = { true, INSTR_FMT_IX },
|
[SETUP_FINALLY] = { true, INSTR_FMT_IX, 0 },
|
||||||
[SETUP_CLEANUP] = { true, INSTR_FMT_IX },
|
[SETUP_CLEANUP] = { true, INSTR_FMT_IX, 0 },
|
||||||
[SETUP_WITH] = { true, INSTR_FMT_IX },
|
[SETUP_WITH] = { true, INSTR_FMT_IX, 0 },
|
||||||
[POP_BLOCK] = { true, INSTR_FMT_IX },
|
[POP_BLOCK] = { true, INSTR_FMT_IX, 0 },
|
||||||
[PUSH_EXC_INFO] = { true, INSTR_FMT_IX },
|
[PUSH_EXC_INFO] = { true, INSTR_FMT_IX, 0 },
|
||||||
[LOAD_ATTR_METHOD_WITH_VALUES] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_METHOD_WITH_VALUES] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_METHOD_NO_DICT] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_METHOD_NO_DICT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[LOAD_ATTR_METHOD_LAZY_DICT] = { true, INSTR_FMT_IBC00000000 },
|
[LOAD_ATTR_METHOD_LAZY_DICT] = { true, INSTR_FMT_IBC00000000, HAS_ARG_FLAG },
|
||||||
[KW_NAMES] = { true, INSTR_FMT_IB },
|
[KW_NAMES] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_CONST_FLAG },
|
||||||
[INSTRUMENTED_CALL] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_CALL] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[CALL] = { true, INSTR_FMT_IBC00 },
|
[CALL] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_BOUND_METHOD_EXACT_ARGS] = { true, INSTR_FMT_IBC00 },
|
[CALL_BOUND_METHOD_EXACT_ARGS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_PY_EXACT_ARGS] = { true, INSTR_FMT_IBC00 },
|
[CALL_PY_EXACT_ARGS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_PY_WITH_DEFAULTS] = { true, INSTR_FMT_IBC00 },
|
[CALL_PY_WITH_DEFAULTS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_TYPE_1] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_TYPE_1] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_STR_1] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_STR_1] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_TUPLE_1] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_TUPLE_1] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_BUILTIN_CLASS] = { true, INSTR_FMT_IBC00 },
|
[CALL_BUILTIN_CLASS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_BUILTIN_O] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_BUILTIN_O] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_BUILTIN_FAST] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_BUILTIN_FAST] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_BUILTIN_FAST_WITH_KEYWORDS] = { true, INSTR_FMT_IBC00 },
|
[CALL_BUILTIN_FAST_WITH_KEYWORDS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_LEN] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_LEN] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_ISINSTANCE] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_ISINSTANCE] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_LIST_APPEND] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_LIST_APPEND] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_METHOD_DESCRIPTOR_O] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_METHOD_DESCRIPTOR_O] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = { true, INSTR_FMT_IBC00 },
|
[CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[CALL_NO_KW_METHOD_DESCRIPTOR_FAST] = { true, INSTR_FMT_IBC00 },
|
[CALL_NO_KW_METHOD_DESCRIPTOR_FAST] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_CALL_FUNCTION_EX] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_CALL_FUNCTION_EX] = { true, INSTR_FMT_IX, 0 },
|
||||||
[CALL_FUNCTION_EX] = { true, INSTR_FMT_IB },
|
[CALL_FUNCTION_EX] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[MAKE_FUNCTION] = { true, INSTR_FMT_IX },
|
[MAKE_FUNCTION] = { true, INSTR_FMT_IX, 0 },
|
||||||
[SET_FUNCTION_ATTRIBUTE] = { true, INSTR_FMT_IB },
|
[SET_FUNCTION_ATTRIBUTE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[RETURN_GENERATOR] = { true, INSTR_FMT_IX },
|
[RETURN_GENERATOR] = { true, INSTR_FMT_IX, 0 },
|
||||||
[BUILD_SLICE] = { true, INSTR_FMT_IB },
|
[BUILD_SLICE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[FORMAT_VALUE] = { true, INSTR_FMT_IB },
|
[FORMAT_VALUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[COPY] = { true, INSTR_FMT_IB },
|
[COPY] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[BINARY_OP] = { true, INSTR_FMT_IBC },
|
[BINARY_OP] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG },
|
||||||
[SWAP] = { true, INSTR_FMT_IB },
|
[SWAP] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_INSTRUCTION] = { true, INSTR_FMT_IX },
|
[INSTRUMENTED_INSTRUCTION] = { true, INSTR_FMT_IX, 0 },
|
||||||
[INSTRUMENTED_JUMP_FORWARD] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_JUMP_FORWARD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_JUMP_BACKWARD] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_JUMP_BACKWARD] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_POP_JUMP_IF_NONE] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_POP_JUMP_IF_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[INSTRUMENTED_POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB },
|
[INSTRUMENTED_POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[EXTENDED_ARG] = { true, INSTR_FMT_IB },
|
[EXTENDED_ARG] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||||
[CACHE] = { true, INSTR_FMT_IX },
|
[CACHE] = { true, INSTR_FMT_IX, 0 },
|
||||||
[RESERVED] = { true, INSTR_FMT_IX },
|
[RESERVED] = { true, INSTR_FMT_IX, 0 },
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,6 +34,11 @@ RE_PREDICTED = (
|
||||||
UNUSED = "unused"
|
UNUSED = "unused"
|
||||||
BITS_PER_CODE_UNIT = 16
|
BITS_PER_CODE_UNIT = 16
|
||||||
|
|
||||||
|
RESERVED_WORDS = {
|
||||||
|
"co_consts" : "Use FRAME_CO_CONSTS.",
|
||||||
|
"co_names": "Use FRAME_CO_NAMES.",
|
||||||
|
}
|
||||||
|
|
||||||
arg_parser = argparse.ArgumentParser(
|
arg_parser = argparse.ArgumentParser(
|
||||||
description="Generate the code for the interpreter switch.",
|
description="Generate the code for the interpreter switch.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
|
@ -223,6 +228,7 @@ class Formatter:
|
||||||
def cast(self, dst: StackEffect, src: StackEffect) -> str:
|
def cast(self, dst: StackEffect, src: StackEffect) -> str:
|
||||||
return f"({dst.type or 'PyObject *'})" if src.type != dst.type else ""
|
return f"({dst.type or 'PyObject *'})" if src.type != dst.type else ""
|
||||||
|
|
||||||
|
INSTRUCTION_FLAGS = ['HAS_ARG', 'HAS_CONST', 'HAS_NAME']
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Instruction:
|
class Instruction:
|
||||||
|
@ -244,6 +250,7 @@ class Instruction:
|
||||||
output_effects: list[StackEffect]
|
output_effects: list[StackEffect]
|
||||||
unmoved_names: frozenset[str]
|
unmoved_names: frozenset[str]
|
||||||
instr_fmt: str
|
instr_fmt: str
|
||||||
|
flags: int
|
||||||
|
|
||||||
# Set later
|
# Set later
|
||||||
family: parser.Family | None = None
|
family: parser.Family | None = None
|
||||||
|
@ -272,7 +279,17 @@ class Instruction:
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
self.unmoved_names = frozenset(unmoved_names)
|
self.unmoved_names = frozenset(unmoved_names)
|
||||||
if variable_used(inst, "oparg"):
|
flag_data = {
|
||||||
|
'HAS_ARG' : variable_used(inst, "oparg"),
|
||||||
|
'HAS_CONST': variable_used(inst, "FRAME_CO_CONSTS"),
|
||||||
|
'HAS_NAME' : variable_used(inst, "FRAME_CO_NAMES"),
|
||||||
|
}
|
||||||
|
assert set(flag_data.keys()) == set(INSTRUCTION_FLAGS)
|
||||||
|
self.flags = 0
|
||||||
|
for i, name in enumerate(INSTRUCTION_FLAGS):
|
||||||
|
self.flags |= (1<<i) if flag_data[name] else 0
|
||||||
|
|
||||||
|
if flag_data['HAS_ARG']:
|
||||||
fmt = "IB"
|
fmt = "IB"
|
||||||
else:
|
else:
|
||||||
fmt = "IX"
|
fmt = "IX"
|
||||||
|
@ -472,6 +489,7 @@ class MacroInstruction:
|
||||||
initial_sp: int
|
initial_sp: int
|
||||||
final_sp: int
|
final_sp: int
|
||||||
instr_fmt: str
|
instr_fmt: str
|
||||||
|
flags: int
|
||||||
macro: parser.Macro
|
macro: parser.Macro
|
||||||
parts: list[Component | parser.CacheEffect]
|
parts: list[Component | parser.CacheEffect]
|
||||||
predicted: bool = False
|
predicted: bool = False
|
||||||
|
@ -482,8 +500,9 @@ class PseudoInstruction:
|
||||||
"""A pseudo instruction."""
|
"""A pseudo instruction."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
instr_fmt: str
|
|
||||||
targets: list[Instruction]
|
targets: list[Instruction]
|
||||||
|
instr_fmt: str
|
||||||
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
|
@ -493,6 +512,7 @@ class OverriddenInstructionPlaceHolder:
|
||||||
|
|
||||||
AnyInstruction = Instruction | MacroInstruction
|
AnyInstruction = Instruction | MacroInstruction
|
||||||
INSTR_FMT_PREFIX = "INSTR_FMT_"
|
INSTR_FMT_PREFIX = "INSTR_FMT_"
|
||||||
|
INSTR_FLAG_SUFFIX = "_FLAG"
|
||||||
|
|
||||||
|
|
||||||
class Analyzer:
|
class Analyzer:
|
||||||
|
@ -590,6 +610,9 @@ class Analyzer:
|
||||||
thing: parser.InstDef | parser.Macro | parser.Family | None
|
thing: parser.InstDef | parser.Macro | parser.Family | None
|
||||||
thing_first_token = psr.peek()
|
thing_first_token = psr.peek()
|
||||||
while thing := psr.definition():
|
while thing := psr.definition():
|
||||||
|
if ws := [w for w in RESERVED_WORDS if variable_used(thing, w)]:
|
||||||
|
self.error(f"'{ws[0]}' is a reserved word. {RESERVED_WORDS[ws[0]]}", thing)
|
||||||
|
|
||||||
match thing:
|
match thing:
|
||||||
case parser.InstDef(name=name):
|
case parser.InstDef(name=name):
|
||||||
if name in self.instrs:
|
if name in self.instrs:
|
||||||
|
@ -740,7 +763,7 @@ class Analyzer:
|
||||||
return cache, input, output
|
return cache, input, output
|
||||||
|
|
||||||
def analyze_macros_and_pseudos(self) -> None:
|
def analyze_macros_and_pseudos(self) -> None:
|
||||||
"""Analyze each super- and macro instruction."""
|
"""Analyze each macro and pseudo instruction."""
|
||||||
self.macro_instrs = {}
|
self.macro_instrs = {}
|
||||||
self.pseudo_instrs = {}
|
self.pseudo_instrs = {}
|
||||||
for name, macro in self.macros.items():
|
for name, macro in self.macros.items():
|
||||||
|
@ -754,6 +777,7 @@ class Analyzer:
|
||||||
sp = initial_sp
|
sp = initial_sp
|
||||||
parts: list[Component | parser.CacheEffect] = []
|
parts: list[Component | parser.CacheEffect] = []
|
||||||
format = "IB"
|
format = "IB"
|
||||||
|
flags = 0
|
||||||
cache = "C"
|
cache = "C"
|
||||||
for component in components:
|
for component in components:
|
||||||
match component:
|
match component:
|
||||||
|
@ -769,11 +793,12 @@ class Analyzer:
|
||||||
for _ in range(ce.size):
|
for _ in range(ce.size):
|
||||||
format += cache
|
format += cache
|
||||||
cache = "0"
|
cache = "0"
|
||||||
|
flags |= instr.flags
|
||||||
case _:
|
case _:
|
||||||
typing.assert_never(component)
|
typing.assert_never(component)
|
||||||
final_sp = sp
|
final_sp = sp
|
||||||
return MacroInstruction(
|
return MacroInstruction(
|
||||||
macro.name, stack, initial_sp, final_sp, format, macro, parts
|
macro.name, stack, initial_sp, final_sp, format, flags, macro, parts
|
||||||
)
|
)
|
||||||
|
|
||||||
def analyze_pseudo(self, pseudo: parser.Pseudo) -> PseudoInstruction:
|
def analyze_pseudo(self, pseudo: parser.Pseudo) -> PseudoInstruction:
|
||||||
|
@ -782,7 +807,9 @@ class Analyzer:
|
||||||
# Make sure the targets have the same fmt
|
# Make sure the targets have the same fmt
|
||||||
fmts = list(set([t.instr_fmt for t in targets]))
|
fmts = list(set([t.instr_fmt for t in targets]))
|
||||||
assert(len(fmts) == 1)
|
assert(len(fmts) == 1)
|
||||||
return PseudoInstruction(pseudo.name, fmts[0], targets)
|
flags_list = list(set([t.flags for t in targets]))
|
||||||
|
assert(len(flags_list) == 1)
|
||||||
|
return PseudoInstruction(pseudo.name, targets, fmts[0], flags_list[0])
|
||||||
|
|
||||||
def analyze_instruction(
|
def analyze_instruction(
|
||||||
self, instr: Instruction, stack: list[StackEffect], sp: int
|
self, instr: Instruction, stack: list[StackEffect], sp: int
|
||||||
|
@ -1005,10 +1032,19 @@ class Analyzer:
|
||||||
|
|
||||||
# Write type definitions
|
# Write type definitions
|
||||||
self.out.emit(f"enum InstructionFormat {{ {', '.join(format_enums)} }};")
|
self.out.emit(f"enum InstructionFormat {{ {', '.join(format_enums)} }};")
|
||||||
|
for i, flag in enumerate(INSTRUCTION_FLAGS):
|
||||||
|
self.out.emit(f"#define {flag}{INSTR_FLAG_SUFFIX} ({1 << i})");
|
||||||
|
for flag in INSTRUCTION_FLAGS:
|
||||||
|
flag_name = f"{flag}{INSTR_FLAG_SUFFIX}"
|
||||||
|
self.out.emit(
|
||||||
|
f"#define OPCODE_{flag}(OP) "
|
||||||
|
f"(_PyOpcode_opcode_metadata[(OP)].flags & ({flag_name}))")
|
||||||
|
|
||||||
self.out.emit("struct opcode_metadata {")
|
self.out.emit("struct opcode_metadata {")
|
||||||
with self.out.indent():
|
with self.out.indent():
|
||||||
self.out.emit("bool valid_entry;")
|
self.out.emit("bool valid_entry;")
|
||||||
self.out.emit("enum InstructionFormat instr_format;")
|
self.out.emit("enum InstructionFormat instr_format;")
|
||||||
|
self.out.emit("int flags;")
|
||||||
self.out.emit("};")
|
self.out.emit("};")
|
||||||
self.out.emit("")
|
self.out.emit("")
|
||||||
self.out.emit("#define OPCODE_METADATA_FMT(OP) "
|
self.out.emit("#define OPCODE_METADATA_FMT(OP) "
|
||||||
|
@ -1049,23 +1085,25 @@ class Analyzer:
|
||||||
self.out.emit(f" ((OP) == {op}) || \\")
|
self.out.emit(f" ((OP) == {op}) || \\")
|
||||||
self.out.emit(f" 0")
|
self.out.emit(f" 0")
|
||||||
|
|
||||||
|
def emit_metadata_entry(self, name: str, fmt: str, flags: int) -> None:
|
||||||
|
flags_strs = [f"{name}{INSTR_FLAG_SUFFIX}"
|
||||||
|
for i, name in enumerate(INSTRUCTION_FLAGS) if (flags & (1<<i))]
|
||||||
|
flags_s = "0" if not flags_strs else ' | '.join(flags_strs)
|
||||||
|
self.out.emit(
|
||||||
|
f" [{name}] = {{ true, {INSTR_FMT_PREFIX}{fmt}, {flags_s} }},"
|
||||||
|
)
|
||||||
|
|
||||||
def write_metadata_for_inst(self, instr: Instruction) -> None:
|
def write_metadata_for_inst(self, instr: Instruction) -> None:
|
||||||
"""Write metadata for a single instruction."""
|
"""Write metadata for a single instruction."""
|
||||||
self.out.emit(
|
self.emit_metadata_entry(instr.name, instr.instr_fmt, instr.flags)
|
||||||
f" [{instr.name}] = {{ true, {INSTR_FMT_PREFIX}{instr.instr_fmt} }},"
|
|
||||||
)
|
|
||||||
|
|
||||||
def write_metadata_for_macro(self, mac: MacroInstruction) -> None:
|
def write_metadata_for_macro(self, mac: MacroInstruction) -> None:
|
||||||
"""Write metadata for a macro-instruction."""
|
"""Write metadata for a macro-instruction."""
|
||||||
self.out.emit(
|
self.emit_metadata_entry(mac.name, mac.instr_fmt, mac.flags)
|
||||||
f" [{mac.name}] = {{ true, {INSTR_FMT_PREFIX}{mac.instr_fmt} }},"
|
|
||||||
)
|
|
||||||
|
|
||||||
def write_metadata_for_pseudo(self, ps: PseudoInstruction) -> None:
|
def write_metadata_for_pseudo(self, ps: PseudoInstruction) -> None:
|
||||||
"""Write metadata for a macro-instruction."""
|
"""Write metadata for a macro-instruction."""
|
||||||
self.out.emit(
|
self.emit_metadata_entry(ps.name, ps.instr_fmt, ps.flags)
|
||||||
f" [{ps.name}] = {{ true, {INSTR_FMT_PREFIX}{ps.instr_fmt} }},"
|
|
||||||
)
|
|
||||||
|
|
||||||
def write_instructions(self) -> None:
|
def write_instructions(self) -> None:
|
||||||
"""Write instructions to output file."""
|
"""Write instructions to output file."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue