Commit 343266ea authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

showbc: Refactor to allow inline instruction printing.

parent c55a4d82
......@@ -53,6 +53,8 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_o
void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *code, mp_uint_t len);
void mp_bytecode_print2(const byte *code, mp_uint_t len);
const byte *mp_bytecode_print_str(const byte *ip);
#define mp_bytecode_print_inst(code) mp_bytecode_print2(code, 1)
// Helper macros to access pointer with least significant bits holding flags
#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)3)))
......
......@@ -57,8 +57,10 @@
ip += sizeof(mp_uint_t); \
} while (0)
static const byte *ip_start;
void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip, mp_uint_t len) {
const byte *ip_start = ip;
ip_start = ip;
// get code info size
const byte *code_info = ip;
......@@ -130,12 +132,10 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip
mp_bytecode_print2(ip, len - 0);
}
void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
const byte *ip_start = ip;
const byte *mp_bytecode_print_str(const byte *ip) {
mp_uint_t unum;
qstr qstr;
while (ip - ip_start < len) {
printf("%02u ", (uint)(ip - ip_start));
switch (*ip++) {
case MP_BC_LOAD_CONST_FALSE:
printf("LOAD_CONST_FALSE");
......@@ -513,10 +513,19 @@ void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
} else {
printf("code %p, byte code 0x%02x not implemented\n", ip, ip[-1]);
assert(0);
return;
return ip;
}
break;
}
return ip;
}
void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
ip_start = ip;
while (ip - ip_start < len) {
printf("%02u ", (uint)(ip - ip_start));
ip = mp_bytecode_print_str(ip);
printf("\n");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment