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

Function write_tailcall_dispatch_table

Tools/cases_generator/target_generator.py:50–93  ·  view source on GitHub ↗
(analysis: Analysis, out: CWriter)

Source from the content-addressed store, hash-verified

48
49
50def write_tailcall_dispatch_table(analysis: Analysis, out: CWriter) -> None:
51 out.emit("static py_tail_call_funcptr instruction_funcptr_handler_table[256];\n")
52 out.emit("\n")
53 out.emit("static py_tail_call_funcptr instruction_funcptr_tracing_table[256];\n")
54 out.emit("\n")
55
56 # Emit function prototypes for labels.
57 for name in analysis.labels:
58 out.emit(f"{function_proto(name)};\n")
59 out.emit("\n")
60
61 # Emit function prototypes for opcode handlers.
62 for name in sorted(analysis.instructions.keys()):
63 out.emit(f"{function_proto(name)};\n")
64 out.emit("\n")
65
66 # Emit unknown opcode handler.
67 out.emit(function_proto("UNKNOWN_OPCODE"))
68 out.emit(" {\n")
69 out.emit("int opcode = next_instr->op.code;\n")
70 out.emit(UNKNOWN_OPCODE_HANDLER)
71 out.emit("}\n")
72 out.emit("\n")
73
74 # Emit the dispatch table.
75 out.emit("static py_tail_call_funcptr instruction_funcptr_handler_table[256] = {\n")
76 for name in sorted(analysis.instructions.keys()):
77 out.emit(f"[{name}] = _TAIL_CALL_{name},\n")
78 named_values = analysis.opmap.values()
79 for rest in range(256):
80 if rest not in named_values:
81 out.emit(f"[{rest}] = _TAIL_CALL_UNKNOWN_OPCODE,\n")
82 out.emit("};\n")
83
84 # Emit the tracing dispatch table.
85 out.emit("static py_tail_call_funcptr instruction_funcptr_tracing_table[256] = {\n")
86 for name in sorted(analysis.instructions.keys()):
87 out.emit(f"[{name}] = _TAIL_CALL_TRACE_RECORD,\n")
88 named_values = analysis.opmap.values()
89 for rest in range(256):
90 if rest not in named_values:
91 out.emit(f"[{rest}] = _TAIL_CALL_UNKNOWN_OPCODE,\n")
92 out.emit("};\n")
93 outfile.write("#endif /* _Py_TAIL_CALL_INTERP */\n")
94
95arg_parser = argparse.ArgumentParser(
96 description="Generate the file with dispatch targets.",

Callers 1

Calls 5

function_protoFunction · 0.85
emitMethod · 0.45
keysMethod · 0.45
valuesMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…