示例#1
0
 def seetranslator(self, t):
     if self.opaquepurefunctions:
         from pypy.jit.hintannotator.bookkeeper import ImpurityAnalyzer
         self.analyzer = ImpurityAnalyzer(t)
     self.translator = t
     self.bookkeeper = t.annotator.bookkeeper
     self.timeshift_graphs = {}
     portal = getattr(self.PORTAL, 'im_func', self.PORTAL)
     portal_graph = graphof(t, portal)
     self.fill_timeshift_graphs(portal_graph)
示例#2
0
 def seetranslator(self, t):
     if self.opaquepurefunctions:
         from pypy.jit.hintannotator.bookkeeper import ImpurityAnalyzer
         self.analyzer = ImpurityAnalyzer(t)
     self.translator = t
     self.bookkeeper = t.annotator.bookkeeper
     self.timeshift_graphs = {}
     portal = getattr(self.PORTAL, 'im_func', self.PORTAL)
     portal_graph = graphof(t, portal)
     self.fill_timeshift_graphs(portal_graph)
示例#3
0
class ManualGraphPolicy(HintAnnotatorPolicy):
    novirtualcontainer = True
    oopspec = True
    opaquepurefunctions = False

    def seetranslator(self, t):
        if self.opaquepurefunctions:
            from pypy.jit.hintannotator.bookkeeper import ImpurityAnalyzer
            self.analyzer = ImpurityAnalyzer(t)
        self.translator = t
        self.bookkeeper = t.annotator.bookkeeper
        self.timeshift_graphs = {}
        portal = getattr(self.PORTAL, 'im_func', self.PORTAL)
        portal_graph = graphof(t, portal)
        self.fill_timeshift_graphs(portal_graph)

    def look_inside_graph(self, graph):
        if graph in self.timeshift_graphs:
            return self.timeshift_graphs[graph]
        # don't look into pure functions
        if (self.opaquepurefunctions
                and not self.analyzer.analyze_direct_call(graph)):
            return False
        try:
            func = graph.func
        except AttributeError:
            return True
        if hasattr(func, '_look_inside_me_'):
            return func._look_inside_me_
        # explicitly pure functions are always opaque
        if getattr(func, '_pure_function_', False):
            return False
        mod = func.__module__ or '?'
        return self.look_inside_graph_of_module(graph, func, mod)

    def look_inside_graph_of_module(self, graph, func, mod):
        return True

    def fill_timeshift_graphs(self, portal_graph):
        # subclasses should have their own
        pass

    def _graph(self, func):
        func = getattr(func, 'im_func', func)
        desc = self.bookkeeper.getdesc(func)
        return getuniquenondirectgraph(desc)

    def seefunc(self, fromfunc, *tofuncs):
        targetgraphs = {}
        for tofunc in tofuncs:
            targetgraphs[self._graph(tofunc)] = True
        graphs = graphs_on_the_path_to(self.translator, self._graph(fromfunc),
                                       targetgraphs)
        for graph in graphs:
            self.timeshift_graphs[graph] = True

    def seepath(self, *path):
        for i in range(1, len(path)):
            self.seefunc(path[i - 1], path[i])

    def seegraph(self, func, look=True):
        graph = self._graph(func)
        self.timeshift_graphs[graph] = look
示例#4
0
class ManualGraphPolicy(HintAnnotatorPolicy):
    novirtualcontainer = True
    oopspec = True
    opaquepurefunctions = False

    def seetranslator(self, t):
        if self.opaquepurefunctions:
            from pypy.jit.hintannotator.bookkeeper import ImpurityAnalyzer
            self.analyzer = ImpurityAnalyzer(t)
        self.translator = t
        self.bookkeeper = t.annotator.bookkeeper
        self.timeshift_graphs = {}
        portal = getattr(self.PORTAL, 'im_func', self.PORTAL)
        portal_graph = graphof(t, portal)
        self.fill_timeshift_graphs(portal_graph)

    def look_inside_graph(self, graph):
        if graph in self.timeshift_graphs:
            return self.timeshift_graphs[graph]
        # don't look into pure functions
        if (self.opaquepurefunctions and
            not self.analyzer.analyze_direct_call(graph)):
            return False
        try:
            func = graph.func
        except AttributeError:
            return True
        if hasattr(func, '_look_inside_me_'):
            return func._look_inside_me_
        # explicitly pure functions are always opaque
        if getattr(func, '_pure_function_', False):
            return False
        mod = func.__module__ or '?'
        return self.look_inside_graph_of_module(graph, func, mod)

    def look_inside_graph_of_module(self, graph, func, mod):
        return True

    def fill_timeshift_graphs(self, portal_graph):
        # subclasses should have their own
        pass

    def _graph(self, func):
        func = getattr(func, 'im_func', func)
        desc = self.bookkeeper.getdesc(func)
        return getuniquenondirectgraph(desc)

    def seefunc(self, fromfunc, *tofuncs):
        targetgraphs = {}
        for tofunc in tofuncs:
            targetgraphs[self._graph(tofunc)] = True
        graphs = graphs_on_the_path_to(self.translator, self._graph(fromfunc),
                                       targetgraphs)
        for graph in graphs:
            self.timeshift_graphs[graph] = True

    def seepath(self, *path):
        for i in range(1, len(path)):
            self.seefunc(path[i-1], path[i])

    def seegraph(self, func, look=True):
        graph = self._graph(func)
        self.timeshift_graphs[graph] = look