Skip to content

Commit

Permalink
calculate block ID and use it for label, instead of address
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Aug 23, 2022
1 parent 78f3fa9 commit ebb10bb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Python/compile.c
Expand Up @@ -9691,8 +9691,12 @@ cfg_to_instructions(cfg_builder *g)
if (instructions == NULL) {
return NULL;
}
int lbl = 1;
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
PyObject *lbl = PyLong_FromUnsignedLongLong((uintptr_t)b);
b->b_label = lbl++;
}
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
PyObject *lbl = PyLong_FromLong(b->b_label);
if (lbl == NULL) {
goto error;
}
Expand All @@ -9704,14 +9708,9 @@ cfg_to_instructions(cfg_builder *g)
for (int i = 0; i < b->b_iused; i++) {
struct instr *instr = &b->b_instr[i];
struct location loc = instr->i_loc;
uintptr_t arg = instr->i_oparg;
if (HAS_TARGET(instr->i_opcode)) {
/* Use the address of the block as its unique ID (for the label) */
arg = (uintptr_t)instr->i_target;
}

int arg = HAS_TARGET(instr->i_opcode) ? instr->i_target->b_label : instr->i_oparg;
PyObject *inst_tuple = Py_BuildValue(
"(iLiiii)", instr->i_opcode, arg,
"(iiiiii)", instr->i_opcode, arg,
loc.lineno, loc.end_lineno,
loc.col_offset, loc.end_col_offset);
if (inst_tuple == NULL) {
Expand Down

0 comments on commit ebb10bb

Please sign in to comment.