Skip to content
Snippets Groups Projects

Resolve "Visualize PG"

Merged Rasmus Karlsson requested to merge 27-visualize-pg into develop
All threads resolved!
Files
3
@@ -9,6 +9,7 @@ from collections import defaultdict, deque
from io import StringIO
from queue import PriorityQueue
import itertools
from graphviz import Digraph
from b_asic.port import SignalSourceProvider, OutputPort
from b_asic.operation import Operation, AbstractOperation, MutableOutputMap, MutableRegisterMap
@@ -577,6 +578,27 @@ class SFG(AbstractOperation):
return precedence_list
def show_precedence_graph(self) -> None:
p_list = self.get_precedence_list()
pg = Digraph()
pg.attr(rankdir = 'LR')
# Creates nodes for each output port in the precedence list
for i in range(len(p_list)):
ports = p_list[i]
with pg.subgraph(name='cluster_' + str(i)) as sub:
sub.attr(label='N' + str(i + 1))
for port in ports:
sub.node(port.operation.graph_id + '.' + str(port.index))
# Creates edges for each output port and creates nodes for each operation and edges for them as well
for i in range(len(p_list)):
ports = p_list[i]
for port in ports:
for signal in port.signals:
pg.edge(port.operation.graph_id + '.' + str(port.index), signal.destination.operation.graph_id)
pg.edge(port.operation.graph_id, port.operation.graph_id + '.' + str(port.index))
pg.view()
def print_precedence_graph(self) -> None:
"""Prints a representation of the SFG's precedence list to the standard out.
If the precedence list already has been calculated then it uses the cached version,
Loading