MCPcopy Index your code
hub / github.com/python/cpython / write_opcode_targets

Function write_opcode_targets

Tools/cases_generator/target_generator.py:23–44  ·  view source on GitHub ↗

Write header file that defines the jump target table

(analysis: Analysis, out: CWriter)

Source from the content-addressed store, hash-verified

21
22
23def write_opcode_targets(analysis: Analysis, out: CWriter) -> None:
24 """Write header file that defines the jump target table"""
25 targets = ["&&_unknown_opcode,\n"] * 256
26 for name, op in analysis.opmap.items():
27 if op < 256:
28 targets[op] = f"&&TARGET_{name},\n"
29 out.emit("#if !_Py_TAIL_CALL_INTERP\n")
30 out.emit("static void *opcode_targets_table[256] = {\n")
31 for target in targets:
32 out.emit(target)
33 out.emit("};\n")
34 targets = ["&&_unknown_opcode,\n"] * 256
35 for name, op in analysis.opmap.items():
36 if op < 256:
37 targets[op] = f"&&TARGET_TRACE_RECORD,\n"
38 out.emit("#if _Py_TIER2\n")
39 out.emit("static void *opcode_tracing_targets_table[256] = {\n")
40 for target in targets:
41 out.emit(target)
42 out.emit("};\n")
43 out.emit(f"#endif\n")
44 out.emit("#else /* _Py_TAIL_CALL_INTERP */\n")
45
46def function_proto(name: str) -> str:
47 return f"static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_{name}(TAIL_CALL_PARAMS)"

Callers 1

Calls 2

itemsMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…