Skip to content

Commit df10346

Browse files
committed
showbc: Make code object start pointer semi-public.
This allows to pring either absolute addresses or relative offsets in jumps and code references.
1 parent 7495750 commit df10346

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

py/showbc.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
ip += sizeof(mp_uint_t); \
5858
} while (0)
5959

60-
static const byte *ip_start;
60+
const byte *mp_showbc_code_start;
6161

6262
void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip, mp_uint_t len) {
63-
ip_start = ip;
63+
mp_showbc_code_start = ip;
6464

6565
// get code info size
6666
const byte *code_info = ip;
@@ -78,7 +78,7 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip
7878
if (i > 0 && i % 16 == 0) {
7979
printf("\n");
8080
}
81-
printf(" %02x", ip_start[i]);
81+
printf(" %02x", mp_showbc_code_start[i]);
8282
}
8383
printf("\n");
8484

@@ -106,12 +106,12 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip
106106
uint local_num = *ip++;
107107
printf("(INIT_CELL %u)\n", local_num);
108108
}
109-
len -= ip - ip_start;
109+
len -= ip - mp_showbc_code_start;
110110
}
111111

112112
// print out line number info
113113
{
114-
mp_int_t bc = (ip_start + code_info_size) - ip; // start counting from the prelude
114+
mp_int_t bc = (mp_showbc_code_start + code_info_size) - ip; // start counting from the prelude
115115
mp_uint_t source_line = 1;
116116
printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
117117
for (const byte* ci = code_info; *ci;) {
@@ -294,32 +294,32 @@ const byte *mp_bytecode_print_str(const byte *ip) {
294294

295295
case MP_BC_JUMP:
296296
DECODE_SLABEL;
297-
printf("JUMP " UINT_FMT, ip + unum - ip_start);
297+
printf("JUMP " UINT_FMT, ip + unum - mp_showbc_code_start);
298298
break;
299299

300300
case MP_BC_POP_JUMP_IF_TRUE:
301301
DECODE_SLABEL;
302-
printf("POP_JUMP_IF_TRUE " INT_FMT, ip + unum - ip_start);
302+
printf("POP_JUMP_IF_TRUE " INT_FMT, ip + unum - mp_showbc_code_start);
303303
break;
304304

305305
case MP_BC_POP_JUMP_IF_FALSE:
306306
DECODE_SLABEL;
307-
printf("POP_JUMP_IF_FALSE " INT_FMT, ip + unum - ip_start);
307+
printf("POP_JUMP_IF_FALSE " INT_FMT, ip + unum - mp_showbc_code_start);
308308
break;
309309

310310
case MP_BC_JUMP_IF_TRUE_OR_POP:
311311
DECODE_SLABEL;
312-
printf("JUMP_IF_TRUE_OR_POP " INT_FMT, ip + unum - ip_start);
312+
printf("JUMP_IF_TRUE_OR_POP " INT_FMT, ip + unum - mp_showbc_code_start);
313313
break;
314314

315315
case MP_BC_JUMP_IF_FALSE_OR_POP:
316316
DECODE_SLABEL;
317-
printf("JUMP_IF_FALSE_OR_POP " INT_FMT, ip + unum - ip_start);
317+
printf("JUMP_IF_FALSE_OR_POP " INT_FMT, ip + unum - mp_showbc_code_start);
318318
break;
319319

320320
case MP_BC_SETUP_WITH:
321321
DECODE_ULABEL; // loop-like labels are always forward
322-
printf("SETUP_WITH " UINT_FMT, ip + unum - ip_start);
322+
printf("SETUP_WITH " UINT_FMT, ip + unum - mp_showbc_code_start);
323323
break;
324324

325325
case MP_BC_WITH_CLEANUP:
@@ -328,18 +328,18 @@ const byte *mp_bytecode_print_str(const byte *ip) {
328328

329329
case MP_BC_UNWIND_JUMP:
330330
DECODE_SLABEL;
331-
printf("UNWIND_JUMP " UINT_FMT " %d", ip + unum - ip_start, *ip);
331+
printf("UNWIND_JUMP " UINT_FMT " %d", ip + unum - mp_showbc_code_start, *ip);
332332
ip += 1;
333333
break;
334334

335335
case MP_BC_SETUP_EXCEPT:
336336
DECODE_ULABEL; // except labels are always forward
337-
printf("SETUP_EXCEPT " UINT_FMT, ip + unum - ip_start);
337+
printf("SETUP_EXCEPT " UINT_FMT, ip + unum - mp_showbc_code_start);
338338
break;
339339

340340
case MP_BC_SETUP_FINALLY:
341341
DECODE_ULABEL; // except labels are always forward
342-
printf("SETUP_FINALLY " UINT_FMT, ip + unum - ip_start);
342+
printf("SETUP_FINALLY " UINT_FMT, ip + unum - mp_showbc_code_start);
343343
break;
344344

345345
case MP_BC_END_FINALLY:
@@ -356,7 +356,7 @@ const byte *mp_bytecode_print_str(const byte *ip) {
356356

357357
case MP_BC_FOR_ITER:
358358
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
359-
printf("FOR_ITER " UINT_FMT, ip + unum - ip_start);
359+
printf("FOR_ITER " UINT_FMT, ip + unum - mp_showbc_code_start);
360360
break;
361361

362362
case MP_BC_POP_BLOCK:
@@ -522,9 +522,9 @@ const byte *mp_bytecode_print_str(const byte *ip) {
522522
}
523523

524524
void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
525-
ip_start = ip;
526-
while (ip - ip_start < len) {
527-
printf("%02u ", (uint)(ip - ip_start));
525+
mp_showbc_code_start = ip;
526+
while (ip - mp_showbc_code_start < len) {
527+
printf("%02u ", (uint)(ip - mp_showbc_code_start));
528528
ip = mp_bytecode_print_str(ip);
529529
printf("\n");
530530
}

0 commit comments

Comments
 (0)