Fix FORMAT_VALUE for values that have both a conversion and a format_spec.

Also output the conversion and flags in disassembly.
This commit is contained in:
Michael Hansen
2024-08-01 13:27:43 -07:00
parent 6ad3ceb67e
commit 0b45b5fa07
7 changed files with 38 additions and 34 deletions

View File

@@ -331,6 +331,11 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
};
static const size_t intrinsic2_names_len = sizeof(intrinsic2_names) / sizeof(intrinsic2_names[0]);
static const char *format_value_names[] = {
"FVC_NONE", "FVC_STR", "FVC_REPR", "FVC_ASCII",
};
static const size_t format_value_names_len = sizeof(format_value_names) / sizeof(format_value_names[0]);
PycBuffer source(code->code()->value(), code->code()->length());
int opcode, operand;
@@ -530,6 +535,18 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
else
formatted_print(pyc_output, "%d (UNKNOWN)", operand);
break;
case Pyc::FORMAT_VALUE_A:
{
auto conv = static_cast<size_t>(operand & 0x03);
const char *flag = (operand & 0x04) ? " | FVS_HAVE_SPEC" : "";
if (conv < format_value_names_len) {
formatted_print(pyc_output, "%d (%s%s)", operand,
format_value_names[conv], flag);
} else {
formatted_print(pyc_output, "%d (UNKNOWN)", operand);
}
}
break;
default:
formatted_print(pyc_output, "%d", operand);
break;