mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-105481: Generate the opcode lists in dis from data extracted from bytecodes.c (#106758)
This commit is contained in:
parent
3535ef1eec
commit
40f3f11a77
16 changed files with 402 additions and 158 deletions
|
@ -147,6 +147,63 @@ _opcode_has_jump_impl(PyObject *module, int opcode)
|
|||
|
||||
/*[clinic input]
|
||||
|
||||
_opcode.has_free -> bool
|
||||
|
||||
opcode: int
|
||||
|
||||
Return True if the opcode accesses a free variable, False otherwise.
|
||||
|
||||
Note that 'free' in this context refers to names in the current scope
|
||||
that are referenced by inner scopes or names in outer scopes that are
|
||||
referenced from this scope. It does not include references to global
|
||||
or builtin scopes.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_opcode_has_free_impl(PyObject *module, int opcode)
|
||||
/*[clinic end generated code: output=d81ae4d79af0ee26 input=117dcd5c19c1139b]*/
|
||||
{
|
||||
return PyUnstable_OpcodeIsValid(opcode) &&
|
||||
PyUnstable_OpcodeHasFree(opcode);
|
||||
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
_opcode.has_local -> bool
|
||||
|
||||
opcode: int
|
||||
|
||||
Return True if the opcode accesses a local variable, False otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_opcode_has_local_impl(PyObject *module, int opcode)
|
||||
/*[clinic end generated code: output=da5a8616b7a5097b input=9a798ee24aaef49d]*/
|
||||
{
|
||||
return PyUnstable_OpcodeIsValid(opcode) &&
|
||||
PyUnstable_OpcodeHasLocal(opcode);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
_opcode.has_exc -> bool
|
||||
|
||||
opcode: int
|
||||
|
||||
Return True if the opcode sets an exception handler, False otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_opcode_has_exc_impl(PyObject *module, int opcode)
|
||||
/*[clinic end generated code: output=41b68dff0ec82a52 input=db0e4bdb9bf13fa5]*/
|
||||
{
|
||||
return PyUnstable_OpcodeIsValid(opcode) &&
|
||||
PyUnstable_OpcodeHasExc(opcode);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
_opcode.get_specialization_stats
|
||||
|
||||
Return the specialization stats
|
||||
|
@ -171,6 +228,9 @@ opcode_functions[] = {
|
|||
_OPCODE_HAS_CONST_METHODDEF
|
||||
_OPCODE_HAS_NAME_METHODDEF
|
||||
_OPCODE_HAS_JUMP_METHODDEF
|
||||
_OPCODE_HAS_FREE_METHODDEF
|
||||
_OPCODE_HAS_LOCAL_METHODDEF
|
||||
_OPCODE_HAS_EXC_METHODDEF
|
||||
_OPCODE_GET_SPECIALIZATION_STATS_METHODDEF
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
|
196
Modules/clinic/_opcode.c.h
generated
196
Modules/clinic/_opcode.c.h
generated
|
@ -401,6 +401,200 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_opcode_has_free__doc__,
|
||||
"has_free($module, /, opcode)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the opcode accesses a free variable, False otherwise.\n"
|
||||
"\n"
|
||||
"Note that \'free\' in this context refers to names in the current scope\n"
|
||||
"that are referenced by inner scopes or names in outer scopes that are\n"
|
||||
"referenced from this scope. It does not include references to global\n"
|
||||
"or builtin scopes.");
|
||||
|
||||
#define _OPCODE_HAS_FREE_METHODDEF \
|
||||
{"has_free", _PyCFunction_CAST(_opcode_has_free), METH_FASTCALL|METH_KEYWORDS, _opcode_has_free__doc__},
|
||||
|
||||
static int
|
||||
_opcode_has_free_impl(PyObject *module, int opcode);
|
||||
|
||||
static PyObject *
|
||||
_opcode_has_free(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_item = { &_Py_ID(opcode), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"opcode", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "has_free",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
int opcode;
|
||||
int _return_value;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
opcode = _PyLong_AsInt(args[0]);
|
||||
if (opcode == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = _opcode_has_free_impl(module, opcode);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_opcode_has_local__doc__,
|
||||
"has_local($module, /, opcode)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the opcode accesses a local variable, False otherwise.");
|
||||
|
||||
#define _OPCODE_HAS_LOCAL_METHODDEF \
|
||||
{"has_local", _PyCFunction_CAST(_opcode_has_local), METH_FASTCALL|METH_KEYWORDS, _opcode_has_local__doc__},
|
||||
|
||||
static int
|
||||
_opcode_has_local_impl(PyObject *module, int opcode);
|
||||
|
||||
static PyObject *
|
||||
_opcode_has_local(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_item = { &_Py_ID(opcode), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"opcode", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "has_local",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
int opcode;
|
||||
int _return_value;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
opcode = _PyLong_AsInt(args[0]);
|
||||
if (opcode == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = _opcode_has_local_impl(module, opcode);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_opcode_has_exc__doc__,
|
||||
"has_exc($module, /, opcode)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the opcode sets an exception handler, False otherwise.");
|
||||
|
||||
#define _OPCODE_HAS_EXC_METHODDEF \
|
||||
{"has_exc", _PyCFunction_CAST(_opcode_has_exc), METH_FASTCALL|METH_KEYWORDS, _opcode_has_exc__doc__},
|
||||
|
||||
static int
|
||||
_opcode_has_exc_impl(PyObject *module, int opcode);
|
||||
|
||||
static PyObject *
|
||||
_opcode_has_exc(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_item = { &_Py_ID(opcode), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"opcode", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "has_exc",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
int opcode;
|
||||
int _return_value;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
opcode = _PyLong_AsInt(args[0]);
|
||||
if (opcode == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = _opcode_has_exc_impl(module, opcode);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_opcode_get_specialization_stats__doc__,
|
||||
"get_specialization_stats($module, /)\n"
|
||||
"--\n"
|
||||
|
@ -418,4 +612,4 @@ _opcode_get_specialization_stats(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return _opcode_get_specialization_stats_impl(module);
|
||||
}
|
||||
/*[clinic end generated code: output=ae2b2ef56d582180 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=e507bf14fb2796f8 input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue