@@ -252,6 +252,7 @@ class InstructionFlags:
252
252
HAS_CONST_FLAG : bool
253
253
HAS_NAME_FLAG : bool
254
254
HAS_JUMP_FLAG : bool
255
+ NO_SIDE_EFFECT_FLAG : bool
255
256
256
257
def __post_init__ (self ):
257
258
self .bitmask = {
@@ -265,11 +266,12 @@ def fromInstruction(instr: "AnyInstruction"):
265
266
HAS_CONST_FLAG = variable_used (instr , "FRAME_CO_CONSTS" ),
266
267
HAS_NAME_FLAG = variable_used (instr , "FRAME_CO_NAMES" ),
267
268
HAS_JUMP_FLAG = variable_used (instr , "JUMPBY" ),
269
+ NO_SIDE_EFFECT_FLAG = no_side_effect (instr ),
268
270
)
269
271
270
272
@staticmethod
271
273
def newEmpty ():
272
- return InstructionFlags (False , False , False , False )
274
+ return InstructionFlags (False , False , False , False , False )
273
275
274
276
def add (self , other : "InstructionFlags" ) -> None :
275
277
for name , value in dataclasses .asdict (other ).items ():
@@ -1585,6 +1587,19 @@ def variable_used(node: parser.Node, name: str) -> bool:
1585
1587
)
1586
1588
1587
1589
1590
+ def no_side_effect (node : parser .Node ) -> bool :
1591
+ if node .name .startswith ("JUMP" ):
1592
+ return False
1593
+ for token in node .tokens :
1594
+ token_text = token .text .lower ()
1595
+ if token .kind == "IDENTIFIER" :
1596
+ if token_text in ("error_if" , "go_to_instruction" ):
1597
+ return False
1598
+ if token_text .startswith ("py" ) or token_text .startswith ("_py" ):
1599
+ return False
1600
+ return True
1601
+
1602
+
1588
1603
def main ():
1589
1604
"""Parse command line, parse input, analyze, write output."""
1590
1605
args = arg_parser .parse_args () # Prints message and sys.exit(2) on error
0 commit comments