@@ -260,27 +260,13 @@ def write_body(self, out: Formatter, cache_adjust: int) -> None:
260260
261261
262262@dataclasses .dataclass
263- class SuperOrMacroInstruction :
264- """Common fields for super- and macro instructions ."""
263+ class MacroInstruction :
264+ """A macro instruction ."""
265265
266266 name : str
267267 stack : list [StackEffect ]
268268 initial_sp : int
269269 final_sp : int
270-
271-
272- @dataclasses .dataclass
273- class SuperInstruction (SuperOrMacroInstruction ):
274- """A super-instruction."""
275-
276- super : parser .Super
277- parts : list [Component ]
278-
279-
280- @dataclasses .dataclass
281- class MacroInstruction (SuperOrMacroInstruction ):
282- """A macro instruction."""
283-
284270 macro : parser .Macro
285271 parts : list [Component | parser .CacheEffect ]
286272
@@ -312,8 +298,6 @@ def error(self, msg: str, node: parser.Node) -> None:
312298 self .errors += 1
313299
314300 instrs : dict [str , Instruction ] # Includes ops
315- supers : dict [str , parser .Super ]
316- super_instrs : dict [str , SuperInstruction ]
317301 macros : dict [str , parser .Macro ]
318302 macro_instrs : dict [str , MacroInstruction ]
319303 families : dict [str , parser .Family ]
@@ -345,15 +329,12 @@ def parse(self) -> None:
345329 # Parse from start
346330 psr .setpos (start )
347331 self .instrs = {}
348- self .supers = {}
349332 self .macros = {}
350333 self .families = {}
351334 while thing := psr .definition ():
352335 match thing :
353336 case parser .InstDef (name = name ):
354337 self .instrs [name ] = Instruction (thing )
355- case parser .Super (name ):
356- self .supers [name ] = thing
357338 case parser .Macro (name ):
358339 self .macros [name ] = thing
359340 case parser .Family (name ):
@@ -365,7 +346,7 @@ def parse(self) -> None:
365346
366347 print (
367348 f"Read { len (self .instrs )} instructions/ops, "
368- f"{ len (self .supers ) } supers, { len ( self . macros )} macros, "
349+ f"{ len (self .macros )} macros, "
369350 f"and { len (self .families )} families from { self .filename } " ,
370351 file = sys .stderr ,
371352 )
@@ -378,7 +359,7 @@ def analyze(self) -> None:
378359 self .find_predictions ()
379360 self .map_families ()
380361 self .check_families ()
381- self .analyze_supers_and_macros ()
362+ self .analyze_macros ()
382363
383364 def find_predictions (self ) -> None :
384365 """Find the instructions that need PREDICTED() labels."""
@@ -444,26 +425,12 @@ def check_families(self) -> None:
444425 family ,
445426 )
446427
447- def analyze_supers_and_macros (self ) -> None :
448- """Analyze each super- and macro instruction."""
449- self .super_instrs = {}
428+ def analyze_macros (self ) -> None :
429+ """Analyze each macro instruction."""
450430 self .macro_instrs = {}
451- for name , super in self .supers .items ():
452- self .super_instrs [name ] = self .analyze_super (super )
453431 for name , macro in self .macros .items ():
454432 self .macro_instrs [name ] = self .analyze_macro (macro )
455433
456- def analyze_super (self , super : parser .Super ) -> SuperInstruction :
457- components = self .check_super_components (super )
458- stack , initial_sp = self .stack_analysis (components )
459- sp = initial_sp
460- parts : list [Component ] = []
461- for instr in components :
462- part , sp = self .analyze_instruction (instr , stack , sp )
463- parts .append (part )
464- final_sp = sp
465- return SuperInstruction (super .name , stack , initial_sp , final_sp , super , parts )
466-
467434 def analyze_macro (self , macro : parser .Macro ) -> MacroInstruction :
468435 components = self .check_macro_components (macro )
469436 stack , initial_sp = self .stack_analysis (components )
@@ -494,15 +461,6 @@ def analyze_instruction(
494461 sp += 1
495462 return Component (instr , input_mapping , output_mapping ), sp
496463
497- def check_super_components (self , super : parser .Super ) -> list [Instruction ]:
498- components : list [Instruction ] = []
499- for op in super .ops :
500- if op .name not in self .instrs :
501- self .error (f"Unknown instruction { op .name !r} " , super )
502- else :
503- components .append (self .instrs [op .name ])
504- return components
505-
506464 def check_macro_components (
507465 self , macro : parser .Macro
508466 ) -> list [InstructionOrCacheEffect ]:
@@ -522,9 +480,7 @@ def check_macro_components(
522480 def stack_analysis (
523481 self , components : typing .Iterable [InstructionOrCacheEffect ]
524482 ) -> tuple [list [StackEffect ], int ]:
525- """Analyze a super-instruction or macro.
526-
527- Print an error if there's a cache effect (which we don't support yet).
483+ """Analyze a macro.
528484
529485 Return the list of variable names and the initial stack pointer.
530486 """
@@ -576,40 +532,21 @@ def write_instructions(self) -> None:
576532 self .out .emit (f"PREDICT({ prediction } );" )
577533 self .out .emit (f"DISPATCH();" )
578534
579- # Write and count super-instructions
580- n_supers = 0
581- for sup in self .super_instrs .values ():
582- n_supers += 1
583- self .write_super (sup )
584-
585535 # Write and count macro instructions
586536 n_macros = 0
587537 for macro in self .macro_instrs .values ():
588538 n_macros += 1
589539 self .write_macro (macro )
590540
591541 print (
592- f"Wrote { n_instrs } instructions, { n_supers } supers, "
542+ f"Wrote { n_instrs } instructions "
593543 f"and { n_macros } macros to { self .output_filename } " ,
594544 file = sys .stderr ,
595545 )
596546
597- def write_super (self , sup : SuperInstruction ) -> None :
598- """Write code for a super-instruction."""
599- with self .wrap_super_or_macro (sup ):
600- first = True
601- for comp in sup .parts :
602- if not first :
603- self .out .emit ("NEXTOPARG();" )
604- self .out .emit ("next_instr++;" )
605- first = False
606- comp .write_body (self .out , 0 )
607- if comp .instr .cache_offset :
608- self .out .emit (f"next_instr += { comp .instr .cache_offset } ;" )
609-
610547 def write_macro (self , mac : MacroInstruction ) -> None :
611548 """Write code for a macro instruction."""
612- with self .wrap_super_or_macro (mac ):
549+ with self .wrap_macro (mac ):
613550 cache_adjust = 0
614551 for part in mac .parts :
615552 match part :
@@ -623,8 +560,8 @@ def write_macro(self, mac: MacroInstruction) -> None:
623560 self .out .emit (f"next_instr += { cache_adjust } ;" )
624561
625562 @contextlib .contextmanager
626- def wrap_super_or_macro (self , up : SuperOrMacroInstruction ):
627- """Shared boilerplate for super- and macro instructions."""
563+ def wrap_macro (self , up : MacroInstruction ):
564+ """Boilerplate for macro instructions."""
628565 # TODO: Somewhere (where?) make it so that if one instruction
629566 # has an output that is input to another, and the variable names
630567 # and types match and don't conflict with other instructions,
0 commit comments