33 #if MICROPY_DEBUG_PRINTERS 36 #define printf(...) mp_printf(&mp_plat_print, __VA_ARGS__) 38 #define DECODE_UINT { \ 41 unum = (unum << 7) + (*ip & 0x7f); \ 42 } while ((*ip++ & 0x80) != 0); \ 44 #define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0) 45 #define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0) 47 #if MICROPY_PERSISTENT_CODE 50 qst = ip[0] | ip[1] << 8; \ 54 unum = mp_showbc_const_table[unum] 57 unum = mp_showbc_const_table[unum] 61 #define DECODE_QSTR { \ 64 qst = (qst << 7) + (*ip & 0x7f); \ 65 } while ((*ip++ & 0x80) != 0); \ 67 #define DECODE_PTR do { \ 68 ip = (byte*)MP_ALIGN(ip, sizeof(void*)); \ 69 unum = (uintptr_t)*(void**)ip; \ 70 ip += sizeof(void*); \ 72 #define DECODE_OBJ do { \ 73 ip = (byte*)MP_ALIGN(ip, sizeof(mp_obj_t)); \ 74 unum = (mp_uint_t)*(mp_obj_t*)ip; \ 75 ip += sizeof(mp_obj_t); \ 80 const byte *mp_showbc_code_start;
84 mp_showbc_code_start = ip;
94 const byte *code_info = ip;
98 #if MICROPY_PERSISTENT_CODE 99 qstr block_name = code_info[0] | (code_info[1] << 8);
106 printf(
"File %s, code block '%s' (descriptor: %p, bytecode @%p " UINT_FMT " bytes)\n",
110 printf(
"Raw bytecode (code_info_size=" UINT_FMT ", bytecode_size=" UINT_FMT "):\n", code_info_size, len - code_info_size);
112 if (i > 0 && i % 16 == 0) {
115 printf(
" %02x", mp_showbc_code_start[i]);
120 printf(
"arg names:");
121 for (
mp_uint_t i = 0; i < n_pos_args + n_kwonly_args; i++) {
126 printf(
"(N_STATE " UINT_FMT ")\n", n_state);
127 printf(
"(N_EXC_STACK " UINT_FMT ")\n", n_exc_stack);
130 const byte *bytecode_start = ip;
135 while ((local_num = *ip++) != 255) {
136 printf(
"(INIT_CELL %u)\n", local_num);
138 len -= ip - mp_showbc_code_start;
146 for (
const byte* ci = code_info; *ci;) {
147 if ((ci[0] & 0x80) == 0) {
150 source_line += ci[0] >> 5;
155 source_line += ((ci[0] << 4) & 0x700) | ci[1];
170 printf(
"LOAD_CONST_FALSE");
174 printf(
"LOAD_CONST_NONE");
178 printf(
"LOAD_CONST_TRUE");
183 if ((ip[0] & 0x40) != 0) {
188 num = (num << 7) | (*ip & 0x7f);
189 }
while ((*ip++ & 0x80) != 0);
190 printf(
"LOAD_CONST_SMALL_INT " INT_FMT, num);
196 printf(
"LOAD_CONST_STRING '%s'",
qstr_str(qst));
211 printf(
"LOAD_FAST_N " UINT_FMT, unum);
216 printf(
"LOAD_DEREF " UINT_FMT, unum);
221 printf(
"LOAD_NAME %s",
qstr_str(qst));
223 printf(
" (cache=%u)", *ip++);
229 printf(
"LOAD_GLOBAL %s",
qstr_str(qst));
231 printf(
" (cache=%u)", *ip++);
237 printf(
"LOAD_ATTR %s",
qstr_str(qst));
239 printf(
" (cache=%u)", *ip++);
245 printf(
"LOAD_METHOD %s",
qstr_str(qst));
250 printf(
"LOAD_SUPER_METHOD %s",
qstr_str(qst));
254 printf(
"LOAD_BUILD_CLASS");
258 printf(
"LOAD_SUBSCR");
263 printf(
"STORE_FAST_N " UINT_FMT, unum);
268 printf(
"STORE_DEREF " UINT_FMT, unum);
273 printf(
"STORE_NAME %s",
qstr_str(qst));
278 printf(
"STORE_GLOBAL %s",
qstr_str(qst));
283 printf(
"STORE_ATTR %s",
qstr_str(qst));
285 printf(
" (cache=%u)", *ip++);
290 printf(
"STORE_SUBSCR");
295 printf(
"DELETE_FAST " UINT_FMT, unum);
300 printf(
"DELETE_DEREF " UINT_FMT, unum);
305 printf(
"DELETE_NAME %s",
qstr_str(qst));
310 printf(
"DELETE_GLOBAL %s",
qstr_str(qst));
318 printf(
"DUP_TOP_TWO");
340 printf(
"POP_JUMP_IF_TRUE " UINT_FMT, (
mp_uint_t)(ip + unum - mp_showbc_code_start));
345 printf(
"POP_JUMP_IF_FALSE " UINT_FMT, (
mp_uint_t)(ip + unum - mp_showbc_code_start));
350 printf(
"JUMP_IF_TRUE_OR_POP " UINT_FMT, (
mp_uint_t)(ip + unum - mp_showbc_code_start));
355 printf(
"JUMP_IF_FALSE_OR_POP " UINT_FMT, (
mp_uint_t)(ip + unum - mp_showbc_code_start));
364 printf(
"WITH_CLEANUP");
369 printf(
"UNWIND_JUMP " UINT_FMT " %d", (
mp_uint_t)(ip + unum - mp_showbc_code_start), *ip);
380 printf(
"SETUP_FINALLY " UINT_FMT, (
mp_uint_t)(ip + unum - mp_showbc_code_start));
388 printf(
"END_FINALLY");
396 printf(
"GET_ITER_STACK");
411 printf(
"POP_EXCEPT");
416 printf(
"BUILD_TUPLE " UINT_FMT, unum);
421 printf(
"BUILD_LIST " UINT_FMT, unum);
426 printf(
"BUILD_MAP " UINT_FMT, unum);
435 printf(
"BUILD_SET " UINT_FMT, unum);
438 #if MICROPY_PY_BUILTINS_SLICE 441 printf(
"BUILD_SLICE " UINT_FMT, unum);
447 printf(
"STORE_COMP " UINT_FMT, unum);
452 printf(
"UNPACK_SEQUENCE " UINT_FMT, unum);
457 printf(
"UNPACK_EX " UINT_FMT, unum);
462 printf(
"MAKE_FUNCTION %p", (
void*)(
uintptr_t)unum);
467 printf(
"MAKE_FUNCTION_DEFARGS %p", (
void*)(
uintptr_t)unum);
480 printf(
"MAKE_CLOSURE_DEFARGS %p " UINT_FMT, (
void*)(
uintptr_t)unum, n_closed_over);
486 printf(
"CALL_FUNCTION n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
491 printf(
"CALL_FUNCTION_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
496 printf(
"CALL_METHOD n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
501 printf(
"CALL_METHOD_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
505 printf(
"RETURN_VALUE");
510 printf(
"RAISE_VARARGS " UINT_FMT, unum);
514 printf(
"YIELD_VALUE");
518 printf(
"YIELD_FROM");
523 printf(
"IMPORT_NAME '%s'",
qstr_str(qst));
528 printf(
"IMPORT_FROM '%s'",
qstr_str(qst));
532 printf(
"IMPORT_STAR");
548 printf(
"code %p, byte code 0x%02x not implemented\n", ip, ip[-1]);
559 mp_showbc_code_start = ip;
560 mp_showbc_const_table = const_table;
561 while (ip < len + mp_showbc_code_start) {
562 printf(
"%02u ", (
uint)(ip - mp_showbc_code_start));
568 #endif // MICROPY_DEBUG_PRINTERS const mp_print_t mp_plat_print
#define MP_BC_CALL_FUNCTION_VAR_KW
#define MP_BC_LOAD_CONST_FALSE
#define MP_BC_BUILD_TUPLE
const char * qstr_str(qstr q)
#define MP_BC_RAISE_VARARGS
#define MP_BC_GET_ITER_STACK
#define MP_BC_UNARY_OP_MULTI
const byte * mp_bytecode_print_str(const byte *ip)
#define MP_BC_IMPORT_FROM
#define MP_BC_LOAD_SUPER_METHOD
#define MP_BC_BINARY_OP_MULTI
#define MP_BC_LOAD_CONST_SMALL_INT_MULTI
void mp_bytecode_print2(const byte *code, size_t len, const mp_uint_t *const_table)
#define MP_OBJ_QSTR_VALUE(o)
#define MP_BC_DUP_TOP_TWO
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
#define MP_BC_LOAD_CONST_NONE
#define MP_BC_LOAD_BUILD_CLASS
#define MP_BC_IMPORT_NAME
#define MP_BC_MAKE_FUNCTION_DEFARGS
#define MP_BC_MAKE_CLOSURE_DEFARGS
#define MP_BC_LOAD_CONST_TRUE
#define MP_BC_DELETE_DEREF
#define MP_BC_CALL_METHOD_VAR_KW
#define MP_BC_CALL_FUNCTION
#define MP_BC_POP_JUMP_IF_FALSE
#define MP_BC_BUILD_SLICE
#define MP_BC_DELETE_NAME
#define MP_BC_JUMP_IF_TRUE_OR_POP
#define MP_BC_LOAD_GLOBAL
#define MP_BC_MAKE_CLOSURE
#define MP_BC_DELETE_GLOBAL
#define MP_BC_UNPACK_SEQUENCE
#define MP_BC_STORE_GLOBAL
#define MP_BC_DELETE_FAST
const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME]
#define MP_BC_LOAD_SUBSCR
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
#define MP_BC_UNWIND_JUMP
#define MP_BC_LOAD_CONST_OBJ
#define MP_BC_CALL_METHOD
#define MP_BC_JUMP_IF_FALSE_OR_POP
#define MP_BC_WITH_CLEANUP
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table)
mp_uint_t mp_decode_uint(const byte **ptr)
#define MP_BC_SETUP_EXCEPT
#define MP_BC_LOAD_METHOD
#define MP_BC_LOAD_CONST_SMALL_INT
#define MP_BC_LOAD_FAST_MULTI
#define MP_BC_STORE_FAST_MULTI
#define MP_BC_MAKE_FUNCTION
#define MP_BC_END_FINALLY
#define MP_BC_STORE_FAST_N
#define MP_BC_STORE_SUBSCR
#define MP_BC_SETUP_FINALLY
#define MP_BC_LOAD_CONST_STRING
#define MP_BC_RETURN_VALUE
#define MP_BC_POP_JUMP_IF_TRUE
#define MP_BC_STORE_DEREF
#define MP_BC_IMPORT_STAR
#define MP_BC_YIELD_VALUE
#define MP_BC_LOAD_FAST_N