diff --git a/py/emitglue.c b/py/emitglue.c index 99cd3f383..dd31de925 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -74,13 +74,6 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, mp_uint_t len, #endif #if MICROPY_DEBUG_PRINTERS if (mp_verbose_flag > 0) { - for (mp_uint_t i = 0; i < len; i++) { - if (i > 0 && i % 16 == 0) { - printf("\n"); - } - printf(" %02x", code[i]); - } - printf("\n"); mp_bytecode_print(rc, code, len); } #endif diff --git a/py/emitglue.h b/py/emitglue.h index 087b2296e..91d5285ad 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -35,7 +35,7 @@ typedef enum { MP_CODE_NATIVE_ASM, } mp_raw_code_kind_t; -typedef struct _mp_code_t { +typedef struct _mp_raw_code_t { mp_raw_code_kind_t kind : 3; mp_uint_t scope_flags : 7; mp_uint_t n_pos_args : 11; diff --git a/py/showbc.c b/py/showbc.c index 214ea9005..28fed14c9 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -70,6 +70,16 @@ void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len) { printf("File %s, code block '%s' (descriptor: %p, bytecode @%p " UINT_FMT " bytes)\n", qstr_str(source_file), qstr_str(block_name), descr, code_info, len); + // raw bytecode dump + printf("Raw bytecode (code_info_size=" UINT_FMT ", bytecode_size=" UINT_FMT "):\n", code_info_size, len - code_info_size); + for (mp_uint_t i = 0; i < len; i++) { + if (i > 0 && i % 16 == 0) { + printf("\n"); + } + printf(" %02x", ip_start[i]); + } + printf("\n"); + // bytecode prelude: state size and exception stack size; 16 bit uints { uint n_state = mp_decode_uint(&ip); @@ -87,15 +97,14 @@ void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len) { printf("(INIT_CELL %u)\n", local_num); } len -= ip - ip_start; - ip_start = ip; } // print out line number info { - mp_int_t bc = (code_info + code_info_size) - ip; + mp_int_t bc = (ip_start + code_info_size) - ip; // start counting from the prelude mp_uint_t source_line = 1; printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line); - for (const byte* ci = code_info + 12; *ci;) { + for (const byte* ci = code_info; *ci;) { if ((ci[0] & 0x80) == 0) { // 0b0LLBBBBB encoding bc += ci[0] & 0x1f;