Skip to content

Commit

Permalink
Improve class structure
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Aug 31, 2023
1 parent 4a93300 commit f98006e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions dace/sdfg/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Contains classes of a single SDFG state and dataflow subgraphs. """

import ast
import abc
import collections
import copy
import inspect
Expand Down Expand Up @@ -68,7 +69,7 @@ def _make_iterators(ndrange):
return params, map_range


class BlockGraphView(object):
class BlockGraphView(abc.ABC):
"""
Read-only view interface of an SDFG control flow block, containing methods for memlet tracking, traversal, subgraph
creation, queries, and replacements. ``ControlFlowBlock`` and ``StateSubgraphView`` inherit from this class to share
Expand Down Expand Up @@ -136,13 +137,11 @@ def data_nodes(self) -> List[nd.AccessNode]:
return data_nodes

def entry_node(self, node: nd.Node) -> nd.EntryNode:
""" Returns the entry node that wraps the current node, or None if
it is top-level in a state. """
""" Returns the entry node that wraps the current node, or None if it is top-level in a state. """
return self.scope_dict()[node]

def exit_node(self, entry_node: nd.EntryNode) -> nd.ExitNode:
""" Returns the exit node leaving the context opened by
the given entry node. """
""" Returns the exit node leaving the context opened by the given entry node. """
node_to_children = self.scope_children()
return next(v for v in node_to_children[entry_node] if isinstance(v, nd.ExitNode))

Expand Down Expand Up @@ -353,8 +352,7 @@ def scope_leaves(self) -> List['dace.sdfg.scope.ScopeTree']:
return copy.copy(self._scope_leaves_cached)

def scope_dict(self, return_ids: bool = False, validate: bool = True) -> Dict[nd.Node, Optional[nd.Node]]:
""" Returns a dictionary that maps each SDFG node to its parent entry
node, or to None if the node is not in any scope.
""" Returns a dictionary that maps each SDFG node to its parent entry node, or to None if not in any scope.
:param return_ids: Return node ID numbers instead of node objects.
:param validate: Ensure that the graph is not malformed when
Expand Down Expand Up @@ -797,9 +795,6 @@ def set_default_lineinfo(self, lineinfo: dace.dtypes.DebugInfo):
"""
self._default_lineinfo = lineinfo

def data_nodes(self) -> List[nd.AccessNode]:
return []

def replace_dict(self,
repl: Dict[str, str],
symrepl: Optional[Dict[symbolic.SymbolicType, symbolic.SymbolicType]] = None):
Expand Down Expand Up @@ -2054,7 +2049,7 @@ def __init__(self, graph, subgraph_nodes):


@make_properties
class ControlFlowGraph(OrderedDiGraph[ControlFlowBlock, 'dace.sdfg.InterstateEdge']):
class ControlFlowGraph(OrderedDiGraph[ControlFlowBlock, 'dace.sdfg.InterstateEdge'], BlockGraphView):

def __init__(self):
super(ControlFlowGraph, self).__init__()
Expand Down

0 comments on commit f98006e

Please sign in to comment.