Home | History | Annotate | Download | only in Python

Lines Matching refs:codestr

44     assert(_Py_OPCODE(codestr[i]) == LOAD_CONST); \
45 assert(PyList_GET_SIZE(consts) > (Py_ssize_t)get_arg(codestr, i)); \
46 _x = PyList_GET_ITEM(consts, get_arg(codestr, i)); \
76 lastn_const_start(const _Py_CODEUNIT *codestr, Py_ssize_t i, Py_ssize_t n)
82 if (_Py_OPCODE(codestr[i]) == LOAD_CONST) {
84 while (i > 0 && _Py_OPCODE(codestr[i-1]) == EXTENDED_ARG) {
91 assert(_Py_OPCODE(codestr[i]) == NOP ||
92 _Py_OPCODE(codestr[i]) == EXTENDED_ARG);
99 find_op(const _Py_CODEUNIT *codestr, Py_ssize_t i)
101 while (_Py_OPCODE(codestr[i]) == EXTENDED_ARG) {
110 get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i)
113 unsigned int oparg = _Py_OPARG(codestr[i]);
114 if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) {
116 if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) {
118 if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) {
128 fill_nops(_Py_CODEUNIT *codestr, Py_ssize_t start, Py_ssize_t end)
130 memset(codestr + start, NOP, (end - start) * sizeof(_Py_CODEUNIT));
137 set_arg(_Py_CODEUNIT *codestr, Py_ssize_t i, unsigned int oparg)
139 unsigned int curarg = get_arg(codestr, i);
149 write_op_arg(codestr + i + 1 - curilen, _Py_OPCODE(codestr[i]), oparg, newilen);
150 fill_nops(codestr, i + 1 - curilen + newilen, i + 1);
158 copy_op_arg(_Py_CODEUNIT *codestr, Py_ssize_t i, unsigned char op,
165 write_op_arg(codestr + maxi - ilen, op, oparg, ilen);
166 fill_nops(codestr, i, maxi - ilen);
174 Called with codestr pointing to the first LOAD_CONST.
180 fold_tuple_on_constants(_Py_CODEUNIT *codestr, Py_ssize_t c_start,
218 return copy_op_arg(codestr, c_start, LOAD_CONST, len_consts, opcode_end);
225 Called with codestr pointing to the BINOP.
232 fold_binops_on_constants(_Py_CODEUNIT *codestr, Py_ssize_t c_start,
317 return copy_op_arg(codestr, c_start, LOAD_CONST, len_consts, opcode_end);
321 fold_unaryops_on_constants(_Py_CODEUNIT *codestr, Py_ssize_t c_start,
365 return copy_op_arg(codestr, c_start, LOAD_CONST, len_consts, opcode_end);
431 _Py_CODEUNIT *codestr = NULL;
462 codestr = (_Py_CODEUNIT *)PyMem_Malloc(codelen);
463 if (codestr == NULL) {
467 memcpy(codestr, PyBytes_AS_STRING(code), codelen);
470 blocks = markblocks(codestr, codelen);
477 for (i=find_op(codestr, 0) ; i<codelen ; i=nexti) {
478 opcode = _Py_OPCODE(codestr[i]);
480 while (op_start >= 1 && _Py_OPCODE(codestr[op_start-1]) == EXTENDED_ARG) {
485 while (nexti < codelen && _Py_OPCODE(codestr[nexti]) == EXTENDED_ARG)
487 nextop = nexti < codelen ? _Py_OPCODE(codestr[nexti]) : 0;
501 fill_nops(codestr, op_start, i + 1);
502 codestr[nexti] = PACKOPARG(POP_JUMP_IF_TRUE, _Py_OPARG(codestr[nexti]));
511 j = get_arg(codestr, i);
516 codestr[i] = PACKOPARG(opcode, j^1);
517 fill_nops(codestr
527 !PyObject_IsTrue(PyList_GET_ITEM(consts, get_arg(codestr, i))))
529 fill_nops(codestr, op_start, nexti + 1);
541 j = get_arg(codestr, i);
543 h = lastn_const_start(codestr, op_start, j);
548 (_Py_OPARG(codestr[nexti]) == PyCmp_IN ||
549 _Py_OPARG(codestr[nexti]) == PyCmp_NOT_IN)) ||
551 h = fold_tuple_on_constants(codestr, h, i + 1, opcode,
562 j != get_arg(codestr, nexti) ||
566 fill_nops(codestr, op_start, nexti + 1);
568 codestr[op_start] = PACKOPARG(ROT_TWO, 0);
569 fill_nops(codestr, op_start + 1, nexti + 1);
572 codestr[op_start] = PACKOPARG(ROT_THREE, 0);
573 codestr[op_start + 1] = PACKOPARG(ROT_TWO, 0);
574 fill_nops(codestr, op_start + 2, nexti + 1);
596 h = lastn_const_start(codestr, op_start, 2);
598 h = fold_binops_on_constants(codestr, h, i + 1, opcode,
614 h = lastn_const_start(codestr, op_start, 1);
616 h = fold_unaryops_on_constants(codestr, h, i + 1, opcode,
641 h = get_arg(codestr, i) / sizeof(_Py_CODEUNIT);
642 tgt = find_op(codestr, h);
644 j = _Py_OPCODE(codestr[tgt]);
651 h = set_arg(codestr, i, get_arg(codestr, tgt));
657 h = set_arg(codestr, i, (tgt + 1) * sizeof(_Py_CODEUNIT));
664 codestr[nexti] = PACKOPARG(j, _Py_OPARG(codestr[nexti]));
682 h = GETJUMPTGT(codestr, i);
683 tgt = find_op(codestr, h);
686 _Py_OPCODE(codestr[tgt]) == RETURN_VALUE) {
687 codestr[op_start] = PACKOPARG(RETURN_VALUE, 0);
688 fill_nops(codestr, op_start + 1, i + 1);
689 } else if (UNCONDITIONAL_JUMP(_Py_OPCODE(codestr[tgt]))) {
690 j = GETJUMPTGT(codestr, tgt);
700 copy_op_arg(codestr, op_start, opcode, j, i + 1);
711 fill_nops(codestr, i + 1, h);
712 nexti = find_op(codestr, h);
723 if (_Py_OPCODE(codestr[i]) == NOP)
742 j = _Py_OPARG(codestr[i]);
743 while (_Py_OPCODE(codestr[i]) == EXTENDED_ARG) {
745 j = j<<8 | _Py_OPARG(codestr[i]);
747 opcode = _Py_OPCODE(codestr[i]);
775 write_op_arg(codestr + h, opcode, j, nexti);
782 code = PyBytes_FromStringAndSize((char *)codestr, h * sizeof(_Py_CODEUNIT));
783 PyMem_Free(codestr);
793 PyMem_Free(codestr);