debug.c: export integer compressing functions.

- mrb_packed_int_len()
- mrb_packed_int_encode()
- mrb_packed_int_decode()
parent 96a8703c
...@@ -20,20 +20,7 @@ ...@@ -20,20 +20,7 @@
#define MRB_DEBUG_BP_FILE_OK (0x0001) #define MRB_DEBUG_BP_FILE_OK (0x0001)
#define MRB_DEBUG_BP_LINENO_OK (0x0002) #define MRB_DEBUG_BP_LINENO_OK (0x0002)
static uint32_t uint32_t mrb_packed_int_decode(uint8_t *p, uint8_t **newpos);
packed_int_decode(uint8_t *p, uint8_t **newpos)
{
size_t i = 0, shift = 0;
uint32_t n = 0;
do {
n |= ((uint32_t)(p[i] & 0x7f)) << shift;
i++;
shift += 7;
} while (shift < sizeof(uint32_t) * 8 && (p[i - 1] & 0x80));
if (newpos) *newpos = p + i;
return n;
}
static uint16_t static uint16_t
check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno) check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
...@@ -64,8 +51,8 @@ check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno) ...@@ -64,8 +51,8 @@ check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
uint8_t *pend = p + count; uint8_t *pend = p + count;
uint32_t line = 0; uint32_t line = 0;
while (p < pend) { while (p < pend) {
packed_int_decode(p, &p); mrb_packed_int_decode(p, &p);
line += packed_int_decode(p, &p); line += mrb_packed_int_decode(p, &p);
if (line == lineno) return lineno; if (line == lineno) return lineno;
} }
} }
......
...@@ -35,8 +35,8 @@ get_file(mrb_irep_debug_info *info, uint32_t pc) ...@@ -35,8 +35,8 @@ get_file(mrb_irep_debug_info *info, uint32_t pc)
return *ret; return *ret;
} }
static size_t size_t
packed_int_len(uint32_t num) mrb_packed_int_len(uint32_t num)
{ {
size_t llen = 0; size_t llen = 0;
...@@ -46,8 +46,8 @@ packed_int_len(uint32_t num) ...@@ -46,8 +46,8 @@ packed_int_len(uint32_t num)
return llen; return llen;
} }
static size_t size_t
packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend) mrb_packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend)
{ {
size_t llen = 0; size_t llen = 0;
...@@ -62,8 +62,8 @@ packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend) ...@@ -62,8 +62,8 @@ packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend)
return llen; return llen;
} }
static uint32_t uint32_t
packed_int_decode(uint8_t *p, uint8_t **newpos) mrb_packed_int_decode(uint8_t *p, uint8_t **newpos)
{ {
size_t i = 0, shift = 0; size_t i = 0, shift = 0;
uint32_t n = 0; uint32_t n = 0;
...@@ -135,8 +135,8 @@ mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc) ...@@ -135,8 +135,8 @@ mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc)
uint8_t *pend = p + f->line_entry_count; uint8_t *pend = p + f->line_entry_count;
uint32_t pos = 0, line = 0, line_diff; uint32_t pos = 0, line = 0, line_diff;
while (p < pend) { while (p < pend) {
pos += packed_int_decode(p, &p); pos += mrb_packed_int_decode(p, &p);
line_diff = packed_int_decode(p, &p); line_diff = mrb_packed_int_decode(p, &p);
if (pc < pos) break; if (pc < pos) break;
line += line_diff; line += line_diff;
} }
...@@ -204,9 +204,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d, ...@@ -204,9 +204,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
for (i = 0; i < file_pc_count; ++i) { for (i = 0; i < file_pc_count; ++i) {
if (lines[start_pos + i] == prev_line) continue; if (lines[start_pos + i] == prev_line) continue;
packed_size += packed_int_len(start_pos+i-prev_pc); packed_size += mrb_packed_int_len(start_pos+i-prev_pc);
prev_pc = start_pos+i; prev_pc = start_pos+i;
packed_size += packed_int_len(lines[start_pos+i]-prev_line); packed_size += mrb_packed_int_len(lines[start_pos+i]-prev_line);
prev_line = lines[start_pos + i]; prev_line = lines[start_pos + i];
} }
p = f->lines.packed_map = (uint8_t*)mrb_malloc(mrb, packed_size); p = f->lines.packed_map = (uint8_t*)mrb_malloc(mrb, packed_size);
...@@ -214,9 +214,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d, ...@@ -214,9 +214,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
prev_line = 0; prev_pc = 0; prev_line = 0; prev_pc = 0;
for (i = 0; i < file_pc_count; ++i) { for (i = 0; i < file_pc_count; ++i) {
if (lines[start_pos + i] == prev_line) continue; if (lines[start_pos + i] == prev_line) continue;
p += packed_int_encode(start_pos+i-prev_pc, p, pend); p += mrb_packed_int_encode(start_pos+i-prev_pc, p, pend);
prev_pc = start_pos + i; prev_pc = start_pos + i;
p += packed_int_encode(lines[start_pos + i]-prev_line, p, pend); p += mrb_packed_int_encode(lines[start_pos + i]-prev_line, p, pend);
prev_line = lines[start_pos + i]; prev_line = lines[start_pos + i];
} }
f->line_entry_count = (uint32_t)packed_size; f->line_entry_count = (uint32_t)packed_size;
......
Markdown is supported
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