Skip to content

Commit

Permalink
Add unknown opcode handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 10, 2025
1 parent 637589e commit 5615d6f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
49 changes: 49 additions & 0 deletions Python/generated_tail_call_handlers.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -9265,6 +9265,15 @@ Py_PRESERVE_NONE_CC static PyObject * _TAIL_CALL_YIELD_VALUE(TAIL_CALL_PARAMS){
}
}

Py_PRESERVE_NONE_CC static PyObject * _TAIL_CALL_UNKNOWN_OPCODE(TAIL_CALL_PARAMS){

int opcode = next_instr->op.code;
_PyErr_Format(tstate, PyExc_SystemError,
"%U:%d: unknown opcode %d",
_PyFrame_GetCode(frame)->co_filename,
PyUnstable_InterpreterFrame_GetLine(frame),
opcode);
CEVAL_GOTO(error);}
static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {
[BINARY_OP] = _TAIL_CALL_BINARY_OP,
[BINARY_OP_ADD_FLOAT] = _TAIL_CALL_BINARY_OP_ADD_FLOAT,
Expand Down Expand Up @@ -9482,5 +9491,45 @@ static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {
[UNPACK_SEQUENCE_TWO_TUPLE] = _TAIL_CALL_UNPACK_SEQUENCE_TWO_TUPLE,
[WITH_EXCEPT_START] = _TAIL_CALL_WITH_EXCEPT_START,
[YIELD_VALUE] = _TAIL_CALL_YIELD_VALUE,
[117] = _TAIL_CALL_UNKNOWN_OPCODE,
[118] = _TAIL_CALL_UNKNOWN_OPCODE,
[119] = _TAIL_CALL_UNKNOWN_OPCODE,
[120] = _TAIL_CALL_UNKNOWN_OPCODE,
[121] = _TAIL_CALL_UNKNOWN_OPCODE,
[122] = _TAIL_CALL_UNKNOWN_OPCODE,
[123] = _TAIL_CALL_UNKNOWN_OPCODE,
[124] = _TAIL_CALL_UNKNOWN_OPCODE,
[125] = _TAIL_CALL_UNKNOWN_OPCODE,
[126] = _TAIL_CALL_UNKNOWN_OPCODE,
[127] = _TAIL_CALL_UNKNOWN_OPCODE,
[128] = _TAIL_CALL_UNKNOWN_OPCODE,
[129] = _TAIL_CALL_UNKNOWN_OPCODE,
[130] = _TAIL_CALL_UNKNOWN_OPCODE,
[131] = _TAIL_CALL_UNKNOWN_OPCODE,
[132] = _TAIL_CALL_UNKNOWN_OPCODE,
[133] = _TAIL_CALL_UNKNOWN_OPCODE,
[134] = _TAIL_CALL_UNKNOWN_OPCODE,
[135] = _TAIL_CALL_UNKNOWN_OPCODE,
[136] = _TAIL_CALL_UNKNOWN_OPCODE,
[137] = _TAIL_CALL_UNKNOWN_OPCODE,
[138] = _TAIL_CALL_UNKNOWN_OPCODE,
[139] = _TAIL_CALL_UNKNOWN_OPCODE,
[140] = _TAIL_CALL_UNKNOWN_OPCODE,
[141] = _TAIL_CALL_UNKNOWN_OPCODE,
[142] = _TAIL_CALL_UNKNOWN_OPCODE,
[143] = _TAIL_CALL_UNKNOWN_OPCODE,
[144] = _TAIL_CALL_UNKNOWN_OPCODE,
[145] = _TAIL_CALL_UNKNOWN_OPCODE,
[146] = _TAIL_CALL_UNKNOWN_OPCODE,
[147] = _TAIL_CALL_UNKNOWN_OPCODE,
[148] = _TAIL_CALL_UNKNOWN_OPCODE,
[228] = _TAIL_CALL_UNKNOWN_OPCODE,
[229] = _TAIL_CALL_UNKNOWN_OPCODE,
[230] = _TAIL_CALL_UNKNOWN_OPCODE,
[231] = _TAIL_CALL_UNKNOWN_OPCODE,
[232] = _TAIL_CALL_UNKNOWN_OPCODE,
[233] = _TAIL_CALL_UNKNOWN_OPCODE,
[234] = _TAIL_CALL_UNKNOWN_OPCODE,
[235] = _TAIL_CALL_UNKNOWN_OPCODE,
};
#undef TIER_ONE
20 changes: 18 additions & 2 deletions Tools/cases_generator/tier1_tail_call_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def generate_tier1(
out.emit("static inline PyObject *_TAIL_CALL_shim(TAIL_CALL_PARAMS);\n")
out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256];\n");

# Emit error handlers

generate_label_handlers(outfile)

emitter = Emitter(out)
Expand All @@ -105,9 +103,27 @@ def generate_tier1(

out.emit("\n")

# Emit unknown opcode handler.
out.emit(function_proto("UNKNOWN_OPCODE"))
out.emit("{\n")
out.emit("""
int opcode = next_instr->op.code;
_PyErr_Format(tstate, PyExc_SystemError,
"%U:%d: unknown opcode %d",
_PyFrame_GetCode(frame)->co_filename,
PyUnstable_InterpreterFrame_GetLine(frame),
opcode);
""")
out.emit("CEVAL_GOTO(error);")
out.emit("}\n")

out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {\n")
for name in sorted(analysis.instructions.keys()):
out.emit(f"[{name}] = _TAIL_CALL_{name},\n")
named_values = analysis.opmap.values()
for rest in range(256):
if rest not in named_values:
out.emit(f"[{rest}] = _TAIL_CALL_UNKNOWN_OPCODE,\n")
out.emit("};\n")
outfile.write(FOOTER)

Expand Down

0 comments on commit 5615d6f

Please sign in to comment.