@@ -260,27 +260,13 @@ def write_body(self, out: Formatter, cache_adjust: int) -> None:
260
260
261
261
262
262
@dataclasses .dataclass
263
- class SuperOrMacroInstruction :
264
- """Common fields for super- and macro instructions ."""
263
+ class MacroInstruction :
264
+ """A macro instruction ."""
265
265
266
266
name : str
267
267
stack : list [StackEffect ]
268
268
initial_sp : int
269
269
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
-
284
270
macro : parser .Macro
285
271
parts : list [Component | parser .CacheEffect ]
286
272
@@ -312,8 +298,6 @@ def error(self, msg: str, node: parser.Node) -> None:
312
298
self .errors += 1
313
299
314
300
instrs : dict [str , Instruction ] # Includes ops
315
- supers : dict [str , parser .Super ]
316
- super_instrs : dict [str , SuperInstruction ]
317
301
macros : dict [str , parser .Macro ]
318
302
macro_instrs : dict [str , MacroInstruction ]
319
303
families : dict [str , parser .Family ]
@@ -345,15 +329,12 @@ def parse(self) -> None:
345
329
# Parse from start
346
330
psr .setpos (start )
347
331
self .instrs = {}
348
- self .supers = {}
349
332
self .macros = {}
350
333
self .families = {}
351
334
while thing := psr .definition ():
352
335
match thing :
353
336
case parser .InstDef (name = name ):
354
337
self .instrs [name ] = Instruction (thing )
355
- case parser .Super (name ):
356
- self .supers [name ] = thing
357
338
case parser .Macro (name ):
358
339
self .macros [name ] = thing
359
340
case parser .Family (name ):
@@ -365,7 +346,7 @@ def parse(self) -> None:
365
346
366
347
print (
367
348
f"Read { len (self .instrs )} instructions/ops, "
368
- f"{ len (self .supers ) } supers, { len ( self . macros )} macros, "
349
+ f"{ len (self .macros )} macros, "
369
350
f"and { len (self .families )} families from { self .filename } " ,
370
351
file = sys .stderr ,
371
352
)
@@ -378,7 +359,7 @@ def analyze(self) -> None:
378
359
self .find_predictions ()
379
360
self .map_families ()
380
361
self .check_families ()
381
- self .analyze_supers_and_macros ()
362
+ self .analyze_macros ()
382
363
383
364
def find_predictions (self ) -> None :
384
365
"""Find the instructions that need PREDICTED() labels."""
@@ -444,26 +425,12 @@ def check_families(self) -> None:
444
425
family ,
445
426
)
446
427
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."""
450
430
self .macro_instrs = {}
451
- for name , super in self .supers .items ():
452
- self .super_instrs [name ] = self .analyze_super (super )
453
431
for name , macro in self .macros .items ():
454
432
self .macro_instrs [name ] = self .analyze_macro (macro )
455
433
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
-
467
434
def analyze_macro (self , macro : parser .Macro ) -> MacroInstruction :
468
435
components = self .check_macro_components (macro )
469
436
stack , initial_sp = self .stack_analysis (components )
@@ -494,15 +461,6 @@ def analyze_instruction(
494
461
sp += 1
495
462
return Component (instr , input_mapping , output_mapping ), sp
496
463
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
-
506
464
def check_macro_components (
507
465
self , macro : parser .Macro
508
466
) -> list [InstructionOrCacheEffect ]:
@@ -522,9 +480,7 @@ def check_macro_components(
522
480
def stack_analysis (
523
481
self , components : typing .Iterable [InstructionOrCacheEffect ]
524
482
) -> 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.
528
484
529
485
Return the list of variable names and the initial stack pointer.
530
486
"""
@@ -576,40 +532,21 @@ def write_instructions(self) -> None:
576
532
self .out .emit (f"PREDICT({ prediction } );" )
577
533
self .out .emit (f"DISPATCH();" )
578
534
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
-
585
535
# Write and count macro instructions
586
536
n_macros = 0
587
537
for macro in self .macro_instrs .values ():
588
538
n_macros += 1
589
539
self .write_macro (macro )
590
540
591
541
print (
592
- f"Wrote { n_instrs } instructions, { n_supers } supers, "
542
+ f"Wrote { n_instrs } instructions "
593
543
f"and { n_macros } macros to { self .output_filename } " ,
594
544
file = sys .stderr ,
595
545
)
596
546
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
-
610
547
def write_macro (self , mac : MacroInstruction ) -> None :
611
548
"""Write code for a macro instruction."""
612
- with self .wrap_super_or_macro (mac ):
549
+ with self .wrap_macro (mac ):
613
550
cache_adjust = 0
614
551
for part in mac .parts :
615
552
match part :
@@ -623,8 +560,8 @@ def write_macro(self, mac: MacroInstruction) -> None:
623
560
self .out .emit (f"next_instr += { cache_adjust } ;" )
624
561
625
562
@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."""
628
565
# TODO: Somewhere (where?) make it so that if one instruction
629
566
# has an output that is input to another, and the variable names
630
567
# and types match and don't conflict with other instructions,
0 commit comments