Split a list of IR blocks into per-location MATCH steps.

    Args:
        pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step.

    Returns:
        list of MatchStep namedtuples, each of which contains all basic blocks that correspond
        to a single MATCH step.

def _split_ir_into_match_steps(pruned_ir_blocks):
    """Split a list of IR blocks into per-location MATCH steps.

    Args:
        pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step.

    Returns:
        list of MatchStep namedtuples, each of which contains all basic blocks that correspond
        to a single MATCH step.
    """
    output = []
    current_tuple = None
    for block in pruned_ir_blocks:
        if isinstance(block, OutputSource):
            # OutputSource blocks do not require any MATCH code, and only serve to help
            # optimizations and debugging. Simply omit them at this stage.
            continue
        elif isinstance(block, root_block_types):
            if current_tuple is not None:
                output.append(current_tuple)
            current_tuple = (block,)
        elif isinstance(block, (CoerceType, Filter, MarkLocation)):
            current_tuple += (block,)
        else:
            raise AssertionError(u'Unexpected block type when converting to MATCH query: '
                                 u'{} {}'.format(block, pruned_ir_blocks))

    if current_tuple is None:
        raise AssertionError(u'current_tuple was unexpectedly None: {}'.format(pruned_ir_blocks))
    output.append(current_tuple)

    return [_per_location_tuple_to_step(x) for x in output]