diff options
author | Damien George <damien.p.george@gmail.com> | 2019-08-30 16:41:08 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-08-30 16:43:46 +1000 |
commit | dbf35d3da359a2ddbccb1ea2116da37e23ce46bf (patch) | |
tree | 06f0c01144358a220563ef026971f97185f1d01b /py/bc.h | |
parent | c7c6703950ef14f04ff9ad9d6b61b4b0666144c0 (diff) |
py/bc: Factor out code to get bytecode line number info into new func.
Diffstat (limited to 'py/bc.h')
-rw-r--r-- | py/bc.h | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -119,4 +119,31 @@ uint mp_opcode_format(const byte *ip, size_t *opcode_size, bool count_var_uint); #endif +static inline size_t mp_bytecode_get_source_line(const byte *line_info, size_t bc_offset) { + size_t source_line = 1; + size_t c; + while ((c = *line_info)) { + size_t b, l; + if ((c & 0x80) == 0) { + // 0b0LLBBBBB encoding + b = c & 0x1f; + l = c >> 5; + line_info += 1; + } else { + // 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte) + b = c & 0xf; + l = ((c << 4) & 0x700) | line_info[1]; + line_info += 2; + } + if (bc_offset >= b) { + bc_offset -= b; + source_line += l; + } else { + // found source line corresponding to bytecode offset + break; + } + } + return source_line; +} + #endif // MICROPY_INCLUDED_PY_BC_H |