diff options
author | Damien George <damien.p.george@gmail.com> | 2015-03-18 17:47:47 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-11-13 12:49:18 +0000 |
commit | 9b7f583b0ca37ee87e5fb82e2d65fcd96a609b2f (patch) | |
tree | 7e061a768312190c62c1fb400619ca59c2f92f70 /py/showbc.c | |
parent | f882d53fcd4ba9775409c994cbf183770963b37e (diff) |
py: Reorganise bytecode layout so it's more structured, easier to edit.
Diffstat (limited to 'py/showbc.c')
-rw-r--r-- | py/showbc.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/py/showbc.c b/py/showbc.c index 2da8d3feb..87e7c6af4 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -57,7 +57,16 @@ const byte *mp_showbc_code_start; void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip, mp_uint_t len) { mp_showbc_code_start = ip; - // get code info size + // get state size and exception stack size + mp_uint_t n_state = mp_decode_uint(&ip); + mp_uint_t n_exc_stack = mp_decode_uint(&ip); + + ip = MP_ALIGN(ip, sizeof(mp_uint_t)); + + // get and skip arg names + const mp_obj_t *arg_names = (const mp_obj_t*)ip; + ip += n_total_args * sizeof(mp_uint_t); + const byte *code_info = ip; mp_uint_t code_info_size = mp_decode_uint(&code_info); ip += code_info_size; @@ -65,7 +74,7 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip qstr block_name = mp_decode_uint(&code_info); qstr source_file = mp_decode_uint(&code_info); 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); + qstr_str(source_file), qstr_str(block_name), descr, mp_showbc_code_start, len); // raw bytecode dump printf("Raw bytecode (code_info_size=" UINT_FMT ", bytecode_size=" UINT_FMT "):\n", code_info_size, len - code_info_size); @@ -80,18 +89,15 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip // bytecode prelude: arg names (as qstr objects) printf("arg names:"); for (mp_uint_t i = 0; i < n_total_args; i++) { - printf(" %s", qstr_str(MP_OBJ_QSTR_VALUE(*(mp_obj_t*)ip))); - ip += sizeof(mp_obj_t); + printf(" %s", qstr_str(MP_OBJ_QSTR_VALUE(arg_names[i]))); } printf("\n"); - // bytecode prelude: state size and exception stack size; 16 bit uints - { - uint n_state = mp_decode_uint(&ip); - uint n_exc_stack = mp_decode_uint(&ip); - printf("(N_STATE %u)\n", n_state); - printf("(N_EXC_STACK %u)\n", n_exc_stack); - } + printf("(N_STATE " UINT_FMT ")\n", n_state); + printf("(N_EXC_STACK " UINT_FMT ")\n", n_exc_stack); + + // for printing line number info + const byte *bytecode_start = ip; // bytecode prelude: initialise closed over variables { @@ -104,7 +110,7 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip // print out line number info { - mp_int_t bc = (mp_showbc_code_start + code_info_size) - ip; // start counting from the prelude + mp_int_t bc = bytecode_start - ip; mp_uint_t source_line = 1; printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line); for (const byte* ci = code_info; *ci;) { |