def regnames_to_ranges(dev, regs):
    """Convert a list of register names to a register-ranges string.

    """
    indices = []
    for name in regs:
        indices.append(dev.reg_idx(name))
    indices = sorted(indices)
    ranges = []
    idx = 0
    while idx < len(indices):
        start = stop = indices[idx]
        idx += 1
        while idx < len(indices) and indices[idx] == stop + 1:
            stop = indices[idx]
            idx += 1
        if start == stop:
            ranges.append('%s' % start)
        else:
            ranges.append('%s:%s' % (start, stop))
    return ','.join(ranges)
