gh-109287: fix overrides in cases generator (#110419)
This commit is contained in:
parent
bb057b3370
commit
3c0f65ebce
@ -598,6 +598,41 @@ class TestGeneratedCases(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.run_cases_test(input, output)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -12,7 +12,6 @@ from instructions import (
|
|||||||
InstructionOrCacheEffect,
|
InstructionOrCacheEffect,
|
||||||
MacroInstruction,
|
MacroInstruction,
|
||||||
MacroParts,
|
MacroParts,
|
||||||
OverriddenInstructionPlaceHolder,
|
|
||||||
PseudoInstruction,
|
PseudoInstruction,
|
||||||
)
|
)
|
||||||
import parsing
|
import parsing
|
||||||
@ -66,7 +65,6 @@ class Analyzer:
|
|||||||
parsing.InstDef
|
parsing.InstDef
|
||||||
| parsing.Macro
|
| parsing.Macro
|
||||||
| parsing.Pseudo
|
| parsing.Pseudo
|
||||||
| OverriddenInstructionPlaceHolder
|
|
||||||
]
|
]
|
||||||
instrs: dict[str, Instruction] # Includes ops
|
instrs: dict[str, Instruction] # Includes ops
|
||||||
macros: dict[str, parsing.Macro]
|
macros: dict[str, parsing.Macro]
|
||||||
@ -141,7 +139,7 @@ class Analyzer:
|
|||||||
match thing:
|
match thing:
|
||||||
case parsing.InstDef(name=name):
|
case parsing.InstDef(name=name):
|
||||||
macro: parsing.Macro | None = None
|
macro: parsing.Macro | None = None
|
||||||
if thing.kind == "inst":
|
if thing.kind == "inst" and not thing.override:
|
||||||
macro = parsing.Macro(name, [parsing.OpName(name)])
|
macro = parsing.Macro(name, [parsing.OpName(name)])
|
||||||
if name in self.instrs:
|
if name in self.instrs:
|
||||||
if not thing.override:
|
if not thing.override:
|
||||||
@ -150,12 +148,7 @@ class Analyzer:
|
|||||||
f"previous definition @ {self.instrs[name].inst.context}",
|
f"previous definition @ {self.instrs[name].inst.context}",
|
||||||
thing_first_token,
|
thing_first_token,
|
||||||
)
|
)
|
||||||
placeholder = OverriddenInstructionPlaceHolder(name=name)
|
self.everything[instrs_idx[name]] = thing
|
||||||
self.everything[instrs_idx[name]] = placeholder
|
|
||||||
if macro is not None:
|
|
||||||
self.warning(
|
|
||||||
f"Overriding desugared {macro.name} may not work", thing
|
|
||||||
)
|
|
||||||
if name not in self.instrs and thing.override:
|
if name not in self.instrs and thing.override:
|
||||||
raise psr.make_syntax_error(
|
raise psr.make_syntax_error(
|
||||||
f"Definition of '{name}' @ {thing.context} is supposed to be "
|
f"Definition of '{name}' @ {thing.context} is supposed to be "
|
||||||
|
@ -26,7 +26,6 @@ from instructions import (
|
|||||||
MacroInstruction,
|
MacroInstruction,
|
||||||
MacroParts,
|
MacroParts,
|
||||||
PseudoInstruction,
|
PseudoInstruction,
|
||||||
OverriddenInstructionPlaceHolder,
|
|
||||||
TIER_ONE,
|
TIER_ONE,
|
||||||
TIER_TWO,
|
TIER_TWO,
|
||||||
)
|
)
|
||||||
@ -208,8 +207,6 @@ class Generator(Analyzer):
|
|||||||
popped_data: list[tuple[AnyInstruction, str]] = []
|
popped_data: list[tuple[AnyInstruction, str]] = []
|
||||||
pushed_data: list[tuple[AnyInstruction, str]] = []
|
pushed_data: list[tuple[AnyInstruction, str]] = []
|
||||||
for thing in self.everything:
|
for thing in self.everything:
|
||||||
if isinstance(thing, OverriddenInstructionPlaceHolder):
|
|
||||||
continue
|
|
||||||
if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
|
if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
|
||||||
continue
|
continue
|
||||||
instr, popped, pushed = self.get_stack_effect_info(thing)
|
instr, popped, pushed = self.get_stack_effect_info(thing)
|
||||||
@ -393,8 +390,6 @@ class Generator(Analyzer):
|
|||||||
for thing in self.everything:
|
for thing in self.everything:
|
||||||
format: str | None = None
|
format: str | None = None
|
||||||
match thing:
|
match thing:
|
||||||
case OverriddenInstructionPlaceHolder():
|
|
||||||
continue
|
|
||||||
case parsing.InstDef():
|
case parsing.InstDef():
|
||||||
format = self.instrs[thing.name].instr_fmt
|
format = self.instrs[thing.name].instr_fmt
|
||||||
case parsing.Macro():
|
case parsing.Macro():
|
||||||
@ -492,8 +487,6 @@ class Generator(Analyzer):
|
|||||||
# Write metadata for each instruction
|
# Write metadata for each instruction
|
||||||
for thing in self.everything:
|
for thing in self.everything:
|
||||||
match thing:
|
match thing:
|
||||||
case OverriddenInstructionPlaceHolder():
|
|
||||||
continue
|
|
||||||
case parsing.InstDef():
|
case parsing.InstDef():
|
||||||
self.write_metadata_for_inst(self.instrs[thing.name])
|
self.write_metadata_for_inst(self.instrs[thing.name])
|
||||||
case parsing.Macro():
|
case parsing.Macro():
|
||||||
@ -774,8 +767,6 @@ class Generator(Analyzer):
|
|||||||
n_macros = 0
|
n_macros = 0
|
||||||
for thing in self.everything:
|
for thing in self.everything:
|
||||||
match thing:
|
match thing:
|
||||||
case OverriddenInstructionPlaceHolder():
|
|
||||||
self.write_overridden_instr_place_holder(thing)
|
|
||||||
case parsing.InstDef():
|
case parsing.InstDef():
|
||||||
pass
|
pass
|
||||||
case parsing.Macro():
|
case parsing.Macro():
|
||||||
@ -836,14 +827,6 @@ class Generator(Analyzer):
|
|||||||
file=sys.stderr,
|
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:
|
def is_super_instruction(mac: MacroInstruction) -> bool:
|
||||||
if (
|
if (
|
||||||
|
@ -295,11 +295,6 @@ class PseudoInstruction:
|
|||||||
instr_flags: InstructionFlags
|
instr_flags: InstructionFlags
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
|
||||||
class OverriddenInstructionPlaceHolder:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
|
|
||||||
AnyInstruction = Instruction | MacroInstruction | PseudoInstruction
|
AnyInstruction = Instruction | MacroInstruction | PseudoInstruction
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user