def test_get_all_hrefs_of_item(self):
        netlist = sdn.Netlist()
        library = netlist.create_library()
        definition = library.create_definition()
        instance = sdn.Instance()
        instance.reference = definition
        netlist.top_instance = instance

        href = next(HRef.get_all_hrefs_of_item(instance))
        self.assertTrue(href.item is instance)

        href = next(HRef.get_all_hrefs_of_item(definition))
        self.assertTrue(href.item is instance)

        port = definition.create_port()
        href = next(HRef.get_all_hrefs_of_item(port))
        self.assertTrue(href.is_valid and href.item is port)
Esempio n. 2
0
def _get_hports_raw(object_collection, patterns, recursive, is_case, is_re):
    in_namemap = set()
    in_yield = set()
    namemap = dict()
    bypass_namesearch = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            top_instance = obj.top_instance
            if top_instance:
                href = HRef.from_parent_and_item(None, top_instance)
                object_collection.append(href)
        elif isinstance(obj, HRef):
            if obj.is_valid is False:
                continue
            item = obj.item
            if isinstance(item, Instance):
                if obj not in bypass_namesearch:
                    _update_hport_namemap(obj, recursive, in_namemap, namemap)
                else:
                    bypass_namesearch.discard(obj)
                    reference = item.reference
                    if reference:
                        # Get all cables inside a hierarchical instance
                        for port in reference.ports:
                            hport = HRef.from_parent_and_item(obj, port)
                            if hport not in in_yield:
                                in_yield.add(hport)
                                yield(hport)
                        # get internal cables recursively
                        if recursive:
                            for child in reference.children:
                                href_child = HRef.from_parent_and_item(obj, child)
                                bypass_namesearch.add(href_child)
                                object_collection.append(href_child)
            elif isinstance(item, Port):
                if obj not in in_yield:
                    in_yield.add(obj)
                    yield (obj)
            elif isinstance(item, Cable):
                for wire in item.wires:
                    href_wire = HRef.from_parent_and_item(obj, wire)
                    object_collection.append(href_wire)
            elif isinstance(item, Wire):
                    href_parent_cable = obj.parent
                    href_parent_instance = href_parent_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            instance = pin.instance
                            if instance:
                                href_inst = HRef.from_parent_and_item(href_parent_instance, pin.instance)
                                inner_pin = pin.inner_pin
                                if inner_pin:
                                    inner_port = inner_pin.port
                                    if inner_port:
                                        href_port = HRef.from_parent_and_item(href_inst, inner_port)
                                        if href_port not in in_yield:
                                            in_yield.add(href_port)
                                            yield href_port
                        else:
                            port = pin.port
                            if port:
                                href_port = HRef.from_parent_and_item(href_parent_instance, port)
                                if href_port not in in_yield:
                                    in_yield.add(href_port)
                                    yield href_port
            elif isinstance(item, InnerPin):
                hport = obj.parent
                if hport not in in_yield:
                    in_yield.add(hport)
                    yield hport
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Definition):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj.references))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, Instance):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, (Port, Cable, InnerPin, OuterPin, Wire)):
            object_collection += HRef.get_all_hrefs_of_item(obj)

    for href in in_yield:
        in_namemap.discard(href)

    if in_namemap:  # namemap is to cable
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for href in result:
                        if href in in_namemap:
                            in_namemap.remove(href)
                            yield href
            else:
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        for href in result:
                            if href in in_namemap:
                                in_namemap.remove(href)
                                yield href
Esempio n. 3
0
def _get_hwires_raw(object_collection, selection, patterns, recursive, is_case, is_re):
    in_namemap = set()
    in_yield = set()
    namemap = dict()
    hpin_search = set()
    bypass_namesearch = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            top_instance = obj.top_instance
            if top_instance:
                href = HRef.from_parent_and_item(None, top_instance)
                object_collection.append(href)
        elif isinstance(obj, HRef):
            if obj.is_valid is False:
                continue
            item = obj.item
            if isinstance(item, Instance):
                if selection == Selection.INSIDE and obj not in bypass_namesearch:
                    _update_hwire_namemap(obj, recursive, in_namemap, namemap)
                else:
                    bypass_namesearch.discard(obj)
                    reference = item.reference
                    if reference:
                        if selection in {Selection.INSIDE, Selection.ALL}:
                            # Get all cables inside a hierarchical instance
                            for cable in reference.cables:
                                hcable = HRef.from_parent_and_item(obj, cable)
                                for wire in cable.wires:
                                    hwire = HRef.from_parent_and_item(hcable, wire)
                                    if hwire not in in_yield:
                                        in_yield.add(hwire)
                                        yield(hwire)
                            # get internal cables recursively
                            if recursive or selection == Selection.ALL:
                                for child in reference.children:
                                    href_child = HRef.from_parent_and_item(obj, child)
                                    bypass_namesearch.add(href_child)
                                    object_collection.append(href_child)
                        if selection in {Selection.OUTSIDE, Selection.BOTH, Selection.ALL}:
                            for port in reference.ports:
                                href_port = HRef.from_parent_and_item(obj, port)
                                for pin in port.pins:
                                    href_pin = HRef.from_parent_and_item(href_port, pin)
                                    hpin_search.add(href_pin)
            elif isinstance(item, Port):
                for pin in item.pins:
                    href_pin = HRef.from_parent_and_item(obj, pin)
                    hpin_search.add(href_pin)
            elif isinstance(item, Cable):
                for wire in item.wires:
                    href_wire = HRef.from_parent_and_item(obj, wire)
                    object_collection.append(href_wire)
            elif isinstance(item, Wire):
                if selection == Selection.INSIDE:
                    if obj not in in_yield:
                        in_yield.add(obj)
                        yield obj
                elif selection == Selection.OUTSIDE:
                    href_parent_cable = obj.parent
                    href_parent_instance = href_parent_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            href_inst = HRef.from_parent_and_item(href_parent_instance, pin.instance)
                            inner_wire = pin.inner_pin.wire
                            if inner_wire:
                                inner_cable = inner_wire.cable
                                href_cable = HRef.from_parent_and_item(href_inst, inner_cable)
                                href_wire = HRef.from_parent_and_item(href_cable, inner_wire)
                                if href_wire not in in_yield:
                                    in_yield.add(href_wire)
                                    yield href_wire
                        else:
                            href_parent = href_parent_instance.parent
                            if href_parent:
                                instance = href_parent_instance.item
                                if pin in instance.pins:
                                    outer_pin = instance.pins[pin]
                                    outer_wire = outer_pin.wire
                                    if outer_wire:
                                        outer_cable = outer_wire.cable
                                        href_cable = HRef.from_parent_and_item(href_parent, outer_cable)
                                        href_wire = HRef.from_parent_and_item(href_cable, outer_wire)
                                        if href_wire not in in_yield:
                                            in_yield.add(href_wire)
                                            yield href_wire
                else:
                    if obj not in in_yield:
                        in_yield.add(obj)
                        yield obj
                    href_cable = obj.parent
                    href_inst = href_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            href_sub_inst = HRef.from_parent_and_item(obj.parent, pin.instance)
                            inner_pin = pin.inner_pin
                            port = inner_pin.port
                            href_port = HRef.from_parent_and_item(href_sub_inst, port)
                            href_pin = HRef.from_parent_and_item(href_port, pin)
                        else:
                            port = pin.port
                            href_port = HRef.from_parent_and_item(href_inst, port)
                            href_pin = HRef.from_parent_and_item(href_port, pin)
                        object_collection.append(href_pin)
            elif isinstance(item, InnerPin):
                hpin_search.add(obj)
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Definition):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj.references))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, Instance):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, (Port, Cable, InnerPin, OuterPin, Wire)):
            object_collection += HRef.get_all_hrefs_of_item(obj)

    if hpin_search:
        for hwire in _get_hwires_from_hpins(hpin_search, selection):
            if hwire not in in_yield:
                in_yield.add(hwire)
                yield hwire

    for href in in_yield:
        in_namemap.discard(href)

    if in_namemap:
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for href in result:
                        if href in in_namemap:
                            in_namemap.remove(href)
                            yield href
            else:
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        for href in result:
                            if href in in_namemap:
                                in_namemap.remove(href)
                                yield href