@@ -47,8 +47,10 @@ class ASTICodeTransformer(ASTIdentityTransformer):
4747
4848 def __init__ (
4949 self ,
50- astinterface : "ASTInterface" ) -> None :
50+ astinterface : "ASTInterface" ,
51+ variablesused : List [str ] = []) -> None :
5152 self ._astinterface = astinterface
53+ self ._variablesused = variablesused
5254
5355 @property
5456 def astinterface (self ) -> "ASTInterface" :
@@ -58,6 +60,10 @@ def astinterface(self) -> "ASTInterface":
5860 def provenance (self ) -> "ASTIProvenance" :
5961 return self .astinterface .astiprovenance
6062
63+ @property
64+ def variables_used (self ) -> List [str ]:
65+ return self ._variablesused
66+
6167 def transform_stmt (self , stmt : AST .ASTStmt ) -> AST .ASTStmt :
6268 return stmt .transform (self )
6369
@@ -98,12 +104,6 @@ def transform_instruction_sequence_stmt(
98104 and not self .provenance .has_expose_instruction (instr .instrid )):
99105 chklogger .logger .info (
100106 "Remove [%s]: has ssa value" , str (instr ))
101- elif self .provenance .has_active_lval_defuse_high (instr .lhs .lvalid ):
102- chklogger .logger .info (
103- "Transform [%s]: active lval_defuse_high: %s" ,
104- str (instr ),
105- self .provenance .active_lval_defuse_high (instr .lhs .lvalid ))
106- instrs .append (instr )
107107 elif self .provenance .has_lval_store (instr .lhs .lvalid ):
108108 chklogger .logger .info (
109109 "Transform [%s]: lval_store" , str (instr ))
@@ -116,6 +116,15 @@ def transform_instruction_sequence_stmt(
116116 chklogger .logger .info (
117117 "Transform [%s]: global lhs" , str (instr ))
118118 instrs .append (instr )
119+ elif str (instr .lhs ) not in self .variables_used :
120+ chklogger .logger .info (
121+ "Remove [%s]: lhs is not used" )
122+ elif self .provenance .has_active_lval_defuse_high (instr .lhs .lvalid ):
123+ chklogger .logger .info (
124+ "Transform [%s]: active lval_defuse_high: %s" ,
125+ str (instr ),
126+ self .provenance .active_lval_defuse_high (instr .lhs .lvalid ))
127+ instrs .append (instr )
119128 else :
120129 chklogger .logger .info ("Transform [%s]: remove" , str (instr ))
121130 else :
0 commit comments