From 3039d8b4103061b1291cfd4e8b6dd1e9678fec6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20=C4=8Caklovi=C4=87?= Date: Thu, 24 Mar 2022 22:06:35 +0100 Subject: [PATCH] Disassembler changes in 3.10 under BPO-27129 --- bytecode.cpp | 17 ++++++++++++++++- bytecode.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bytecode.cpp b/bytecode.cpp index 6909834..12ed098 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -137,6 +137,12 @@ bool Pyc::IsCellArg(int opcode) (opcode == Pyc::STORE_DEREF_A); } +bool Pyc::IsJumpArg(int opcode) +{ + return (opcode == Pyc::POP_JUMP_IF_FALSE_A) || (opcode == Pyc::POP_JUMP_IF_TRUE_A) || + (opcode == Pyc::JUMP_IF_FALSE_OR_POP_A) || (opcode == JUMP_IF_TRUE_OR_POP_A); +} + bool Pyc::IsJumpOffsetArg(int opcode) { return (opcode == Pyc::JUMP_FORWARD_A) || (opcode == Pyc::JUMP_IF_FALSE_A) || @@ -385,7 +391,16 @@ void bc_disasm(PycRef code, PycModule* mod, int indent) fprintf(pyc_output, "%d ", operand); } } else if (Pyc::IsJumpOffsetArg(opcode)) { - fprintf(pyc_output, "%d (to %d)", operand, pos+operand); + int offs = operand; + if (mod->verCompare(3, 10) >= 0) + offs *= sizeof(uint16_t); // BPO-27129 + fprintf(pyc_output, "%d (to %d)", operand, pos+offs); + } + else if (Pyc::IsJumpArg(opcode)) { + if (mod->verCompare(3, 10) >= 0) // BPO-27129 + fprintf(pyc_output, "%d (to %d)", operand, int(operand * sizeof(uint16_t))); + else + fprintf(pyc_output, "%d", operand); } else if (Pyc::IsCompareArg(opcode)) { if (static_cast(operand) < cmp_strings_len) fprintf(pyc_output, "%d (%s)", operand, cmp_strings[operand]); diff --git a/bytecode.h b/bytecode.h index a577100..a9dc150 100644 --- a/bytecode.h +++ b/bytecode.h @@ -25,6 +25,7 @@ bool IsNameArg(int opcode); bool IsVarNameArg(int opcode); bool IsCellArg(int opcode); bool IsJumpOffsetArg(int opcode); +bool IsJumpArg(int opcode); bool IsCompareArg(int opcode); }