summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-11-30 11:03:30 (GMT)
committerGitHub <noreply@github.com>2023-11-30 11:03:30 (GMT)
commit07ebd46f9e55ed2f18c5ea2a79ec5054bc26b915 (patch)
treecfa482ec8e6e8f5dd4b77804a668235aa1ae9ccf /Tools
parent7eeea13403882af63a71226433c9a13b80c22564 (diff)
downloadcpython-07ebd46f9e55ed2f18c5ea2a79ec5054bc26b915.zip
cpython-07ebd46f9e55ed2f18c5ea2a79ec5054bc26b915.tar.gz
cpython-07ebd46f9e55ed2f18c5ea2a79ec5054bc26b915.tar.bz2
gh-112519: Make it possible to specify instruction flags for pseudo instructions in bytecodes.c (#112520)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/cases_generator/analysis.py9
-rw-r--r--Tools/cases_generator/parsing.py25
2 files changed, 30 insertions, 4 deletions
diff --git a/Tools/cases_generator/analysis.py b/Tools/cases_generator/analysis.py
index 603b155..26d92c1 100644
--- a/Tools/cases_generator/analysis.py
+++ b/Tools/cases_generator/analysis.py
@@ -390,9 +390,14 @@ class Analyzer:
else:
targets.append(self.macro_instrs[target_name])
assert targets
- ignored_flags = {"HAS_EVAL_BREAK_FLAG", "HAS_DEOPT_FLAG", "HAS_ERROR_FLAG", "HAS_ESCAPES_FLAG"}
+ ignored_flags = {"HAS_EVAL_BREAK_FLAG", "HAS_DEOPT_FLAG", "HAS_ERROR_FLAG",
+ "HAS_ESCAPES_FLAG"}
assert len({t.instr_flags.bitmap(ignore=ignored_flags) for t in targets}) == 1
- return PseudoInstruction(pseudo.name, targets, targets[0].instr_flags)
+
+ flags = InstructionFlags(**{f"{f}_FLAG" : True for f in pseudo.flags})
+ for t in targets:
+ flags.add(t.instr_flags)
+ return PseudoInstruction(pseudo.name, targets, flags)
def analyze_instruction(
self, instr: Instruction, offset: int
diff --git a/Tools/cases_generator/parsing.py b/Tools/cases_generator/parsing.py
index d36bd52..7800adf 100644
--- a/Tools/cases_generator/parsing.py
+++ b/Tools/cases_generator/parsing.py
@@ -138,7 +138,8 @@ class Family(Node):
@dataclass
class Pseudo(Node):
name: str
- targets: list[str] # opcodes this can be replaced by
+ flags: list[str] # instr flags to set on the pseudo instruction
+ targets: list[str] # opcodes this can be replaced by
class Parser(PLexer):
@@ -374,19 +375,39 @@ class Parser(PLexer):
)
return None
+ def flags(self) -> list[str]:
+ here = self.getpos()
+ if self.expect(lx.LPAREN):
+ if tkn := self.expect(lx.IDENTIFIER):
+ flags = [tkn.text]
+ while self.expect(lx.COMMA):
+ if tkn := self.expect(lx.IDENTIFIER):
+ flags.append(tkn.text)
+ else:
+ break
+ if not self.expect(lx.RPAREN):
+ raise self.make_syntax_error("Expected comma or right paren")
+ return flags
+ self.setpos(here)
+ return []
+
@contextual
def pseudo_def(self) -> Pseudo | None:
if (tkn := self.expect(lx.IDENTIFIER)) and tkn.text == "pseudo":
size = None
if self.expect(lx.LPAREN):
if tkn := self.expect(lx.IDENTIFIER):
+ if self.expect(lx.COMMA):
+ flags = self.flags()
+ else:
+ flags = []
if self.expect(lx.RPAREN):
if self.expect(lx.EQUALS):
if not self.expect(lx.LBRACE):
raise self.make_syntax_error("Expected {")
if members := self.members():
if self.expect(lx.RBRACE) and self.expect(lx.SEMI):
- return Pseudo(tkn.text, members)
+ return Pseudo(tkn.text, flags, members)
return None
def members(self) -> list[str] | None: