Пример #1
0
 def test_print(self):
     a = ir.Print((self.var_a, ), self.var_b, self.loc1)
     b = ir.Print((self.var_a, ), self.var_b, self.loc1)
     c = ir.Print((self.var_a, ), self.var_b, self.loc2)
     d = ir.Print((self.var_c, ), self.var_b, self.loc1)
     e = ir.Print((self.var_a, ), self.var_c, self.loc1)
     self.check(a, same=[b, c], different=[d, e])
Пример #2
0
 def apply(self):
     """
     Rewrite `var = call <print function>(...)` as a sequence of
     `print(...)` and `var = const(None)`.
     """
     new_block = self.block.copy()
     new_block.clear()
     for inst in self.block.body:
         if inst in self.prints:
             expr = self.prints[inst]
             print_node = ir.Print(args=expr.args, vararg=expr.vararg,
                                   loc=expr.loc)
             new_block.append(print_node)
             assign_node = ir.Assign(value=ir.Const(None, loc=expr.loc),
                                     target=inst.target,
                                     loc=inst.loc)
             new_block.append(assign_node)
         else:
             new_block.append(inst)
     return new_block