def flattenPort(port: LPort):
    """
    Flatten hierarchical ports
    """
    yield port
    if port.children:
        for ch in port.children:
            yield from flattenPort(ch)
        port.children.clear()
Flatten hierarchical ports