Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only output uop names in debug mode
  • Loading branch information
gvanrossum committed Jun 27, 2023
commit 60403c9dc88afdb33b234cbf9cddc51862ab1c0f
4 changes: 4 additions & 0 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,9 @@ struct opcode_macro_expansion {
#ifndef NEED_OPCODE_METADATA
extern const struct opcode_metadata _PyOpcode_opcode_metadata[512];
extern const struct opcode_macro_expansion _PyOpcode_macro_expansion[256];
#ifdef Py_DEBUG
extern const char *_PyOpcode_uop_name[512];
#endif
#else
const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {
[NOP] = { true, INSTR_FMT_IX, 0 },
Expand Down Expand Up @@ -1219,6 +1221,7 @@ const struct opcode_macro_expansion _PyOpcode_macro_expansion[256] = {
[COPY] = { .nuops = 1, .uops = { { COPY, 0, 0 } } },
[SWAP] = { .nuops = 1, .uops = { { SWAP, 0, 0 } } },
};
#ifdef Py_DEBUG
const char *_PyOpcode_uop_name[512] = {
[300] = "EXIT_TRACE",
[301] = "SET_IP",
Expand All @@ -1236,3 +1239,4 @@ const char *_PyOpcode_uop_name[512] = {
[313] = "_LOAD_FROM_DICT_OR_GLOBALS",
};
#endif
#endif
4 changes: 4 additions & 0 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,9 @@ def write_metadata(self) -> None:
self.out.emit("#ifndef NEED_OPCODE_METADATA")
self.out.emit("extern const struct opcode_metadata _PyOpcode_opcode_metadata[512];")
self.out.emit("extern const struct opcode_macro_expansion _PyOpcode_macro_expansion[256];")
self.out.emit("#ifdef Py_DEBUG")
self.out.emit("extern const char *_PyOpcode_uop_name[512];")
self.out.emit("#endif")
self.out.emit("#else")

self.out.emit("const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {")
Expand Down Expand Up @@ -1265,8 +1267,10 @@ def write_metadata(self) -> None:
case _:
typing.assert_never(thing)

self.out.emit("#ifdef Py_DEBUG")
with self.out.block("const char *_PyOpcode_uop_name[512] =", ";"):
self.write_uop_items(lambda name, counter: f"[{counter}] = \"{name}\",")
self.out.emit("#endif")

self.out.emit("#endif")

Expand Down