diff options
author | Damien George <damien.p.george@gmail.com> | 2019-09-25 15:45:47 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-10-01 12:26:22 +1000 |
commit | c8c0fd4ca39fbdcf9ca5f2fc99ca4d6b81a28b65 (patch) | |
tree | 0fcbf3a263817be928c0b7db847d94293c79cce5 /py/profile.c | |
parent | b5ebfadbd615de42c43851f27a062bacd9147996 (diff) |
py: Rework and compress second part of bytecode prelude.
This patch compresses the second part of the bytecode prelude which
contains the source file name, function name, source-line-number mapping
and cell closure information. This part of the prelude now begins with a
single varible length unsigned integer which encodes 2 numbers, being the
byte-size of the following 2 sections in the header: the "source info
section" and the "closure section". After decoding this variable unsigned
integer it's possible to skip over one or both of these sections very
easily.
This scheme saves about 2 bytes for most functions compared to the original
format: one in the case that there are no closure cells, and one because
padding was eliminated.
Diffstat (limited to 'py/profile.c')
-rw-r--r-- | py/profile.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/py/profile.c b/py/profile.c index 230bb7cc2..f16d4d701 100644 --- a/py/profile.c +++ b/py/profile.c @@ -34,7 +34,7 @@ STATIC uint mp_prof_bytecode_lineno(const mp_raw_code_t *rc, size_t bc) { const mp_bytecode_prelude_t *prelude = &rc->prelude; - return mp_bytecode_get_source_line(prelude->line_info, bc + prelude->opcodes - prelude->locals); + return mp_bytecode_get_source_line(prelude->line_info, bc); } void mp_prof_extract_prelude(const byte *bytecode, mp_bytecode_prelude_t *prelude) { @@ -48,22 +48,15 @@ void mp_prof_extract_prelude(const byte *bytecode, mp_bytecode_prelude_t *prelud prelude->n_kwonly_args = n_kwonly_args; prelude->n_def_pos_args = n_def_pos_args; - const byte *code_info = ip; - size_t code_info_size = mp_decode_uint(&ip); + MP_BC_PRELUDE_SIZE_DECODE(ip); + + prelude->line_info = ip + 4; + prelude->opcodes = ip + n_info + n_cell; qstr block_name = ip[0] | (ip[1] << 8); qstr source_file = ip[2] | (ip[3] << 8); - ip += 4; prelude->qstr_block_name = block_name; prelude->qstr_source_file = source_file; - - prelude->line_info = ip; - prelude->locals = code_info + code_info_size; - - ip = prelude->locals; - while (*ip++ != 255) { - } - prelude->opcodes = ip; } /******************************************************************************/ |