예제 #1
0
파일: test_ir.py 프로젝트: zsoltc89/numba
 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 _dbgprint_after_each_array_assignments(lowerer, loop_body, typemap):
    for label, block in loop_body.items():
        new_block = block.copy()
        new_block.clear()
        loc = block.loc
        scope = block.scope
        for inst in block.body:
            new_block.append(inst)
            # Append print after assignment
            if isinstance(inst, ir.Assign):
                # Only apply to numbers
                if typemap[inst.target.name] not in types.number_domain:
                    continue

                # Make constant string
                strval = "{} =".format(inst.target.name)
                strconsttyp = types.StringLiteral(strval)

                lhs = ir.Var(scope, mk_unique_var("str_const"), loc)
                assign_lhs = ir.Assign(value=ir.Const(value=strval, loc=loc),
                                       target=lhs,
                                       loc=loc)
                typemap[lhs.name] = strconsttyp
                new_block.append(assign_lhs)

                # Make print node
                print_node = ir.Print(args=[lhs, inst.target],
                                      vararg=None,
                                      loc=loc)
                new_block.append(print_node)
                sig = numba.typing.signature(types.none, typemap[lhs.name],
                                             typemap[inst.target.name])
                lowerer.fndesc.calltypes[print_node] = sig
        loop_body[label] = new_block
예제 #3
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