Skip to content

Commit 5d56130

Browse files
Address review by removing in test cases generator
1 parent e1f9475 commit 5d56130

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

Lib/test/test_generated_cases.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,23 @@ def run_cases_test(self, input: str, expected: str):
253253
lines.pop(0)
254254
while lines and lines[-1].startswith(("#", "\n")):
255255
lines.pop(-1)
256+
while lines and tier1_generator.INSTRUCTION_START_MARKER not in lines[0]:
257+
lines.pop(0)
258+
lines.pop(0)
259+
for instruction_end_marker_index, line in enumerate(lines):
260+
if tier1_generator.INSTRUCTION_END_MARKER in line:
261+
break
262+
else:
263+
assert False, "No instruction end marker found."
264+
for label_start_marker_index, line in enumerate(lines):
265+
if tier1_generator.LABEL_START_MARKER in line:
266+
break
267+
else:
268+
assert False, "No label start marker found."
269+
del lines[instruction_end_marker_index:label_start_marker_index+1]
270+
# Pop the label markers themselves
271+
lines.pop(0)
272+
lines.pop(-1)
256273
actual = "".join(lines)
257274
# if actual.strip() != expected.strip():
258275
# print("Actual:")

Tools/cases_generator/tier1_generator.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333

3434
FOOTER = "#undef TIER_ONE\n"
35+
INSTRUCTION_START_MARKER = "/* BEGIN INSTRUCTIONS */"
36+
INSTRUCTION_END_MARKER = "/* END INSTRUCTIONS */"
37+
LABEL_START_MARKER = "/* BEGIN LABEL */"
38+
LABEL_END_MARKER = "/* END LABEL */"
3539

3640

3741
def declare_variable(var: StackItem, out: CWriter) -> None:
@@ -130,22 +134,23 @@ def generate_tier1(
130134
) -> None:
131135
write_header(__file__, filenames, outfile)
132136
outfile.write(
133-
"""
137+
f"""
134138
#ifdef TIER_TWO
135139
#error "This file is for Tier 1 only"
136140
#endif
137141
#define TIER_ONE 1
138142
139-
/* Start instructions */
140143
#if !USE_COMPUTED_GOTOS
141144
dispatch_opcode:
142145
switch (opcode)
143146
#endif
144-
{
147+
{{
148+
{INSTRUCTION_START_MARKER}
145149
"""
146150
)
147151
generate_tier1_cases(analysis, outfile, lines)
148-
outfile.write("""
152+
outfile.write(f"""
153+
{INSTRUCTION_END_MARKER}
149154
#if USE_COMPUTED_GOTOS
150155
_unknown_opcode:
151156
#else
@@ -161,13 +166,15 @@ def generate_tier1(
161166
opcode);
162167
goto error;
163168
164-
} /* End instructions */
169+
}}
165170
166171
/* This should never be reached. Every opcode should end with DISPATCH()
167172
or goto error. */
168173
Py_UNREACHABLE();
174+
{LABEL_START_MARKER}
169175
""")
170176
generate_tier1_labels(analysis, outfile, lines)
177+
outfile.write(f"{LABEL_END_MARKER}\n")
171178
outfile.write(FOOTER)
172179

173180
def generate_tier1_labels(
@@ -255,8 +262,7 @@ def generate_tier1_from_files(
255262
) -> None:
256263
data = analyze_files(filenames)
257264
with open(outfilename, "w") as outfile:
258-
generate_tier1_cases(data, outfile, lines)
259-
generate_tier1_labels(data, outfile, lines)
265+
generate_tier1(filenames, data, outfile, lines)
260266

261267

262268
if __name__ == "__main__":

0 commit comments

Comments
 (0)