showbc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013, 2014 Damien P. George
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <stdio.h>
  27. #include <assert.h>
  28. #include "py/bc0.h"
  29. #include "py/bc.h"
  30. #if MICROPY_DEBUG_PRINTERS
  31. #define DECODE_UINT { \
  32. unum = 0; \
  33. do { \
  34. unum = (unum << 7) + (*ip & 0x7f); \
  35. } while ((*ip++ & 0x80) != 0); \
  36. }
  37. #define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0)
  38. #define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0)
  39. #if MICROPY_PERSISTENT_CODE
  40. #define DECODE_QSTR \
  41. qst = ip[0] | ip[1] << 8; \
  42. ip += 2;
  43. #define DECODE_PTR \
  44. DECODE_UINT; \
  45. unum = mp_showbc_const_table[unum]
  46. #define DECODE_OBJ \
  47. DECODE_UINT; \
  48. unum = mp_showbc_const_table[unum]
  49. #else
  50. #define DECODE_QSTR { \
  51. qst = 0; \
  52. do { \
  53. qst = (qst << 7) + (*ip & 0x7f); \
  54. } while ((*ip++ & 0x80) != 0); \
  55. }
  56. #define DECODE_PTR do { \
  57. ip = (byte *)MP_ALIGN(ip, sizeof(void *)); \
  58. unum = (uintptr_t)*(void **)ip; \
  59. ip += sizeof(void *); \
  60. } while (0)
  61. #define DECODE_OBJ do { \
  62. ip = (byte *)MP_ALIGN(ip, sizeof(mp_obj_t)); \
  63. unum = (mp_uint_t)*(mp_obj_t *)ip; \
  64. ip += sizeof(mp_obj_t); \
  65. } while (0)
  66. #endif
  67. const byte *mp_showbc_code_start;
  68. const mp_uint_t *mp_showbc_const_table;
  69. void mp_bytecode_print(const mp_print_t *print, const void *descr, const byte *ip, mp_uint_t len, const mp_uint_t *const_table) {
  70. mp_showbc_code_start = ip;
  71. // Decode prelude
  72. MP_BC_PRELUDE_SIG_DECODE(ip);
  73. MP_BC_PRELUDE_SIZE_DECODE(ip);
  74. const byte *code_info = ip;
  75. #if MICROPY_PERSISTENT_CODE
  76. qstr block_name = code_info[0] | (code_info[1] << 8);
  77. qstr source_file = code_info[2] | (code_info[3] << 8);
  78. code_info += 4;
  79. #else
  80. qstr block_name = mp_decode_uint(&code_info);
  81. qstr source_file = mp_decode_uint(&code_info);
  82. #endif
  83. mp_printf(print, "File %s, code block '%s' (descriptor: %p, bytecode @%p " UINT_FMT " bytes)\n",
  84. qstr_str(source_file), qstr_str(block_name), descr, mp_showbc_code_start, len);
  85. // raw bytecode dump
  86. size_t prelude_size = ip - mp_showbc_code_start + n_info + n_cell;
  87. mp_printf(print, "Raw bytecode (code_info_size=" UINT_FMT ", bytecode_size=" UINT_FMT "):\n",
  88. prelude_size, len - prelude_size);
  89. for (mp_uint_t i = 0; i < len; i++) {
  90. if (i > 0 && i % 16 == 0) {
  91. mp_printf(print, "\n");
  92. }
  93. mp_printf(print, " %02x", mp_showbc_code_start[i]);
  94. }
  95. mp_printf(print, "\n");
  96. // bytecode prelude: arg names (as qstr objects)
  97. mp_printf(print, "arg names:");
  98. for (mp_uint_t i = 0; i < n_pos_args + n_kwonly_args; i++) {
  99. mp_printf(print, " %s", qstr_str(MP_OBJ_QSTR_VALUE(const_table[i])));
  100. }
  101. mp_printf(print, "\n");
  102. mp_printf(print, "(N_STATE %u)\n", (unsigned)n_state);
  103. mp_printf(print, "(N_EXC_STACK %u)\n", (unsigned)n_exc_stack);
  104. // skip over code_info
  105. ip += n_info;
  106. // bytecode prelude: initialise closed over variables
  107. for (size_t i = 0; i < n_cell; ++i) {
  108. uint local_num = *ip++;
  109. mp_printf(print, "(INIT_CELL %u)\n", local_num);
  110. }
  111. // print out line number info
  112. {
  113. mp_int_t bc = 0;
  114. mp_uint_t source_line = 1;
  115. mp_printf(print, " bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
  116. for (const byte *ci = code_info; *ci;) {
  117. if ((ci[0] & 0x80) == 0) {
  118. // 0b0LLBBBBB encoding
  119. bc += ci[0] & 0x1f;
  120. source_line += ci[0] >> 5;
  121. ci += 1;
  122. } else {
  123. // 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)
  124. bc += ci[0] & 0xf;
  125. source_line += ((ci[0] << 4) & 0x700) | ci[1];
  126. ci += 2;
  127. }
  128. mp_printf(print, " bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
  129. }
  130. }
  131. mp_bytecode_print2(print, ip, len - prelude_size, const_table);
  132. }
  133. const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip) {
  134. mp_uint_t unum;
  135. qstr qst;
  136. switch (*ip++) {
  137. case MP_BC_LOAD_CONST_FALSE:
  138. mp_printf(print, "LOAD_CONST_FALSE");
  139. break;
  140. case MP_BC_LOAD_CONST_NONE:
  141. mp_printf(print, "LOAD_CONST_NONE");
  142. break;
  143. case MP_BC_LOAD_CONST_TRUE:
  144. mp_printf(print, "LOAD_CONST_TRUE");
  145. break;
  146. case MP_BC_LOAD_CONST_SMALL_INT: {
  147. mp_int_t num = 0;
  148. if ((ip[0] & 0x40) != 0) {
  149. // Number is negative
  150. num--;
  151. }
  152. do {
  153. num = (num << 7) | (*ip & 0x7f);
  154. } while ((*ip++ & 0x80) != 0);
  155. mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, num);
  156. break;
  157. }
  158. case MP_BC_LOAD_CONST_STRING:
  159. DECODE_QSTR;
  160. mp_printf(print, "LOAD_CONST_STRING '%s'", qstr_str(qst));
  161. break;
  162. case MP_BC_LOAD_CONST_OBJ:
  163. DECODE_OBJ;
  164. mp_printf(print, "LOAD_CONST_OBJ %p=", MP_OBJ_TO_PTR(unum));
  165. mp_obj_print_helper(print, (mp_obj_t)unum, PRINT_REPR);
  166. break;
  167. case MP_BC_LOAD_NULL:
  168. mp_printf(print, "LOAD_NULL");
  169. break;
  170. case MP_BC_LOAD_FAST_N:
  171. DECODE_UINT;
  172. mp_printf(print, "LOAD_FAST_N " UINT_FMT, unum);
  173. break;
  174. case MP_BC_LOAD_DEREF:
  175. DECODE_UINT;
  176. mp_printf(print, "LOAD_DEREF " UINT_FMT, unum);
  177. break;
  178. case MP_BC_LOAD_NAME:
  179. DECODE_QSTR;
  180. mp_printf(print, "LOAD_NAME %s", qstr_str(qst));
  181. if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) {
  182. mp_printf(print, " (cache=%u)", *ip++);
  183. }
  184. break;
  185. case MP_BC_LOAD_GLOBAL:
  186. DECODE_QSTR;
  187. mp_printf(print, "LOAD_GLOBAL %s", qstr_str(qst));
  188. if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) {
  189. mp_printf(print, " (cache=%u)", *ip++);
  190. }
  191. break;
  192. case MP_BC_LOAD_ATTR:
  193. DECODE_QSTR;
  194. mp_printf(print, "LOAD_ATTR %s", qstr_str(qst));
  195. if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) {
  196. mp_printf(print, " (cache=%u)", *ip++);
  197. }
  198. break;
  199. case MP_BC_LOAD_METHOD:
  200. DECODE_QSTR;
  201. mp_printf(print, "LOAD_METHOD %s", qstr_str(qst));
  202. break;
  203. case MP_BC_LOAD_SUPER_METHOD:
  204. DECODE_QSTR;
  205. mp_printf(print, "LOAD_SUPER_METHOD %s", qstr_str(qst));
  206. break;
  207. case MP_BC_LOAD_BUILD_CLASS:
  208. mp_printf(print, "LOAD_BUILD_CLASS");
  209. break;
  210. case MP_BC_LOAD_SUBSCR:
  211. mp_printf(print, "LOAD_SUBSCR");
  212. break;
  213. case MP_BC_STORE_FAST_N:
  214. DECODE_UINT;
  215. mp_printf(print, "STORE_FAST_N " UINT_FMT, unum);
  216. break;
  217. case MP_BC_STORE_DEREF:
  218. DECODE_UINT;
  219. mp_printf(print, "STORE_DEREF " UINT_FMT, unum);
  220. break;
  221. case MP_BC_STORE_NAME:
  222. DECODE_QSTR;
  223. mp_printf(print, "STORE_NAME %s", qstr_str(qst));
  224. break;
  225. case MP_BC_STORE_GLOBAL:
  226. DECODE_QSTR;
  227. mp_printf(print, "STORE_GLOBAL %s", qstr_str(qst));
  228. break;
  229. case MP_BC_STORE_ATTR:
  230. DECODE_QSTR;
  231. mp_printf(print, "STORE_ATTR %s", qstr_str(qst));
  232. if (MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) {
  233. mp_printf(print, " (cache=%u)", *ip++);
  234. }
  235. break;
  236. case MP_BC_STORE_SUBSCR:
  237. mp_printf(print, "STORE_SUBSCR");
  238. break;
  239. case MP_BC_DELETE_FAST:
  240. DECODE_UINT;
  241. mp_printf(print, "DELETE_FAST " UINT_FMT, unum);
  242. break;
  243. case MP_BC_DELETE_DEREF:
  244. DECODE_UINT;
  245. mp_printf(print, "DELETE_DEREF " UINT_FMT, unum);
  246. break;
  247. case MP_BC_DELETE_NAME:
  248. DECODE_QSTR;
  249. mp_printf(print, "DELETE_NAME %s", qstr_str(qst));
  250. break;
  251. case MP_BC_DELETE_GLOBAL:
  252. DECODE_QSTR;
  253. mp_printf(print, "DELETE_GLOBAL %s", qstr_str(qst));
  254. break;
  255. case MP_BC_DUP_TOP:
  256. mp_printf(print, "DUP_TOP");
  257. break;
  258. case MP_BC_DUP_TOP_TWO:
  259. mp_printf(print, "DUP_TOP_TWO");
  260. break;
  261. case MP_BC_POP_TOP:
  262. mp_printf(print, "POP_TOP");
  263. break;
  264. case MP_BC_ROT_TWO:
  265. mp_printf(print, "ROT_TWO");
  266. break;
  267. case MP_BC_ROT_THREE:
  268. mp_printf(print, "ROT_THREE");
  269. break;
  270. case MP_BC_JUMP:
  271. DECODE_SLABEL;
  272. mp_printf(print, "JUMP " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  273. break;
  274. case MP_BC_POP_JUMP_IF_TRUE:
  275. DECODE_SLABEL;
  276. mp_printf(print, "POP_JUMP_IF_TRUE " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  277. break;
  278. case MP_BC_POP_JUMP_IF_FALSE:
  279. DECODE_SLABEL;
  280. mp_printf(print, "POP_JUMP_IF_FALSE " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  281. break;
  282. case MP_BC_JUMP_IF_TRUE_OR_POP:
  283. DECODE_SLABEL;
  284. mp_printf(print, "JUMP_IF_TRUE_OR_POP " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  285. break;
  286. case MP_BC_JUMP_IF_FALSE_OR_POP:
  287. DECODE_SLABEL;
  288. mp_printf(print, "JUMP_IF_FALSE_OR_POP " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  289. break;
  290. case MP_BC_SETUP_WITH:
  291. DECODE_ULABEL; // loop-like labels are always forward
  292. mp_printf(print, "SETUP_WITH " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  293. break;
  294. case MP_BC_WITH_CLEANUP:
  295. mp_printf(print, "WITH_CLEANUP");
  296. break;
  297. case MP_BC_UNWIND_JUMP:
  298. DECODE_SLABEL;
  299. mp_printf(print, "UNWIND_JUMP " UINT_FMT " %d", (mp_uint_t)(ip + unum - mp_showbc_code_start), *ip);
  300. ip += 1;
  301. break;
  302. case MP_BC_SETUP_EXCEPT:
  303. DECODE_ULABEL; // except labels are always forward
  304. mp_printf(print, "SETUP_EXCEPT " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  305. break;
  306. case MP_BC_SETUP_FINALLY:
  307. DECODE_ULABEL; // except labels are always forward
  308. mp_printf(print, "SETUP_FINALLY " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  309. break;
  310. case MP_BC_END_FINALLY:
  311. // if TOS is an exception, reraises the exception (3 values on TOS)
  312. // if TOS is an integer, does something else
  313. // if TOS is None, just pops it and continues
  314. // else error
  315. mp_printf(print, "END_FINALLY");
  316. break;
  317. case MP_BC_GET_ITER:
  318. mp_printf(print, "GET_ITER");
  319. break;
  320. case MP_BC_GET_ITER_STACK:
  321. mp_printf(print, "GET_ITER_STACK");
  322. break;
  323. case MP_BC_FOR_ITER:
  324. DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
  325. mp_printf(print, "FOR_ITER " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  326. break;
  327. case MP_BC_POP_EXCEPT_JUMP:
  328. DECODE_ULABEL; // these labels are always forward
  329. mp_printf(print, "POP_EXCEPT_JUMP " UINT_FMT, (mp_uint_t)(ip + unum - mp_showbc_code_start));
  330. break;
  331. case MP_BC_BUILD_TUPLE:
  332. DECODE_UINT;
  333. mp_printf(print, "BUILD_TUPLE " UINT_FMT, unum);
  334. break;
  335. case MP_BC_BUILD_LIST:
  336. DECODE_UINT;
  337. mp_printf(print, "BUILD_LIST " UINT_FMT, unum);
  338. break;
  339. case MP_BC_BUILD_MAP:
  340. DECODE_UINT;
  341. mp_printf(print, "BUILD_MAP " UINT_FMT, unum);
  342. break;
  343. case MP_BC_STORE_MAP:
  344. mp_printf(print, "STORE_MAP");
  345. break;
  346. case MP_BC_BUILD_SET:
  347. DECODE_UINT;
  348. mp_printf(print, "BUILD_SET " UINT_FMT, unum);
  349. break;
  350. #if MICROPY_PY_BUILTINS_SLICE
  351. case MP_BC_BUILD_SLICE:
  352. DECODE_UINT;
  353. mp_printf(print, "BUILD_SLICE " UINT_FMT, unum);
  354. break;
  355. #endif
  356. case MP_BC_STORE_COMP:
  357. DECODE_UINT;
  358. mp_printf(print, "STORE_COMP " UINT_FMT, unum);
  359. break;
  360. case MP_BC_UNPACK_SEQUENCE:
  361. DECODE_UINT;
  362. mp_printf(print, "UNPACK_SEQUENCE " UINT_FMT, unum);
  363. break;
  364. case MP_BC_UNPACK_EX:
  365. DECODE_UINT;
  366. mp_printf(print, "UNPACK_EX " UINT_FMT, unum);
  367. break;
  368. case MP_BC_MAKE_FUNCTION:
  369. DECODE_PTR;
  370. mp_printf(print, "MAKE_FUNCTION %p", (void *)(uintptr_t)unum);
  371. break;
  372. case MP_BC_MAKE_FUNCTION_DEFARGS:
  373. DECODE_PTR;
  374. mp_printf(print, "MAKE_FUNCTION_DEFARGS %p", (void *)(uintptr_t)unum);
  375. break;
  376. case MP_BC_MAKE_CLOSURE: {
  377. DECODE_PTR;
  378. mp_uint_t n_closed_over = *ip++;
  379. mp_printf(print, "MAKE_CLOSURE %p " UINT_FMT, (void *)(uintptr_t)unum, n_closed_over);
  380. break;
  381. }
  382. case MP_BC_MAKE_CLOSURE_DEFARGS: {
  383. DECODE_PTR;
  384. mp_uint_t n_closed_over = *ip++;
  385. mp_printf(print, "MAKE_CLOSURE_DEFARGS %p " UINT_FMT, (void *)(uintptr_t)unum, n_closed_over);
  386. break;
  387. }
  388. case MP_BC_CALL_FUNCTION:
  389. DECODE_UINT;
  390. mp_printf(print, "CALL_FUNCTION n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
  391. break;
  392. case MP_BC_CALL_FUNCTION_VAR_KW:
  393. DECODE_UINT;
  394. mp_printf(print, "CALL_FUNCTION_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
  395. break;
  396. case MP_BC_CALL_METHOD:
  397. DECODE_UINT;
  398. mp_printf(print, "CALL_METHOD n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
  399. break;
  400. case MP_BC_CALL_METHOD_VAR_KW:
  401. DECODE_UINT;
  402. mp_printf(print, "CALL_METHOD_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
  403. break;
  404. case MP_BC_RETURN_VALUE:
  405. mp_printf(print, "RETURN_VALUE");
  406. break;
  407. case MP_BC_RAISE_LAST:
  408. mp_printf(print, "RAISE_LAST");
  409. break;
  410. case MP_BC_RAISE_OBJ:
  411. mp_printf(print, "RAISE_OBJ");
  412. break;
  413. case MP_BC_RAISE_FROM:
  414. mp_printf(print, "RAISE_FROM");
  415. break;
  416. case MP_BC_YIELD_VALUE:
  417. mp_printf(print, "YIELD_VALUE");
  418. break;
  419. case MP_BC_YIELD_FROM:
  420. mp_printf(print, "YIELD_FROM");
  421. break;
  422. case MP_BC_IMPORT_NAME:
  423. DECODE_QSTR;
  424. mp_printf(print, "IMPORT_NAME '%s'", qstr_str(qst));
  425. break;
  426. case MP_BC_IMPORT_FROM:
  427. DECODE_QSTR;
  428. mp_printf(print, "IMPORT_FROM '%s'", qstr_str(qst));
  429. break;
  430. case MP_BC_IMPORT_STAR:
  431. mp_printf(print, "IMPORT_STAR");
  432. break;
  433. default:
  434. if (ip[-1] < MP_BC_LOAD_CONST_SMALL_INT_MULTI + 64) {
  435. mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, (mp_int_t)ip[-1] - MP_BC_LOAD_CONST_SMALL_INT_MULTI - 16);
  436. } else if (ip[-1] < MP_BC_LOAD_FAST_MULTI + 16) {
  437. mp_printf(print, "LOAD_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_LOAD_FAST_MULTI);
  438. } else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) {
  439. mp_printf(print, "STORE_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_STORE_FAST_MULTI);
  440. } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NUM_BYTECODE) {
  441. mp_printf(print, "UNARY_OP " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_UNARY_OP_MULTI);
  442. } else if (ip[-1] < MP_BC_BINARY_OP_MULTI + MP_BINARY_OP_NUM_BYTECODE) {
  443. mp_uint_t op = ip[-1] - MP_BC_BINARY_OP_MULTI;
  444. mp_printf(print, "BINARY_OP " UINT_FMT " %s", op, qstr_str(mp_binary_op_method_name[op]));
  445. } else {
  446. mp_printf(print, "code %p, byte code 0x%02x not implemented\n", ip - 1, ip[-1]);
  447. assert(0);
  448. return ip;
  449. }
  450. break;
  451. }
  452. return ip;
  453. }
  454. void mp_bytecode_print2(const mp_print_t *print, const byte *ip, size_t len, const mp_uint_t *const_table) {
  455. mp_showbc_code_start = ip;
  456. mp_showbc_const_table = const_table;
  457. while (ip < len + mp_showbc_code_start) {
  458. mp_printf(print, "%02u ", (uint)(ip - mp_showbc_code_start));
  459. ip = mp_bytecode_print_str(print, ip);
  460. mp_printf(print, "\n");
  461. }
  462. }
  463. #endif // MICROPY_DEBUG_PRINTERS