GH-98831: Auto-generate PREDICTED() macro calls (#99102)

Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
Guido van Rossum 2022-11-04 15:30:17 -07:00 committed by GitHub
parent e99380cc39
commit c885623e9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 16 deletions

View file

@ -6,6 +6,7 @@
import argparse
import io
import re
import sys
import parser
@ -61,12 +62,18 @@ def always_exits(block: parser.Block) -> bool:
def write_cases(f: io.TextIOBase, instrs: list[InstDef]):
predictions = set()
for inst in instrs:
for target in re.findall(r"(?:PREDICT|GO_TO_INSTRUCTION)\((\w+)\)", inst.block.text):
predictions.add(target)
indent = " "
f.write("// This file is generated by Tools/scripts/generate_cases.py\n")
f.write("// Do not edit!\n")
for instr in instrs:
assert isinstance(instr, InstDef)
f.write(f"\n{indent}TARGET({instr.name}) {{\n")
if instr.name in predictions:
f.write(f"{indent} PREDICTED({instr.name});\n")
# input = ", ".join(instr.inputs)
# output = ", ".join(instr.outputs)
# f.write(f"{indent} // {input} -- {output}\n")