mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-133273: Keep instruction definitions in bytecodes.c
and optimizer_bytecodes.c
in sync (GH-133320)
This commit is contained in:
parent
5f3d3f2a6c
commit
3f2f59a91d
4 changed files with 372 additions and 134 deletions
|
@ -30,16 +30,52 @@ DEFAULT_ABSTRACT_INPUT = (ROOT / "Python/optimizer_bytecodes.c").absolute().as_p
|
|||
|
||||
|
||||
def validate_uop(override: Uop, uop: Uop) -> None:
|
||||
# To do
|
||||
pass
|
||||
"""
|
||||
Check that the overridden uop (defined in 'optimizer_bytecodes.c')
|
||||
has the same stack effects as the original uop (defined in 'bytecodes.c').
|
||||
|
||||
Ensure that:
|
||||
- The number of inputs and outputs is the same.
|
||||
- The names of the inputs and outputs are the same
|
||||
(except for 'unused' which is ignored).
|
||||
- The sizes of the inputs and outputs are the same.
|
||||
"""
|
||||
for stack_effect in ('inputs', 'outputs'):
|
||||
orig_effects = getattr(uop.stack, stack_effect)
|
||||
new_effects = getattr(override.stack, stack_effect)
|
||||
|
||||
if len(orig_effects) != len(new_effects):
|
||||
msg = (
|
||||
f"{uop.name}: Must have the same number of {stack_effect} "
|
||||
"in bytecodes.c and optimizer_bytecodes.c "
|
||||
f"({len(orig_effects)} != {len(new_effects)})"
|
||||
)
|
||||
raise analysis_error(msg, override.body.open)
|
||||
|
||||
for orig, new in zip(orig_effects, new_effects, strict=True):
|
||||
if orig.name != new.name and orig.name != "unused" and new.name != "unused":
|
||||
msg = (
|
||||
f"{uop.name}: {stack_effect.capitalize()} must have "
|
||||
"equal names in bytecodes.c and optimizer_bytecodes.c "
|
||||
f"({orig.name} != {new.name})"
|
||||
)
|
||||
raise analysis_error(msg, override.body.open)
|
||||
|
||||
if orig.size != new.size:
|
||||
msg = (
|
||||
f"{uop.name}: {stack_effect.capitalize()} must have "
|
||||
"equal sizes in bytecodes.c and optimizer_bytecodes.c "
|
||||
f"({orig.size!r} != {new.size!r})"
|
||||
)
|
||||
raise analysis_error(msg, override.body.open)
|
||||
|
||||
|
||||
def type_name(var: StackItem) -> str:
|
||||
if var.is_array():
|
||||
return f"JitOptSymbol **"
|
||||
return "JitOptSymbol **"
|
||||
if var.type:
|
||||
return var.type
|
||||
return f"JitOptSymbol *"
|
||||
return "JitOptSymbol *"
|
||||
|
||||
|
||||
def declare_variables(uop: Uop, out: CWriter, skip_inputs: bool) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue