@@ -413,13 +413,13 @@ def analyze_supers_and_macros(self) -> None:
413
413
"""Analyze each super- and macro instruction."""
414
414
self .super_instrs = {}
415
415
self .macro_instrs = {}
416
- for name , sup in self .supers .items ():
417
- self .super_instrs [name ] = self .analyze_super (sup )
416
+ for name , super in self .supers .items ():
417
+ self .super_instrs [name ] = self .analyze_super (super )
418
418
for name , macro in self .macros .items ():
419
419
self .macro_instrs [name ] = self .analyze_macro (macro )
420
420
421
- def analyze_super (self , supe : parser .Super ) -> SuperInstruction :
422
- components = self .check_super_components (supe )
421
+ def analyze_super (self , super : parser .Super ) -> SuperInstruction :
422
+ components = self .check_super_components (super )
423
423
stack , initial_sp = self .stack_analysis (components )
424
424
sp = initial_sp
425
425
parts : list [Component ] = []
@@ -442,10 +442,10 @@ def analyze_super(self, supe: parser.Super) -> SuperInstruction:
442
442
case _:
443
443
typing .assert_never (component )
444
444
final_sp = sp
445
- return SuperInstruction (supe , stack , initial_sp , final_sp , parts )
445
+ return SuperInstruction (super , stack , initial_sp , final_sp , parts )
446
446
447
- def analyze_macro (self , supe : parser .Macro ) -> MacroInstruction :
448
- components = self .check_macro_components (supe )
447
+ def analyze_macro (self , macro : parser .Macro ) -> MacroInstruction :
448
+ components = self .check_macro_components (macro )
449
449
stack , initial_sp = self .stack_analysis (components )
450
450
sp = initial_sp
451
451
parts : list [Component | parser .CacheEffect ] = []
@@ -468,36 +468,30 @@ def analyze_macro(self, supe: parser.Macro) -> MacroInstruction:
468
468
case _:
469
469
typing .assert_never (component )
470
470
final_sp = sp
471
- return MacroInstruction (supe , stack , initial_sp , final_sp , parts )
471
+ return MacroInstruction (macro , stack , initial_sp , final_sp , parts )
472
472
473
- def check_super_components (self , supe : parser .Super ) -> list [Instruction ]:
473
+ def check_super_components (self , super : parser .Super ) -> list [Instruction ]:
474
474
components : list [Instruction ] = []
475
- if not supe .ops :
476
- self .error (f"Super-instruction has no operands" , supe )
477
- for op in supe .ops :
475
+ if not super .ops :
476
+ self .error (f"Super-instruction has no operands" , super )
477
+ for op in super .ops :
478
478
if op .name not in self .instrs :
479
- self .error (f"Unknown instruction { op .name !r} " , supe )
479
+ self .error (f"Unknown instruction { op .name !r} " , super )
480
480
else :
481
- instr = self .instrs [op .name ]
482
- if instr .kind != "inst" :
483
- self .error (
484
- f"Super-instruction operand { instr .name } must be inst, not op" ,
485
- instr ,
486
- )
487
- components .append (instr )
481
+ components .append (self .instrs [op .name ])
488
482
return components
489
483
490
484
def check_macro_components (
491
- self , supe : parser .Macro
485
+ self , macro : parser .Macro
492
486
) -> list [InstructionOrCacheEffect ]:
493
487
components : list [InstructionOrCacheEffect ] = []
494
- if not supe .uops :
495
- self .error (f"Macro instruction has no operands" , supe )
496
- for uop in supe .uops :
488
+ if not macro .uops :
489
+ self .error (f"Macro instruction has no operands" , macro )
490
+ for uop in macro .uops :
497
491
match uop :
498
492
case parser .OpName (name ):
499
493
if name not in self .instrs :
500
- self .error (f"Unknown instruction { name !r} " , supe )
494
+ self .error (f"Unknown instruction { name !r} " , macro )
501
495
components .append (self .instrs [name ])
502
496
case parser .CacheEffect ():
503
497
components .append (uop )
@@ -595,23 +589,23 @@ def write_super(self, sup: SuperInstruction) -> None:
595
589
self .write_stack_pokes (sup .stack , sup .initial_sp , sup .final_sp )
596
590
self .out .emit ("DISPATCH();" )
597
591
598
- def write_macro (self , macro : MacroInstruction ) -> None :
592
+ def write_macro (self , mac : MacroInstruction ) -> None :
599
593
"""Write code for a macro instruction."""
600
594
self .out .emit ("" )
601
595
602
- with self .out .block (f"TARGET({ macro .name } )" ):
603
- self .write_stack_vars (macro .stack , macro .initial_sp )
596
+ with self .out .block (f"TARGET({ mac .name } )" ):
597
+ self .write_stack_vars (mac .stack , mac .initial_sp )
604
598
605
599
cache_adjust = 0
606
- for part in macro .parts :
600
+ for part in mac .parts :
607
601
match part :
608
602
case parser .CacheEffect (size = size ):
609
603
cache_adjust += size
610
604
case Component () as comp :
611
605
comp .write_body (self .out , cache_adjust )
612
606
cache_adjust += comp .instr .cache_offset
613
607
614
- self .write_stack_pokes (macro .stack , macro .initial_sp , macro .final_sp )
608
+ self .write_stack_pokes (mac .stack , mac .initial_sp , mac .final_sp )
615
609
if cache_adjust :
616
610
self .out .emit (f"next_instr += { cache_adjust } ;" )
617
611
self .out .emit (f"DISPATCH();" )
0 commit comments