mirror of
https://github.com/python/cpython
synced 2026-09-29 11:35:29 +03:00
GH-111485: Test the new cases generator (GH-113252)
This commit is contained in:
parent
4a24bf9a13
commit
771903596b
8 changed files with 116 additions and 88 deletions
|
|
@ -444,7 +444,8 @@ def analyze_forest(forest: list[parser.AstNode]) -> Analysis:
|
|||
if target.text in instructions:
|
||||
instructions[target.text].is_target = True
|
||||
# Hack
|
||||
instructions["BINARY_OP_INPLACE_ADD_UNICODE"].family = families["BINARY_OP"]
|
||||
if "BINARY_OP_INPLACE_ADD_UNICODE" in instructions:
|
||||
instructions["BINARY_OP_INPLACE_ADD_UNICODE"].family = families["BINARY_OP"]
|
||||
return Analysis(instructions, uops, families, pseudos)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ class CWriter:
|
|||
parens = txt.count("(") - txt.count(")")
|
||||
if parens < 0:
|
||||
self.indents.pop()
|
||||
elif "}" in txt or is_label(txt):
|
||||
braces = txt.count("{") - txt.count("}")
|
||||
if braces < 0 or is_label(txt):
|
||||
self.indents.pop()
|
||||
|
||||
def maybe_indent(self, txt: str) -> None:
|
||||
|
|
@ -50,11 +51,13 @@ class CWriter:
|
|||
self.indents.append(offset)
|
||||
if is_label(txt):
|
||||
self.indents.append(self.indents[-1] + 4)
|
||||
elif "{" in txt:
|
||||
if 'extern "C"' in txt:
|
||||
self.indents.append(self.indents[-1])
|
||||
else:
|
||||
self.indents.append(self.indents[-1] + 4)
|
||||
else:
|
||||
braces = txt.count("{") - txt.count("}")
|
||||
if braces > 0:
|
||||
if 'extern "C"' in txt:
|
||||
self.indents.append(self.indents[-1])
|
||||
else:
|
||||
self.indents.append(self.indents[-1] + 4)
|
||||
|
||||
def emit_text(self, txt: str) -> None:
|
||||
self.out.write(txt)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@ DEFAULT_INPUT = (ROOT / "Python/bytecodes.c").absolute().as_posix()
|
|||
|
||||
|
||||
def root_relative_path(filename: str) -> str:
|
||||
return Path(filename).absolute().relative_to(ROOT).as_posix()
|
||||
|
||||
try:
|
||||
return Path(filename).absolute().relative_to(ROOT).as_posix()
|
||||
except ValueError:
|
||||
return filename
|
||||
|
||||
def write_header(generator: str, sources: list[str], outfile: TextIO) -> None:
|
||||
outfile.write(
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class Stack:
|
|||
cast = "(PyObject *)" if var.type else ""
|
||||
if var.name != "unused" and not var.is_array():
|
||||
if var.condition:
|
||||
out.emit(f" if ({var.condition}) ")
|
||||
out.emit(f"if ({var.condition}) ")
|
||||
out.emit(
|
||||
f"stack_pointer[{self.base_offset.to_c()}] = {cast}{var.name};\n"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -181,6 +181,14 @@ arg_parser.add_argument(
|
|||
"input", nargs=argparse.REMAINDER, help="Instruction definition file(s)"
|
||||
)
|
||||
|
||||
|
||||
def generate_tier1_from_files(
|
||||
filenames: list[str], outfilename: str, lines: bool
|
||||
) -> None:
|
||||
data = analyze_files(filenames)
|
||||
with open(outfilename, "w") as outfile:
|
||||
generate_tier1(filenames, data, outfile, lines)
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = arg_parser.parse_args()
|
||||
if len(args.input) == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue