@@ -94,13 +94,8 @@ def parse(self) -> None:
94
94
self .parse_file (filename , instrs_idx )
95
95
96
96
files = " + " .join (self .input_filenames )
97
- n_instrs = 0
98
- n_ops = 0
99
- for instr in self .instrs .values ():
100
- if instr .kind == "op" :
101
- n_ops += 1
102
- else :
103
- n_instrs += 1
97
+ n_instrs = len (set (self .instrs ) & set (self .macros ))
98
+ n_ops = len (self .instrs ) - n_instrs
104
99
print (
105
100
f"Read { n_instrs } instructions, { n_ops } ops, "
106
101
f"{ len (self .macros )} macros, { len (self .pseudos )} pseudos, "
@@ -145,16 +140,22 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
145
140
146
141
match thing :
147
142
case parsing .InstDef (name = name ):
143
+ macro : parsing .Macro | None = None
144
+ if thing .kind == "inst" :
145
+ macro = parsing .Macro (name , [parsing .OpName (name )])
148
146
if name in self .instrs :
149
147
if not thing .override :
150
148
raise psr .make_syntax_error (
151
149
f"Duplicate definition of '{ name } ' @ { thing .context } "
152
150
f"previous definition @ { self .instrs [name ].inst .context } " ,
153
151
thing_first_token ,
154
152
)
155
- self .everything [
156
- instrs_idx [name ]
157
- ] = OverriddenInstructionPlaceHolder (name = name )
153
+ placeholder = OverriddenInstructionPlaceHolder (name = name )
154
+ self .everything [instrs_idx [name ]] = placeholder
155
+ if macro is not None :
156
+ self .warning (
157
+ f"Overriding desugared { macro .name } may not work" , thing
158
+ )
158
159
if name not in self .instrs and thing .override :
159
160
raise psr .make_syntax_error (
160
161
f"Definition of '{ name } ' @ { thing .context } is supposed to be "
@@ -164,6 +165,9 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
164
165
self .instrs [name ] = Instruction (thing )
165
166
instrs_idx [name ] = len (self .everything )
166
167
self .everything .append (thing )
168
+ if macro is not None :
169
+ self .macros [macro .name ] = macro
170
+ self .everything .append (macro )
167
171
case parsing .Macro (name ):
168
172
self .macros [name ] = thing
169
173
self .everything .append (thing )
@@ -197,9 +201,9 @@ def find_predictions(self) -> None:
197
201
for target in targets :
198
202
if target_instr := self .instrs .get (target ):
199
203
target_instr .predicted = True
200
- elif target_macro := self .macro_instrs .get (target ):
204
+ if target_macro := self .macro_instrs .get (target ):
201
205
target_macro .predicted = True
202
- else :
206
+ if not target_instr and not target_macro :
203
207
self .error (
204
208
f"Unknown instruction { target !r} predicted in { instr .name !r} " ,
205
209
instr .inst , # TODO: Use better location
@@ -263,11 +267,7 @@ def check_families(self) -> None:
263
267
)
264
268
265
269
def effect_counts (self , name : str ) -> tuple [int , int , int ]:
266
- if instr := self .instrs .get (name ):
267
- cache = instr .cache_offset
268
- input = len (instr .input_effects )
269
- output = len (instr .output_effects )
270
- elif mac := self .macro_instrs .get (name ):
270
+ if mac := self .macro_instrs .get (name ):
271
271
cache = mac .cache_offset
272
272
input , output = 0 , 0
273
273
for part in mac .parts :
@@ -407,7 +407,8 @@ def check_macro_components(
407
407
case parsing .OpName (name ):
408
408
if name not in self .instrs :
409
409
self .error (f"Unknown instruction { name !r} " , macro )
410
- components .append (self .instrs [name ])
410
+ else :
411
+ components .append (self .instrs [name ])
411
412
case parsing .CacheEffect ():
412
413
components .append (uop )
413
414
case _:
0 commit comments