GH-120024: Tidy up case generator code a bit. by markshannon · Pull Request #122780 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 63 additions & 25 deletions Tools/cases_generator/analyzer.py
7 changes: 3 additions & 4 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ def emit_to(out: CWriter, tkn_iter: Iterator[Token], end: str) -> None:
parens -= 1
out.emit(tkn)


ReplacementFunctionType = Callable[
[Token, Iterator[Token], Uop, Stack, Instruction | None], None
]

class Emitter:

class Emitter:
out: CWriter
_replacers: dict[str, ReplacementFunctionType]

Expand Down Expand Up @@ -176,7 +177,6 @@ def decref_inputs(
else:
self.out.emit(f"PyStackRef_CLOSE({var.name});\n")


def sync_sp(
self,
tkn: Token,
Expand All @@ -190,7 +190,6 @@ def sync_sp(
next(tkn_iter)
stack.flush(self.out)


def check_eval_breaker(
self,
tkn: Token,
Expand Down Expand Up @@ -227,7 +226,6 @@ def py_stack_ref_from_py_object_new(
# unused portions of the stack to NULL.
stack.flush_single_var(self.out, target, uop.stack.outputs)


def emit_tokens(
self,
uop: Uop,
Expand All @@ -248,6 +246,7 @@ def emit_tokens(
def emit(self, txt: str | Token) -> None:
self.out.emit(txt)


def cflags(p: Properties) -> str:
flags: list[str] = []
if p.oparg:
Expand Down
1 change: 1 addition & 0 deletions Tools/cases_generator/opcode_metadata_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def emit_stack_effect_function(
def generate_stack_effect_functions(analysis: Analysis, out: CWriter) -> None:
popped_data: list[tuple[str, str]] = []
pushed_data: list[tuple[str, str]] = []

def add(inst: Instruction | PseudoInstruction) -> None:
stack = get_stack_effect(inst)
popped = (-stack.base_offset).to_c()
Expand Down
13 changes: 7 additions & 6 deletions Tools/cases_generator/optimizer_generator.py
Loading