Esempio n. 1
0
def kill_assertion_link(graph, link):
    block = link.prevblock
    exits = list(block.exits)
    if len(exits) <= 1:
        return False
    remove_condition = len(exits) == 2
    if block.exitswitch == c_last_exception:
        if link is exits[0]:
            return False  # cannot remove the non-exceptional path
    else:
        if block.exitswitch.concretetype is not lltype.Bool:  # a switch
            remove_condition = False
        else:
            # common case: if <cond>: raise AssertionError
            # turn it into a debug_assert operation
            assert remove_condition
            newops = LowLevelOpList()
            if link.exitcase:
                v = newops.genop('bool_not', [block.exitswitch],
                                 resulttype=lltype.Bool)
            else:
                v = block.exitswitch
            msg = "assertion failed in %s" % (graph.name, )
            c_msg = inputconst(lltype.Void, msg)
            newops.genop('debug_assert', [v, c_msg])
            block.operations.extend(newops)

    exits.remove(link)
    if remove_condition:
        # condition no longer necessary
        block.exitswitch = None
        exits[0].exitcase = None
        exits[0].llexitcase = None
    block.recloseblock(*exits)
    return True
Esempio n. 2
0
def kill_assertion_link(graph, link):
    block = link.prevblock
    exits = list(block.exits)
    if len(exits) <= 1:
        return False
    remove_condition = len(exits) == 2
    if block.canraise:
        if link is exits[0]:
            return False       # cannot remove the non-exceptional path
    else:
        if block.exitswitch.concretetype is not lltype.Bool:   # a switch
            remove_condition = False
        else:
            # common case: if <cond>: raise AssertionError
            # turn it into a debug_assert operation
            assert remove_condition
            newops = LowLevelOpList()
            if link.exitcase:
                v = newops.genop('bool_not', [block.exitswitch],
                                 resulttype=lltype.Bool)
            else:
                v = block.exitswitch
            msg = "assertion failed in %s" % (graph.name,)
            c_msg = inputconst(lltype.Void, msg)
            newops.genop('debug_assert', [v, c_msg])
            block.operations.extend(newops)

    exits.remove(link)
    if remove_condition:
        # condition no longer necessary
        block.exitswitch = None
        exits[0].exitcase = None
        exits[0].llexitcase = None
    block.recloseblock(*exits)
    return True
Esempio n. 3
0
 def generate_exception_match(self, oplist, var_etype, const_etype):
     # generate the content of rclass.ll_issubclass(_const)
     from rpython.rtyper.rtyper import LowLevelOpList
     from rpython.rtyper.lltypesystem import lltype
     from rpython.flowspace.model import Constant, Variable, SpaceOperation
     llops = LowLevelOpList(None)
     field = llops.genop(
         'getfield',
         [var_etype, llops.genvoidconst('subclassrange_min')],
         lltype.Signed)
     res = llops.genop('int_between', [
         llops.genconst(const_etype.value.subclassrange_min),
         field,
         llops.genconst(const_etype.value.subclassrange_max),
     ], lltype.Bool)
     oplist.extend(llops)
     return res