当前位置: 首页>>代码示例>>Python>>正文


Python TranslationContext.getexceptiontransformer方法代码示例

本文整理汇总了Python中rpython.translator.translator.TranslationContext.getexceptiontransformer方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationContext.getexceptiontransformer方法的具体用法?Python TranslationContext.getexceptiontransformer怎么用?Python TranslationContext.getexceptiontransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rpython.translator.translator.TranslationContext的用法示例。


在下文中一共展示了TranslationContext.getexceptiontransformer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_secondary_backendopt

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import getexceptiontransformer [as 别名]
    def test_secondary_backendopt(self):
        # checks an issue with a newly added graph that calls an
        # already-exception-transformed graph.  This can occur e.g.
        # from a late-seen destructor added by the GC transformer
        # which ends up calling existing code.
        def common(n):
            if n > 5:
                raise ValueError

        def main(n):
            common(n)

        def later(n):
            try:
                common(n)
                return 0
            except ValueError:
                return 1

        t = TranslationContext()
        t.buildannotator().build_types(main, [int])
        t.buildrtyper().specialize()
        exctransformer = t.getexceptiontransformer()
        exctransformer.create_exception_handling(graphof(t, common))
        from rpython.annotator import model as annmodel
        from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator

        annhelper = MixLevelHelperAnnotator(t.rtyper)
        later_graph = annhelper.getgraph(later, [annmodel.SomeInteger()], annmodel.SomeInteger())
        annhelper.finish()
        annhelper.backend_optimize()
        # ^^^ as the inliner can't handle exception-transformed graphs,
        # this should *not* inline common() into later().
        if option.view:
            later_graph.show()
        common_graph = graphof(t, common)
        found = False
        for block in later_graph.iterblocks():
            for op in block.operations:
                if op.opname == "direct_call" and op.args[0].value._obj.graph is common_graph:
                    found = True
        assert found, "cannot find the call (buggily inlined?)"
        from rpython.rtyper.llinterp import LLInterpreter

        llinterp = LLInterpreter(t.rtyper)
        res = llinterp.eval_graph(later_graph, [10])
        assert res == 1
开发者ID:mozillazg,项目名称:pypy,代码行数:49,代码来源:test_all.py

示例2: test_gctransformed

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import getexceptiontransformer [as 别名]
def test_gctransformed():
    t = TranslationContext()
    a = t.buildannotator()
    a.build_types(g, [int])
    a.simplify()
    t.buildrtyper().specialize()
    backend_optimizations(t)
    t.checkgraphs()
    n = insert_ll_stackcheck(t)
    t.checkgraphs()
    assert n == 1
    exctransf = t.getexceptiontransformer()
    f_graph = graphof(t, f)
    exctransf.create_exception_handling(f_graph)
    if option.view:
        f_graph.show()
    check(f_graph, "f")

    class GCTransform(shadowstack.ShadowStackFrameworkGCTransformer):
        from rpython.memory.gc.generation import GenerationGC as GCClass

        GC_PARAMS = {}

    gctransf = GCTransform(t)
    gctransf.transform_graph(f_graph)
    if option.view:
        f_graph.show()
    relevant = check(f_graph, "f")
    for p in relevant:
        in_between = False
        reload = 0
        for spaceop in p:
            if spaceop.opname == "direct_call":
                target = direct_target(spaceop)
                if target == "f":
                    in_between = False
                elif target == "stack_check___":
                    in_between = True
            if in_between and spaceop.opname == "gc_reload_possibly_moved":
                reload += 1

        assert reload == 0
开发者ID:cimarieta,项目名称:usp,代码行数:44,代码来源:test_stackcheck.py


注:本文中的rpython.translator.translator.TranslationContext.getexceptiontransformer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。