Skip to content

gh-128563: Move labels in ceval.c to bytecodes.c #129112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ def run_cases_test(self, input: str, expected: str):
lines.pop(0)
while lines and lines[-1].startswith(("#", "\n")):
lines.pop(-1)
while lines and tier1_generator.INSTRUCTION_START_MARKER not in lines[0]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this line by line processing, including the start and end comment stripping, by splitting the whole file on INSTRUCTION_START_MARKER and INSTRUCTION_START_MARKER, discarding the first and last parts.

text = temp_output.read()
_, rest = text.split(INSTRUCTION_START_MARKER)
actual, _ = rest.split(LABEL_START_MARKER)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation. Thanks!

lines.pop(0)
lines.pop(0)
for instruction_end_marker_index, line in enumerate(lines):
if tier1_generator.INSTRUCTION_END_MARKER in line:
break
else:
assert False, "No instruction end marker found."
for label_start_marker_index, line in enumerate(lines):
if tier1_generator.LABEL_START_MARKER in line:
break
else:
assert False, "No label start marker found."
del lines[instruction_end_marker_index:label_start_marker_index+1]
# Pop the label markers themselves
lines.pop(0)
lines.pop(-1)
actual = "".join(lines)
# if actual.strip() != expected.strip():
# print("Actual:")
Expand Down
20 changes: 13 additions & 7 deletions Tools/cases_generator/tier1_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@


FOOTER = "#undef TIER_ONE\n"
INSTRUCTION_START_MARKER = "/* BEGIN INSTRUCTIONS */"
INSTRUCTION_END_MARKER = "/* END INSTRUCTIONS */"
LABEL_START_MARKER = "/* BEGIN LABEL */"
LABEL_END_MARKER = "/* END LABEL */"


def declare_variable(var: StackItem, out: CWriter) -> None:
Expand Down Expand Up @@ -130,22 +134,23 @@ def generate_tier1(
) -> None:
write_header(__file__, filenames, outfile)
outfile.write(
"""
f"""
#ifdef TIER_TWO
#error "This file is for Tier 1 only"
#endif
#define TIER_ONE 1

/* Start instructions */
#if !USE_COMPUTED_GOTOS
dispatch_opcode:
switch (opcode)
#endif
{
{{
{INSTRUCTION_START_MARKER}
"""
)
generate_tier1_cases(analysis, outfile, lines)
outfile.write("""
outfile.write(f"""
{INSTRUCTION_END_MARKER}
#if USE_COMPUTED_GOTOS
_unknown_opcode:
#else
Expand All @@ -161,13 +166,15 @@ def generate_tier1(
opcode);
goto error;

} /* End instructions */
}}

/* This should never be reached. Every opcode should end with DISPATCH()
or goto error. */
Py_UNREACHABLE();
{LABEL_START_MARKER}
""")
generate_tier1_labels(analysis, outfile, lines)
outfile.write(f"{LABEL_END_MARKER}\n")
outfile.write(FOOTER)

def generate_tier1_labels(
Expand Down Expand Up @@ -255,8 +262,7 @@ def generate_tier1_from_files(
) -> None:
data = analyze_files(filenames)
with open(outfilename, "w") as outfile:
generate_tier1_cases(data, outfile, lines)
generate_tier1_labels(data, outfile, lines)
generate_tier1(filenames, data, outfile, lines)


if __name__ == "__main__":
Expand Down
Loading