Skip to content

Commit cc4c1ad

Browse files
committed
py/showbc: Make sure to set the const_table before printing bytecode.
1 parent 4614403 commit cc4c1ad

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

py/bc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, s
9494
struct _mp_obj_fun_bc_t;
9595
void mp_setup_code_state(mp_code_state_t *code_state, struct _mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args);
9696
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table);
97-
void mp_bytecode_print2(const byte *code, mp_uint_t len);
97+
void mp_bytecode_print2(const byte *code, size_t len, const mp_uint_t *const_table);
9898
const byte *mp_bytecode_print_str(const byte *ip);
99-
#define mp_bytecode_print_inst(code) mp_bytecode_print2(code, 1)
99+
#define mp_bytecode_print_inst(code, const_table) mp_bytecode_print2(code, 1, const_table)
100100

101101
// Helper macros to access pointer with least significant bits holding flags
102102
#define MP_TAGPTR_PTR(x) ((void*)((uintptr_t)(x) & ~((uintptr_t)3)))

py/showbc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const mp_uint_t *mp_showbc_const_table;
8282

8383
void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len, const mp_uint_t *const_table) {
8484
mp_showbc_code_start = ip;
85-
mp_showbc_const_table = const_table;
8685

8786
// get bytecode parameters
8887
mp_uint_t n_state = mp_decode_uint(&ip);
@@ -159,7 +158,7 @@ void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len, const m
159158
printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
160159
}
161160
}
162-
mp_bytecode_print2(ip, len - 0);
161+
mp_bytecode_print2(ip, len - 0, const_table);
163162
}
164163

165164
const byte *mp_bytecode_print_str(const byte *ip) {
@@ -547,8 +546,9 @@ const byte *mp_bytecode_print_str(const byte *ip) {
547546
return ip;
548547
}
549548

550-
void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
549+
void mp_bytecode_print2(const byte *ip, size_t len, const mp_uint_t *const_table) {
551550
mp_showbc_code_start = ip;
551+
mp_showbc_const_table = const_table;
552552
while (ip < len + mp_showbc_code_start) {
553553
printf("%02u ", (uint)(ip - mp_showbc_code_start));
554554
ip = mp_bytecode_print_str(ip);

py/vm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
#include "py/bc.h"
3939

4040
#if 0
41-
//#define TRACE(ip) printf("sp=" INT_FMT " ", sp - code_state->sp); mp_bytecode_print2(ip, 1);
42-
#define TRACE(ip) printf("sp=%d ", sp - code_state->sp); mp_bytecode_print2(ip, 1);
41+
#define TRACE(ip) printf("sp=%d ", (int)(sp - code_state->sp)); mp_bytecode_print2(ip, 1, code_state->const_table);
4342
#else
4443
#define TRACE(ip)
4544
#endif

0 commit comments

Comments
 (0)