"""
self.run_cases_test(input, output)
+ def test_override_inst(self):
+ input = """
+ inst(OP, (--)) {
+ spam();
+ }
+ override inst(OP, (--)) {
+ ham();
+ }
+ """
+ output = """
+ TARGET(OP) {
+ ham();
+ DISPATCH();
+ }
+ """
+ self.run_cases_test(input, output)
+
+ def test_override_op(self):
+ input = """
+ op(OP, (--)) {
+ spam();
+ }
+ macro(M) = OP;
+ override op(OP, (--)) {
+ ham();
+ }
+ """
+ output = """
+ TARGET(M) {
+ ham();
+ DISPATCH();
+ }
+ """
+ self.run_cases_test(input, output)
+
if __name__ == "__main__":
unittest.main()
InstructionOrCacheEffect,
MacroInstruction,
MacroParts,
- OverriddenInstructionPlaceHolder,
PseudoInstruction,
)
import parsing
parsing.InstDef
| parsing.Macro
| parsing.Pseudo
- | OverriddenInstructionPlaceHolder
]
instrs: dict[str, Instruction] # Includes ops
macros: dict[str, parsing.Macro]
match thing:
case parsing.InstDef(name=name):
macro: parsing.Macro | None = None
- if thing.kind == "inst":
+ if thing.kind == "inst" and not thing.override:
macro = parsing.Macro(name, [parsing.OpName(name)])
if name in self.instrs:
if not thing.override:
f"previous definition @ {self.instrs[name].inst.context}",
thing_first_token,
)
- placeholder = OverriddenInstructionPlaceHolder(name=name)
- self.everything[instrs_idx[name]] = placeholder
- if macro is not None:
- self.warning(
- f"Overriding desugared {macro.name} may not work", thing
- )
+ self.everything[instrs_idx[name]] = thing
if name not in self.instrs and thing.override:
raise psr.make_syntax_error(
f"Definition of '{name}' @ {thing.context} is supposed to be "
MacroInstruction,
MacroParts,
PseudoInstruction,
- OverriddenInstructionPlaceHolder,
TIER_ONE,
TIER_TWO,
)
popped_data: list[tuple[AnyInstruction, str]] = []
pushed_data: list[tuple[AnyInstruction, str]] = []
for thing in self.everything:
- if isinstance(thing, OverriddenInstructionPlaceHolder):
- continue
if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
continue
instr, popped, pushed = self.get_stack_effect_info(thing)
for thing in self.everything:
format: str | None = None
match thing:
- case OverriddenInstructionPlaceHolder():
- continue
case parsing.InstDef():
format = self.instrs[thing.name].instr_fmt
case parsing.Macro():
# Write metadata for each instruction
for thing in self.everything:
match thing:
- case OverriddenInstructionPlaceHolder():
- continue
case parsing.InstDef():
self.write_metadata_for_inst(self.instrs[thing.name])
case parsing.Macro():
n_macros = 0
for thing in self.everything:
match thing:
- case OverriddenInstructionPlaceHolder():
- self.write_overridden_instr_place_holder(thing)
case parsing.InstDef():
pass
case parsing.Macro():
file=sys.stderr,
)
- def write_overridden_instr_place_holder(
- self, place_holder: OverriddenInstructionPlaceHolder
- ) -> None:
- self.out.emit("")
- self.out.emit(
- f"{self.out.comment} TARGET({place_holder.name}) overridden by later definition"
- )
-
def is_super_instruction(mac: MacroInstruction) -> bool:
if (
instr_flags: InstructionFlags
-@dataclasses.dataclass
-class OverriddenInstructionPlaceHolder:
- name: str
-
-
AnyInstruction = Instruction | MacroInstruction | PseudoInstruction