Show binary ops from Python 3.11 in disassembly

This commit is contained in:
Michael Hansen
2023-05-30 14:45:22 -07:00
parent 0710ea07f1
commit ee934a1e99

View File

@@ -371,6 +371,12 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent, unsigned flags)
};
static const size_t cmp_strings_len = sizeof(cmp_strings) / sizeof(cmp_strings[0]);
static const char *binop_strings[] = {
"+", "&", "//", "<<", "@", "*", "%", "|", "**", ">>", "-", "/", "^",
"+=", "&=", "//=", "<<=", "@=", "*=", "%=", "|=", "**=", ">>=", "-=", "/=", "^=",
};
static const size_t binop_strings_len = sizeof(binop_strings) / sizeof(binop_strings[0]);
PycBuffer source(code->code()->value(), code->code()->length());
int opcode, operand;
@@ -437,6 +443,11 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent, unsigned flags)
fprintf(pyc_output, "%d (%s)", operand, cmp_strings[operand]);
else
fprintf(pyc_output, "%d (UNKNOWN)", operand);
} else if (opcode == Pyc::BINARY_OP_A) {
if (static_cast<size_t>(operand) < binop_strings_len)
fprintf(pyc_output, "%d (%s)", operand, binop_strings[operand]);
else
fprintf(pyc_output, "%d (UNKNOWN)", operand);
} else if (opcode == Pyc::IS_OP_A) {
fprintf(pyc_output, "%d (%s)", operand, (operand == 0) ? "is"
: (operand == 1) ? "is not"