示例#1
0
    def generic_visit(self, node):
        if isinstance(node, ast.expr) and node in self.constant_expressions:
            fake_node = ast.Expression(node)
            code = compile(ast.gast_to_ast(fake_node),
                           '<constant folding>', 'eval')
            try:
                value = eval(code, self.env)
                new_node = to_ast(value)
                if not ASTMatcher(node).match(new_node):
                    self.update = True
                    return new_node
            except DamnTooLongPattern as e:
                print("W: ", e, " Assume no update happened.")
            except ConversionError as e:
                print('error in constant folding: ', e)
                raise
            except ToNotEval:
                pass
            except AttributeError as e:
                # this may miss a few optimization
                logger.info('During constant folding, bailing out due to: ' +
                            e.args[0])
            except NameError as e:
                # FIXME dispatched function are not processed by constant
                # folding
                if "__dispatch__" in e.args[0]:
                    return Transformation.generic_visit(self, node)
                # this may miss a few optimization
                logger.info('During constant folding, bailing out due to: ' +
                            e.args[0])
            except Exception as e:
                raise PythranSyntaxError(str(e), node)

        return Transformation.generic_visit(self, node)
示例#2
0
 def generic_visit(self, node):
     if node in self.constant_expressions:
         try:
             fake_node = ast.Expression(node.value if isinstance(node, ast.Index) else node)
             code = compile(fake_node, "<constant folding>", "eval")
             value = eval(code, self.env)
             new_node = self.to_ast(value)
             if isinstance(node, ast.Index) and not isinstance(new_node, ast.Index):
                 new_node = ast.Index(new_node)
             return new_node
         except ConstantFolding.ConversionError as e:
             print ast.dump(node)
             print "error in constant folding: ", e
             raise
         except ConstantFolding.ToNotEval:
             return Transformation.generic_visit(self, node)
         except AttributeError as e:
             # FIXME union_ function is not handle by constant folding
             if "union_" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             raise
         except NameError as e:
             # FIXME dispatched function are not processed by constant
             # folding
             if "__dispatch__" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             raise
     else:
         return Transformation.generic_visit(self, node)
示例#3
0
 def __init__(self, pm, name, ctx, lambdas, imports, global_decls):
     Transformation.__init__(self)
     self.passmanager = pm
     self.ctx = ctx
     self.prefix = name
     self.lambda_functions = lambdas
     self.imports = imports
     self.global_declarations = global_decls
示例#4
0
 def __init__(self, pm, name, ctx, lambda_functions, imports):
     Transformation.__init__(self)
     self.passmanager = pm
     self.ctx = ctx
     self.prefix = name
     self.lambda_functions = lambda_functions
     self.imports = imports
     self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
示例#5
0
 def __init__(self, pm, name, ctx, lambda_functions, imports):
     Transformation.__init__(self)
     self.passmanager = pm
     self.ctx = ctx
     self.prefix = name
     self.lambda_functions = lambda_functions
     self.imports = imports
     self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
示例#6
0
 def __init__(self, pm, name, ctx, lambdas, imports, global_decls):
     Transformation.__init__(self)
     self.passmanager = pm
     self.ctx = ctx
     self.prefix = name
     self.lambda_functions = lambdas
     self.imports = imports
     self.global_declarations = global_decls
示例#7
0
 def generic_visit(self, node):
     if node in self.constant_expressions:
         try:
             fake_node = ast.Expression(
                 node.value if isinstance(node, ast.Index) else node)
             code = compile(fake_node, '<constant folding>', 'eval')
             value = eval(code, self.env)
             new_node = self.to_ast(value)
             if (isinstance(node, ast.Index)
                     and not isinstance(new_node, ast.Index)):
                 new_node = ast.Index(new_node)
             return new_node
         except Exception:  # as e:
             #print ast.dump(node)
             #print 'error in constant folding: ', e
             return Transformation.generic_visit(self, node)
     else:
         return Transformation.generic_visit(self, node)
示例#8
0
 def generic_visit(self, node):
     if node in self.constant_expressions:
         try:
             fake_node = ast.Expression(
                 node.value if isinstance(node, ast.Index) else node)
             code = compile(fake_node, '<constant folding>', 'eval')
             value = eval(code, self.env)
             new_node = to_ast(value)
             if(isinstance(node, ast.Index) and
                not isinstance(new_node, ast.Index)):
                 new_node = ast.Index(new_node)
             try:
                 if not ASTMatcher(node).search(new_node):
                     self.update = True
             except DamnTooLongPattern as e:
                 print "W: ", e, " Assume no update happened."
             return new_node
         except ConversionError as e:
             print ast.dump(node)
             print 'error in constant folding: ', e
             raise
         except ToNotEval:
             return Transformation.generic_visit(self, node)
         except AttributeError as e:
             # FIXME union_ function is not handle by constant folding
             if "union_" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             elif "pythran" in e.args[0]:
                 # FIXME: Can be fix giving a Python implementation for
                 # these functions.
                 return Transformation.generic_visit(self, node)
             raise
         except NameError as e:
             # FIXME dispatched function are not processed by constant
             # folding
             if "__dispatch__" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             raise
     else:
         return Transformation.generic_visit(self, node)
示例#9
0
 def generic_visit(self, node):
     if node in self.constant_expressions:
         try:
             fake_node = ast.Expression(
                 node.value if isinstance(node, ast.Index) else node)
             code = compile(fake_node, '<constant folding>', 'eval')
             value = eval(code, self.env)
             new_node = to_ast(value)
             if (isinstance(node, ast.Index)
                     and not isinstance(new_node, ast.Index)):
                 new_node = ast.Index(new_node)
             try:
                 if not ASTMatcher(node).search(new_node):
                     self.update = True
             except DamnTooLongPattern as e:
                 print "W: ", e, " Assume no update happened."
             return new_node
         except ConversionError as e:
             print ast.dump(node)
             print 'error in constant folding: ', e
             raise
         except ToNotEval:
             return Transformation.generic_visit(self, node)
         except AttributeError as e:
             # FIXME union_ function is not handle by constant folding
             if "union_" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             elif "pythran" in e.args[0]:
                 # FIXME: Can be fix giving a Python implementation for
                 # these functions.
                 return Transformation.generic_visit(self, node)
             raise
         except NameError as e:
             # FIXME dispatched function are not processed by constant
             # folding
             if "__dispatch__" in e.args[0]:
                 return Transformation.generic_visit(self, node)
             raise
     else:
         return Transformation.generic_visit(self, node)
示例#10
0
 def __init__(self):
     self.count = 0
     Transformation.__init__(self)
示例#11
0
 def __init__(self):
     Transformation.__init__(self, NormalizeTuples,
                             OptimizableComprehension)
 def __init__(self):
     Transformation.__init__(self, OptimizableComprehension)
示例#13
0
 def __init__(self):
     """ Basic initialiser. """
     Transformation.__init__(self)
     self.imports = set()
     self.symbols = dict()
示例#14
0
文件: square.py 项目: xmar/pythran
 def __init__(self):
     Transformation.__init__(self)
示例#15
0
 def __init__(self):
     Transformation.__init__(self, Identifiers)
示例#16
0
 def __init__(self):
     Transformation.__init__(self, RangeValues)
示例#17
0
 def __init__(self):
     """ Gather required information. """
     Transformation.__init__(self, PotentialIterator, Aliases)
示例#18
0
 def __init__(self):
     """ Basic initialiser. """
     Transformation.__init__(self)
     self.imports = set()
     self.symbols = dict()
示例#19
0
 def __init__(self):
     Transformation.__init__(self, NormalizeTuples, PotentialIterator)
 def __init__(self):
     Transformation.__init__(self, PotentialIterator, Aliases)
示例#21
0
 def __init__(self):
     Transformation.__init__(self)
     self.imports = set()
     self.symbols = dict()
示例#22
0
 def __init__(self):
     Transformation.__init__(self)
     self.imports = set()
     self.symbols = dict()
示例#23
0
 def __init__(self, pm, ctx, global_declarations):
     Transformation.__init__(self)
     self.ctx = ctx
     self.passmanager = pm
     self.global_declarations = global_declarations
     self.identifiers = set(self.global_declarations.keys())
示例#24
0
 def __init__(self):
     Transformation.__init__(self)
     # Remap self.visit_XXXX() to self.attach_data() generic method
     for s in GatherOMPData.statements:
         setattr(self, "visit_" + s, self.attach_data)
     self.current = list()
示例#25
0
 def __init__(self, pm, ctx, global_declarations):
     Transformation.__init__(self)
     self.ctx = ctx
     self.passmanager = pm
     self.global_declarations = global_declarations
 def __init__(self):
     self.renamings = dict()
     Transformation.__init__(self, Identifiers)
示例#27
0
 def __init__(self, pm, ctx):
     Transformation.__init__(self)
     self.ctx = ctx
     self.passmanager = pm
     self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
示例#28
0
文件: openmp.py 项目: xmar/pythran
 def __init__(self):
     Transformation.__init__(self)
     # Remap self.visit_XXXX() to self.attach_data() generic method
     for s in GatherOMPData.statements:
         setattr(self, "visit_" + s, self.attach_data)
     self.current = list()
示例#29
0
 def __init__(self, pm, ctx, global_declarations):
     Transformation.__init__(self)
     self.ctx = ctx
     self.passmanager = pm
     self.global_declarations = global_declarations
示例#30
0
 def __init__(self):
     Transformation.__init__(self, OptimizableComprehension)
示例#31
0
 def __init__(self):
     Transformation.__init__(self, UseDefChains, Ancestors, Aliases,
                             RangeValues, Identifiers)
     self.loops_mod = dict()
示例#32
0
 def visit_Call(self, node):
     if isinstance(node.func, ast.Attribute):
         return self.generic_visit(node)
     else:
         return Transformation.generic_visit(self, node)
示例#33
0
 def __init__(self):
     Transformation.__init__(self, UseDefChain, Ancestors, Aliases,
                             RangeValues, Identifiers)
     self.loops_mod = dict()
 def __init__(self):
     Transformation.__init__(self, Globals)
     self.imports = {'__builtin__': '__builtin__'}
     self.to_import = set()
 def __init__(self):
     Transformation.__init__(self, Globals, Ancestors)
     self.imports = {'builtins': 'builtins'}
     self.to_import = set()
示例#36
0
 def __init__(self):
     Transformation.__init__(self, NormalizeTuples,
                             OptimizableComprehension)
示例#37
0
 def __init__(self):
     Transformation.__init__(self, TypeDependencies,
                             OrderedGlobalDeclarations)
示例#38
0
 def __init__(self):
     Transformation.__init__(self, Locals, Globals)
示例#39
0
 def __init__(self):
     Transformation.__init__(self, Identifiers)
示例#40
0
 def __init__(self):
     Transformation.__init__(self)
示例#41
0
 def __init__(self):
     Transformation.__init__(self, PotentialIterator)
示例#42
0
 def __init__(self):
     """ Gather required information. """
     Transformation.__init__(self, PotentialIterator, Aliases)
示例#43
0
 def __init__(self):
     Transformation.__init__(self, NormalizeTuples,
                             PotentialIterator)
示例#44
0
 def __init__(self):
     Transformation.__init__(self, Globals)
     self.imports = {'__builtin__': '__builtin__'}
     self.to_import = set()
示例#45
0
 def __init__(self):
     Transformation.__init__(self, Aliases, ConstantExpressions,
                             PureExpressions)
 def __init__(self):
     Transformation.__init__(self, ConstantExpressions)
示例#47
0
 def __init__(self):
     Transformation.__init__(self, Globals)
     self.imports = set()
     self.to_import = set()
 def __init__(self, pm, ctx):
     Transformation.__init__(self)
     self.ctx = ctx
     self.passmanager = pm
     self.global_declarations = pm.gather(GlobalDeclarations, ctx.module)
示例#49
0
 def __init__(self):
     Transformation.__init__(self, Globals)
     self.imports = set()
     self.to_import = set()
示例#50
0
 def __init__(self):
     self.renamings = dict()
     Transformation.__init__(self, Identifiers)
示例#51
0
 def __init__(self):
     """Gather required information."""
     Transformation.__init__(self, PotentialIterator, Aliases)
     self.use_itertools = False
示例#52
0
 def __init__(self):
     Transformation.__init__(self, ConstantExpressions)
 def __init__(self):
     Transformation.__init__(self, RangeValues)
示例#54
0
 def __init__(self):
     self.count = 0
     Transformation.__init__(self)
示例#55
0
 def __init__(self):
     Transformation.__init__(self, Aliases, PureExpressions)