@@ -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
@@ -311,10 +297,8 @@ def error(self, msg: str, node: parser.Node) -> None:
311
297
print (f"{ self .filename } :{ lineno } : { msg } " , file = sys .stderr )
312
298
self .errors += 1
313
299
314
- everything : list [parser .InstDef | parser .Super | parser . Macro ]
300
+ everything : list [parser .InstDef | parser .Macro ]
315
301
instrs : dict [str , Instruction ] # Includes ops
316
- supers : dict [str , parser .Super ]
317
- super_instrs : dict [str , SuperInstruction ]
318
302
macros : dict [str , parser .Macro ]
319
303
macro_instrs : dict [str , MacroInstruction ]
320
304
families : dict [str , parser .Family ]
@@ -347,17 +331,13 @@ def parse(self) -> None:
347
331
psr .setpos (start )
348
332
self .everything = []
349
333
self .instrs = {}
350
- self .supers = {}
351
334
self .macros = {}
352
335
self .families = {}
353
336
while thing := psr .definition ():
354
337
match thing :
355
338
case parser .InstDef (name = name ):
356
339
self .instrs [name ] = Instruction (thing )
357
340
self .everything .append (thing )
358
- case parser .Super (name ):
359
- self .supers [name ] = thing
360
- self .everything .append (thing )
361
341
case parser .Macro (name ):
362
342
self .macros [name ] = thing
363
343
self .everything .append (thing )
@@ -370,7 +350,7 @@ def parse(self) -> None:
370
350
371
351
print (
372
352
f"Read { len (self .instrs )} instructions/ops, "
373
- f"{ len (self .supers ) } supers, { len ( self . macros )} macros, "
353
+ f"{ len (self .macros )} macros, "
374
354
f"and { len (self .families )} families from { self .filename } " ,
375
355
file = sys .stderr ,
376
356
)
@@ -383,7 +363,7 @@ def analyze(self) -> None:
383
363
self .find_predictions ()
384
364
self .map_families ()
385
365
self .check_families ()
386
- self .analyze_supers_and_macros ()
366
+ self .analyze_macros ()
387
367
388
368
def find_predictions (self ) -> None :
389
369
"""Find the instructions that need PREDICTED() labels."""
@@ -449,26 +429,12 @@ def check_families(self) -> None:
449
429
family ,
450
430
)
451
431
452
- def analyze_supers_and_macros (self ) -> None :
453
- """Analyze each super- and macro instruction."""
454
- self .super_instrs = {}
432
+ def analyze_macros (self ) -> None :
433
+ """Analyze each macro instruction."""
455
434
self .macro_instrs = {}
456
- for name , super in self .supers .items ():
457
- self .super_instrs [name ] = self .analyze_super (super )
458
435
for name , macro in self .macros .items ():
459
436
self .macro_instrs [name ] = self .analyze_macro (macro )
460
437
461
- def analyze_super (self , super : parser .Super ) -> SuperInstruction :
462
- components = self .check_super_components (super )
463
- stack , initial_sp = self .stack_analysis (components )
464
- sp = initial_sp
465
- parts : list [Component ] = []
466
- for instr in components :
467
- part , sp = self .analyze_instruction (instr , stack , sp )
468
- parts .append (part )
469
- final_sp = sp
470
- return SuperInstruction (super .name , stack , initial_sp , final_sp , super , parts )
471
-
472
438
def analyze_macro (self , macro : parser .Macro ) -> MacroInstruction :
473
439
components = self .check_macro_components (macro )
474
440
stack , initial_sp = self .stack_analysis (components )
@@ -499,15 +465,6 @@ def analyze_instruction(
499
465
sp += 1
500
466
return Component (instr , input_mapping , output_mapping ), sp
501
467
502
- def check_super_components (self , super : parser .Super ) -> list [Instruction ]:
503
- components : list [Instruction ] = []
504
- for op in super .ops :
505
- if op .name not in self .instrs :
506
- self .error (f"Unknown instruction { op .name !r} " , super )
507
- else :
508
- components .append (self .instrs [op .name ])
509
- return components
510
-
511
468
def check_macro_components (
512
469
self , macro : parser .Macro
513
470
) -> list [InstructionOrCacheEffect ]:
@@ -527,7 +484,7 @@ def check_macro_components(
527
484
def stack_analysis (
528
485
self , components : typing .Iterable [InstructionOrCacheEffect ]
529
486
) -> tuple [list [StackEffect ], int ]:
530
- """Analyze a super-instruction or macro.
487
+ """Analyze a macro instruction .
531
488
532
489
Print an error if there's a cache effect (which we don't support yet).
533
490
@@ -567,25 +524,21 @@ def write_instructions(self) -> None:
567
524
568
525
# Write and count instructions of all kinds
569
526
n_instrs = 0
570
- n_supers = 0
571
527
n_macros = 0
572
528
for thing in self .everything :
573
529
match thing :
574
530
case parser .InstDef ():
575
531
if thing .kind == "inst" :
576
532
n_instrs += 1
577
533
self .write_instr (self .instrs [thing .name ])
578
- case parser .Super ():
579
- n_supers += 1
580
- self .write_super (self .super_instrs [thing .name ])
581
534
case parser .Macro ():
582
535
n_macros += 1
583
536
self .write_macro (self .macro_instrs [thing .name ])
584
537
case _:
585
538
typing .assert_never (thing )
586
539
587
540
print (
588
- f"Wrote { n_instrs } instructions, { n_supers } supers, "
541
+ f"Wrote { n_instrs } instructions, "
589
542
f"and { n_macros } macros to { self .output_filename } " ,
590
543
file = sys .stderr ,
591
544
)
@@ -602,22 +555,9 @@ def write_instr(self, instr: Instruction) -> None:
602
555
self .out .emit (f"PREDICT({ prediction } );" )
603
556
self .out .emit (f"DISPATCH();" )
604
557
605
- def write_super (self , sup : SuperInstruction ) -> None :
606
- """Write code for a super-instruction."""
607
- with self .wrap_super_or_macro (sup ):
608
- first = True
609
- for comp in sup .parts :
610
- if not first :
611
- self .out .emit ("NEXTOPARG();" )
612
- self .out .emit ("JUMPBY(1);" )
613
- first = False
614
- comp .write_body (self .out , 0 )
615
- if comp .instr .cache_offset :
616
- self .out .emit (f"JUMPBY({ comp .instr .cache_offset } );" )
617
-
618
558
def write_macro (self , mac : MacroInstruction ) -> None :
619
559
"""Write code for a macro instruction."""
620
- with self .wrap_super_or_macro (mac ):
560
+ with self .wrap_macro (mac ):
621
561
cache_adjust = 0
622
562
for part in mac .parts :
623
563
match part :
@@ -631,8 +571,8 @@ def write_macro(self, mac: MacroInstruction) -> None:
631
571
self .out .emit (f"JUMPBY({ cache_adjust } );" )
632
572
633
573
@contextlib .contextmanager
634
- def wrap_super_or_macro (self , up : SuperOrMacroInstruction ):
635
- """Shared boilerplate for super- and macro instructions."""
574
+ def wrap_macro (self , up : MacroInstruction ):
575
+ """Boilerplate for macro instructions."""
636
576
# TODO: Somewhere (where?) make it so that if one instruction
637
577
# has an output that is input to another, and the variable names
638
578
# and types match and don't conflict with other instructions,
0 commit comments