diff options
author | Guido van Rossum <guido@python.org> | 2023-01-31 01:27:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 01:27:51 (GMT) |
commit | 04ab767d28024b7a42b630a817227b02097aef30 (patch) | |
tree | 8b798a0ef45cc7e3eead1e01782230256142f0a7 /Tools/cases_generator | |
parent | af7b2db38497479238bba3f7edba1d8f8d685c4f (diff) | |
download | cpython-04ab767d28024b7a42b630a817227b02097aef30.zip cpython-04ab767d28024b7a42b630a817227b02097aef30.tar.gz cpython-04ab767d28024b7a42b630a817227b02097aef30.tar.bz2 |
gh-98831: Clean up and add cache size static_assert to macro (#101442)
Diffstat (limited to 'Tools/cases_generator')
-rw-r--r-- | Tools/cases_generator/generate_cases.py | 27 | ||||
-rw-r--r-- | Tools/cases_generator/test_generator.py | 1 |
2 files changed, 24 insertions, 4 deletions
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py index f0c5f96..4368545 100644 --- a/Tools/cases_generator/generate_cases.py +++ b/Tools/cases_generator/generate_cases.py @@ -597,7 +597,7 @@ class Analyzer: self.error( f"Instruction {member} is a member of multiple families " f"({member_instr.family.name}, {family.name}).", - family + family, ) else: member_instr.family = family @@ -609,7 +609,7 @@ class Analyzer: f"Component {part.instr.name} of macro {member} " f"is a member of multiple families " f"({part.instr.family.name}, {family.name}).", - family + family, ) else: part.instr.family = family @@ -629,7 +629,11 @@ class Analyzer: for family in self.families.values(): if len(family.members) < 2: self.error(f"Family {family.name!r} has insufficient members", family) - members = [member for member in family.members if member in self.instrs or member in self.macro_instrs] + members = [ + member + for member in family.members + if member in self.instrs or member in self.macro_instrs + ] if members != family.members: unknown = set(family.members) - set(members) self.error( @@ -859,7 +863,9 @@ class Analyzer: popped_data.append((instr, popped)) pushed_data.append((instr, pushed)) - def write_function(direction: str, data: list[tuple[AnyInstruction, str]]) -> None: + def write_function( + direction: str, data: list[tuple[AnyInstruction, str]] + ) -> None: self.out.emit("\n#ifndef NDEBUG") self.out.emit("static int") self.out.emit(f"_PyOpcode_num_{direction}(int opcode, int oparg) {{") @@ -1031,6 +1037,7 @@ class Analyzer: def write_macro(self, mac: MacroInstruction) -> None: """Write code for a macro instruction.""" + last_instr: Instruction | None = None with self.wrap_super_or_macro(mac): cache_adjust = 0 for part in mac.parts: @@ -1038,12 +1045,24 @@ class Analyzer: case parser.CacheEffect(size=size): cache_adjust += size case Component() as comp: + last_instr = comp.instr comp.write_body(self.out, cache_adjust) cache_adjust += comp.instr.cache_offset if cache_adjust: self.out.emit(f"JUMPBY({cache_adjust});") + if ( + last_instr + and (family := last_instr.family) + and mac.name == family.members[0] + and (cache_size := family.size) + ): + self.out.emit( + f"static_assert({cache_size} == " + f'{cache_adjust}, "incorrect cache size");' + ) + @contextlib.contextmanager def wrap_super_or_macro(self, up: SuperOrMacroInstruction): """Shared boilerplate for super- and macro instructions.""" diff --git a/Tools/cases_generator/test_generator.py b/Tools/cases_generator/test_generator.py index 49a9937..9df97d2 100644 --- a/Tools/cases_generator/test_generator.py +++ b/Tools/cases_generator/test_generator.py @@ -383,6 +383,7 @@ def test_macro_instruction(): _tmp_3 = res; } JUMPBY(5); + static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size"); STACK_SHRINK(2); POKE(1, _tmp_3); DISPATCH(); |