Branch data Line data Source code
1 : : #include "Python.h" 2 : : #include "opcode.h" 3 : : #include "internal/pycore_code.h" 4 : : 5 : : /*[clinic input] 6 : : module _opcode 7 : : [clinic start generated code]*/ 8 : : /*[clinic end generated code: output=da39a3ee5e6b4b0d input=117442e66eb376e6]*/ 9 : : 10 : : #include "clinic/_opcode.c.h" 11 : : 12 : : /*[clinic input] 13 : : 14 : : _opcode.stack_effect -> int 15 : : 16 : : opcode: int 17 : : oparg: object = None 18 : : / 19 : : * 20 : : jump: object = None 21 : : 22 : : Compute the stack effect of the opcode. 23 : : [clinic start generated code]*/ 24 : : 25 : : static int 26 : 0 : _opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg, 27 : : PyObject *jump) 28 : : /*[clinic end generated code: output=64a18f2ead954dbb input=461c9d4a44851898]*/ 29 : : { 30 : : int effect; 31 : 0 : int oparg_int = 0; 32 : : int jump_int; 33 [ # # # # : 0 : if (HAS_ARG(opcode)) { # # # # # # # # ] 34 [ # # ]: 0 : if (oparg == Py_None) { 35 : 0 : PyErr_SetString(PyExc_ValueError, 36 : : "stack_effect: opcode requires oparg but oparg was not specified"); 37 : 0 : return -1; 38 : : } 39 : 0 : oparg_int = (int)PyLong_AsLong(oparg); 40 [ # # # # ]: 0 : if ((oparg_int == -1) && PyErr_Occurred()) { 41 : 0 : return -1; 42 : : } 43 : : } 44 [ # # ]: 0 : else if (oparg != Py_None) { 45 : 0 : PyErr_SetString(PyExc_ValueError, 46 : : "stack_effect: opcode does not permit oparg but oparg was specified"); 47 : 0 : return -1; 48 : : } 49 [ # # ]: 0 : if (jump == Py_None) { 50 : 0 : jump_int = -1; 51 : : } 52 [ # # ]: 0 : else if (jump == Py_True) { 53 : 0 : jump_int = 1; 54 : : } 55 [ # # ]: 0 : else if (jump == Py_False) { 56 : 0 : jump_int = 0; 57 : : } 58 : : else { 59 : 0 : PyErr_SetString(PyExc_ValueError, 60 : : "stack_effect: jump must be False, True or None"); 61 : 0 : return -1; 62 : : } 63 : 0 : effect = PyCompile_OpcodeStackEffectWithJump(opcode, oparg_int, jump_int); 64 [ # # ]: 0 : if (effect == PY_INVALID_STACK_EFFECT) { 65 : 0 : PyErr_SetString(PyExc_ValueError, 66 : : "invalid opcode or oparg"); 67 : 0 : return -1; 68 : : } 69 : 0 : return effect; 70 : : } 71 : : 72 : : /*[clinic input] 73 : : 74 : : _opcode.get_specialization_stats 75 : : 76 : : Return the specialization stats 77 : : [clinic start generated code]*/ 78 : : 79 : : static PyObject * 80 : 0 : _opcode_get_specialization_stats_impl(PyObject *module) 81 : : /*[clinic end generated code: output=fcbc32fdfbec5c17 input=e1f60db68d8ce5f6]*/ 82 : : { 83 : : #ifdef Py_STATS 84 : : return _Py_GetSpecializationStats(); 85 : : #else 86 : 0 : Py_RETURN_NONE; 87 : : #endif 88 : : } 89 : : 90 : : static PyMethodDef 91 : : opcode_functions[] = { 92 : : _OPCODE_STACK_EFFECT_METHODDEF 93 : : _OPCODE_GET_SPECIALIZATION_STATS_METHODDEF 94 : : {NULL, NULL, 0, NULL} 95 : : }; 96 : : 97 : : static struct PyModuleDef opcodemodule = { 98 : : PyModuleDef_HEAD_INIT, 99 : : .m_name = "_opcode", 100 : : .m_doc = "Opcode support module.", 101 : : .m_size = 0, 102 : : .m_methods = opcode_functions 103 : : }; 104 : : 105 : : PyMODINIT_FUNC 106 : 3 : PyInit__opcode(void) 107 : : { 108 : 3 : return PyModuleDef_Init(&opcodemodule); 109 : : }