Exemple #1
0
def _apply_path_update(path: ComponentPath, old_path_prefix: ComponentPath,
                       new_path_prefix: ComponentPath):
    """
    Update prefix of the path tuple
    """
    if isinstance(path, iHdlConstrain):
        return path._copy_with_root_upadate(old_path_prefix, new_path_prefix)
    return path.update_prefix(old_path_prefix, new_path_prefix)
Exemple #2
0
    def set_css_style(self,
                      hwt_obj: Union[RtlSignal, Interface, Unit, ComponentPath,
                                     Operator, HdlStatement], style_str: str):
        """
        :note: If you doing a large update use :class:`UpdateAccumulator`
        .. code-block:: python

            with UpdateAccumulator(scheme):
                scheme.set_css_style(x, "fill:red")
                scheme.set_css_style(y, "fill:blue")

        """
        if self.hwt_obj_to_j_obj_ids is None:
            self._init_hwt_obj_to_json_mapping_dicts()

        if isinstance(hwt_obj, Interface):
            hwt_obj = hwt_obj._sigInside

        if not isinstance(hwt_obj, ComponentPath):
            hwt_obj = ComponentPath(hwt_obj)

        j_ids = self.hwt_obj_to_j_obj_ids[hwt_obj]
        for j_id in j_ids:
            j_obj = self.id_to_j_obj[str(j_id)]
            j_obj["hwMeta"]["cssStyle"] = style_str

        if not self._update_accumulator:
            self._trigger_update()
Exemple #3
0
    def toElkJson(self, idStore: "ElkIdStore", path_prefix: ComponentPath=ComponentPath(), isTop=True):
        props = {
            "org.eclipse.elk.portConstraints": self.portConstraints.name,
            'org.eclipse.elk.layered.mergeEdges': 1,
        }
        hw_meta = {
            "name": self.name,
            "cls": self.cls,
        }
        d = {
            "hwMeta": hw_meta,
            "properties": props
        }
        hideChildren = False
        if self.bodyText is not None:
            hw_meta["bodyText"] = self.bodyText

        if isTop:
            self.toElkJson_registerNodes(idStore, path_prefix)
            self.toElkJson_registerPorts(idStore, path_prefix)
        else:
            d["id"] = str(idStore[path_prefix / self])
            hideChildren = True
            # if self.parent.parent is not None:
            #    props["org.eclipse.elk.noLayout"] = True

        d["ports"] = [p.toElkJson(idStore, path_prefix)
                      for p in self.iterPorts()]

        children, path_prefix = self._getUniqRefChildren(path_prefix)
        if children:
            assert isinstance(children, list)
            formalParent = self._shared_component_with
            if formalParent is None:
                formalParent = self
            nodes = []
            edges = UniqList()
            for ch in children:
                for e in ch.iterEdges():
                    if e.parentNode is formalParent:
                        edges.append(e)

            for ch in children:
                nodes.append(ch.toElkJson(idStore, isTop=False, path_prefix=path_prefix))

            nodes.sort(key=lambda n: n["id"])
            d["_children" if hideChildren else "children"] = nodes

            for e in edges:
                idStore.registerEdge(path_prefix / e)

            d["_edges" if hideChildren else "edges"] = [e.toElkJson(idStore, path_prefix) for e in edges]

        hw_meta["maxId"] = idStore.getMaxId()

        return d
Exemple #4
0
def _get_absolute_path(
    obj
) -> Union[Tuple[Union[Unit, Interface, RtlSignal, iHdlConstrain], ...], None]:
    """
    Get tuple containing a path of objects from top to this object
    """
    if obj is None:
        return None
    elif isinstance(obj, iHdlConstrain):
        return obj

    return ComponentPath(obj).resolve()
Exemple #5
0
 def __init__(self):
     # RtlSignal: Set[RtlSignal]
     self.comb_connection_matrix = {}
     # RtlSignal: set of signals in comb loop
     self._report = {}
     self.actual_path_prefix = ComponentPath()
Exemple #6
0
    def _init_hwt_obj_to_json_mapping_dicts(self):
        # 1:1
        id_to_j_obj = {}

        def walk_json(obj):
            _id = obj.get("id", None)
            if _id is not None:
                id_to_j_obj[_id] = obj

            for prop in ("ports", "children", "edges", "_children", "_edges"):
                obj_list = obj.get(prop, None)
                if obj_list:
                    for o in obj_list:
                        walk_json(o)

        walk_json(self.value)

        # N:M
        hwt_obj_to_j_obj_ids = {}

        def collect_port_signal(key, port_signal, j_id):
            if isinstance(key, ComponentPath):
                port_signal = ComponentPath(*key[:-1], port_signal)

            hwt_obj_to_j_obj_ids.setdefault(port_signal, set()).add(j_id)

        def collect_l_obj(j_id, key, _hwt_obj):
            if _hwt_obj is None or isinstance(_hwt_obj,
                                              (HValue, HdlStatement)):
                return

            if isinstance(_hwt_obj, (Unit, Interface, RtlSignal, Operator)):
                hwt_obj_to_j_obj_ids.setdefault(key, set()).add(j_id)

            elif isinstance(_hwt_obj, HdlPortItem):
                if _hwt_obj.src is not None:
                    collect_port_signal(key, _hwt_obj.src, j_id)

                if _hwt_obj.dst is not None:
                    collect_port_signal(key, _hwt_obj.dst, j_id)
            else:
                print("Can not find in json", key)
                # raise NotImplementedError(key, _hwt_obj)

        # need_to_convert_component_paths = False
        for l_obj, j_id in self.json_idStore.items():
            if isinstance(l_obj, ComponentPath):
                # need_to_convert_component_paths = True
                key = ComponentPath(*(o.originObj for o in l_obj))
                _hwt_obj = key[-1]
                if type(_hwt_obj) is tuple or type(
                        _hwt_obj) is InterfaceSplitInfo:
                    key_prefix = key[:-1]
                    for _hwt_obj0 in _hwt_obj:
                        collect_l_obj(j_id, key_prefix / _hwt_obj0, _hwt_obj0)
                else:
                    collect_l_obj(j_id, key, _hwt_obj)

            else:
                _hwt_obj = l_obj.originObj
                if type(_hwt_obj) is tuple:
                    for _hwt_obj0 in _hwt_obj:
                        collect_l_obj(j_id, key, _hwt_obj0)
                else:
                    key = _hwt_obj
                    collect_l_obj(j_id, key, _hwt_obj)

        self.hwt_obj_to_j_obj_ids = hwt_obj_to_j_obj_ids
        self.id_to_j_obj = id_to_j_obj
Exemple #7
0
        def collect_port_signal(key, port_signal, j_id):
            if isinstance(key, ComponentPath):
                port_signal = ComponentPath(*key[:-1], port_signal)

            hwt_obj_to_j_obj_ids.setdefault(port_signal, set()).add(j_id)