Skip to content

Commit 05d1263

Browse files
committed
Remove accidentally duplicated code
1 parent ad44eef commit 05d1263

File tree

1 file changed

+0
-108
lines changed

1 file changed

+0
-108
lines changed

Tools/cases_generator/generate_cases.py

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -536,114 +536,6 @@ def stack_analysis(
536536
stack = [f"_tmp_{i+1}" for i in range(highest - lowest)]
537537
return stack, -lowest
538538

539-
def analyze_super(self, supe: parser.Super) -> SuperInstruction:
540-
components = self.check_super_components(supe)
541-
stack, initial_sp = self.stack_analysis(components)
542-
sp = initial_sp
543-
parts: list[Component] = []
544-
for component in components:
545-
match component:
546-
case parser.CacheEffect() as ceffect:
547-
parts.append(ceffect)
548-
case Instruction() as instr:
549-
input_mapping = {}
550-
for ieffect in reversed(instr.input_effects):
551-
sp -= 1
552-
if ieffect.name != "unused":
553-
input_mapping[stack[sp]] = ieffect
554-
output_mapping = {}
555-
for oeffect in instr.output_effects:
556-
if oeffect.name != "unused":
557-
output_mapping[stack[sp]] = oeffect
558-
sp += 1
559-
parts.append(Component(instr, input_mapping, output_mapping))
560-
case _:
561-
typing.assert_never(component)
562-
final_sp = sp
563-
return SuperInstruction(supe, stack, initial_sp, final_sp, parts)
564-
565-
def analyze_macro(self, macro: parser.Macro) -> MacroInstruction:
566-
components = self.check_macro_components(macro)
567-
stack, initial_sp = self.stack_analysis(components)
568-
sp = initial_sp
569-
parts: list[Component | parser.CacheEffect] = []
570-
for component in components:
571-
match component:
572-
case parser.CacheEffect() as ceffect:
573-
parts.append(ceffect)
574-
case Instruction() as instr:
575-
input_mapping = {}
576-
for ieffect in reversed(instr.input_effects):
577-
sp -= 1
578-
if ieffect.name != "unused":
579-
input_mapping[stack[sp]] = ieffect
580-
output_mapping = {}
581-
for oeffect in instr.output_effects:
582-
if oeffect.name != "unused":
583-
output_mapping[stack[sp]] = oeffect
584-
sp += 1
585-
parts.append(Component(instr, input_mapping, output_mapping))
586-
case _:
587-
typing.assert_never(component)
588-
final_sp = sp
589-
return MacroInstruction(macro, stack, initial_sp, final_sp, parts)
590-
591-
def check_super_components(self, supe: parser.Super) -> list[Instruction]:
592-
components: list[Instruction] = []
593-
if not supe.ops:
594-
self.error(f"Super-instruction has no operands", supe)
595-
for op in supe.ops:
596-
if op.name not in self.instrs:
597-
self.error(f"Unknown instruction {op.name!r}", supe)
598-
else:
599-
components.append(self.instrs[op.name])
600-
return components
601-
602-
def check_macro_components(
603-
self, macro: parser.Macro
604-
) -> list[InstructionOrCacheEffect]:
605-
components: list[InstructionOrCacheEffect] = []
606-
if not macro.uops:
607-
self.error(f"Macro instruction has no operands", macro)
608-
for uop in macro.uops:
609-
match uop:
610-
case parser.OpName(name):
611-
if name not in self.instrs:
612-
self.error(f"Unknown instruction {name!r}", macro)
613-
components.append(self.instrs[name])
614-
case parser.CacheEffect():
615-
components.append(uop)
616-
case _:
617-
typing.assert_never(uop)
618-
return components
619-
620-
def stack_analysis(
621-
self, components: typing.Iterable[InstructionOrCacheEffect]
622-
) -> tuple[list[str], int]:
623-
"""Analyze a super-instruction or macro.
624-
625-
Print an error if there's a cache effect (which we don't support yet).
626-
627-
Return the list of variable names and the initial stack pointer.
628-
"""
629-
lowest = current = highest = 0
630-
for thing in components:
631-
match thing:
632-
case Instruction() as instr:
633-
current -= len(instr.input_effects)
634-
lowest = min(lowest, current)
635-
current += len(instr.output_effects)
636-
highest = max(highest, current)
637-
case parser.CacheEffect():
638-
pass
639-
case _:
640-
typing.assert_never(thing)
641-
# At this point, 'current' is the net stack effect,
642-
# and 'lowest' and 'highest' are the extremes.
643-
# Note that 'lowest' may be negative.
644-
stack = [f"_tmp_{i+1}" for i in range(highest - lowest)]
645-
return stack, -lowest
646-
647539
def write_instructions(self) -> None:
648540
"""Write instructions to output file."""
649541
with open(self.output_filename, "w") as f:

0 commit comments

Comments
 (0)