Skip to content
Snippets Groups Projects
Commit ba6dfd11 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add fontname argument to Architecture digraph and use it for all text

parent 647716f2
No related branches found
No related tags found
1 merge request!530Add fontname argument to Architecture digraph and use it for all text
Pipeline #161949 passed
...@@ -171,14 +171,21 @@ class Resource(HardwareBlock): ...@@ -171,14 +171,21 @@ class Resource(HardwareBlock):
def __iter__(self): def __iter__(self):
return iter(self._collection) return iter(self._collection)
def _digraph(self) -> Digraph: def _digraph(self, fontname: str = "Times New Roman") -> Digraph:
"""
Parameters
----------
fontname : str, default: "Times New Roman"
Font to use.
"""
dg = Digraph(node_attr={"shape": "box"}) dg = Digraph(node_attr={"shape": "box"})
dg.node( dg.node(
self.entity_name, self.entity_name,
self._struct_def(), self._struct_def(),
style="filled", style="filled",
fillcolor=self._color, fillcolor=self._color,
fontname="Times New Roman", fontname=fontname,
) )
return dg return dg
...@@ -1000,6 +1007,7 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1000,6 +1007,7 @@ of :class:`~b_asic.architecture.ProcessingElement`
io_cluster: bool = True, io_cluster: bool = True,
multiplexers: bool = True, multiplexers: bool = True,
colored: bool = True, colored: bool = True,
fontname: str = "Times New Roman",
) -> Digraph: ) -> Digraph:
""" """
Parameters Parameters
...@@ -1017,6 +1025,8 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1017,6 +1025,8 @@ of :class:`~b_asic.architecture.ProcessingElement`
Whether input multiplexers are included. Whether input multiplexers are included.
colored : bool, default: True colored : bool, default: True
Whether to color the nodes. Whether to color the nodes.
fontname : str, default: "Times New Roman"
Font to use.
""" """
dg = Digraph(node_attr={"shape": "box"}) dg = Digraph(node_attr={"shape": "box"})
dg.attr(splines=splines) dg.attr(splines=splines)
...@@ -1062,10 +1072,10 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1062,10 +1072,10 @@ of :class:`~b_asic.architecture.ProcessingElement`
mem._struct_def(), mem._struct_def(),
style="filled", style="filled",
fillcolor=memory_color, fillcolor=memory_color,
fontname="Times New Roman", fontname=fontname,
) )
label = "Memory" if len(self._memories) <= 1 else "Memories" label = "Memory" if len(self._memories) <= 1 else "Memories"
c.attr(label=label, bgcolor=memory_cluster_color) c.attr(label=label, bgcolor=memory_cluster_color, fontname=fontname)
with dg.subgraph(name="cluster_pes") as c: with dg.subgraph(name="cluster_pes") as c:
for pe in self._processing_elements: for pe in self._processing_elements:
if pe._type_name not in ("in", "out"): if pe._type_name not in ("in", "out"):
...@@ -1074,14 +1084,14 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1074,14 +1084,14 @@ of :class:`~b_asic.architecture.ProcessingElement`
pe._struct_def(), pe._struct_def(),
style="filled", style="filled",
fillcolor=pe_color, fillcolor=pe_color,
fontname="Times New Roman", fontname=fontname,
) )
label = ( label = (
"Processing element" "Processing element"
if len(self._processing_elements) <= 1 if len(self._processing_elements) <= 1
else "Processing elements" else "Processing elements"
) )
c.attr(label=label, bgcolor=pe_cluster_color) c.attr(label=label, bgcolor=pe_cluster_color, fontname=fontname)
if io_cluster: if io_cluster:
with dg.subgraph(name="cluster_io") as c: with dg.subgraph(name="cluster_io") as c:
for pe in self._processing_elements: for pe in self._processing_elements:
...@@ -1091,9 +1101,9 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1091,9 +1101,9 @@ of :class:`~b_asic.architecture.ProcessingElement`
pe._struct_def(), pe._struct_def(),
style="filled", style="filled",
fillcolor=io_color, fillcolor=io_color,
fontname="Times New Roman", fontname=fontname,
) )
c.attr(label="IO", bgcolor=io_cluster_color) c.attr(label="IO", bgcolor=io_cluster_color, fontname=fontname)
else: else:
for pe in self._processing_elements: for pe in self._processing_elements:
if pe._type_name in ("in", "out"): if pe._type_name in ("in", "out"):
...@@ -1102,7 +1112,7 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1102,7 +1112,7 @@ of :class:`~b_asic.architecture.ProcessingElement`
pe._struct_def(), pe._struct_def(),
style="filled", style="filled",
fillcolor=io_color, fillcolor=io_color,
fontname="Times New Roman", fontname=fontname,
) )
else: else:
for mem in self._memories: for mem in self._memories:
...@@ -1111,11 +1121,15 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1111,11 +1121,15 @@ of :class:`~b_asic.architecture.ProcessingElement`
mem._struct_def(), mem._struct_def(),
style="filled", style="filled",
fillcolor=memory_color, fillcolor=memory_color,
fontname="Times New Roman", fontname=fontname,
) )
for pe in self._processing_elements: for pe in self._processing_elements:
dg.node( dg.node(
pe.entity_name, pe._struct_def(), style="filled", fillcolor=pe_color pe.entity_name,
pe._struct_def(),
style="filled",
fillcolor=pe_color,
fontname=fontname,
) )
# Create list of interconnects # Create list of interconnects
...@@ -1172,7 +1186,7 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1172,7 +1186,7 @@ of :class:`~b_asic.architecture.ProcessingElement`
ret + "</TABLE>>", ret + "</TABLE>>",
style="filled", style="filled",
fillcolor=mux_color, fillcolor=mux_color,
fontname="Times New Roman", fontname=fontname,
) )
# Add edge from mux output to resource input # Add edge from mux output to resource input
dg.edge(f"{name}:out0", destination_str) dg.edge(f"{name}:out0", destination_str)
...@@ -1183,13 +1197,13 @@ of :class:`~b_asic.architecture.ProcessingElement` ...@@ -1183,13 +1197,13 @@ of :class:`~b_asic.architecture.ProcessingElement`
if len(destination_counts) > 1 and branch_node: if len(destination_counts) > 1 and branch_node:
branch = f"{src_str}_branch".replace(":", "") branch = f"{src_str}_branch".replace(":", "")
dg.node(branch, shape="point") dg.node(branch, shape="point")
dg.edge(src_str, branch, arrowhead="none") dg.edge(src_str, branch, arrowhead="none", fontname=fontname)
src_str = branch src_str = branch
for destination_str, cnt_str in destination_counts: for destination_str, cnt_str in destination_counts:
if multiplexers and len(destination_list[destination_str]) > 1: if multiplexers and len(destination_list[destination_str]) > 1:
idx = destination_list[destination_str].index(original_src_str) idx = destination_list[destination_str].index(original_src_str)
destination_str = f"{destination_str.replace(':', '_')}_mux:in{idx}" destination_str = f"{destination_str.replace(':', '_')}_mux:in{idx}"
dg.edge(src_str, destination_str, label=cnt_str) dg.edge(src_str, destination_str, label=cnt_str, fontname=fontname)
return dg return dg
@property @property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment