def signals_to_nets( signals ):

  nets           = []
  slice_connects = set()

  #---------------------------------------------------------------------
  # valid_connection
  #---------------------------------------------------------------------
  # Utility function to filter only supported connections (ports/wires),
  # ignore slices and constants.
  def valid_connection( c ):
    if c.src_slice != None or c.dest_slice != None:
      # TODO: collect slice connections somewhere else
      slice_connects.add( c )
      return False
    else:
      return True

  #---------------------------------------------------------------------
  # iter_dfs
  #---------------------------------------------------------------------
  # Iterative Depth-First-Search algorithm, borrowed from Listing 5-5
  # in 'Python Algorithms': http://www.apress.com/9781430232377/
  def iter_dfs( s ):
    S, Q = set(), []
    Q.append( s )
    while Q:
      u = Q.pop()
      if u in S: continue
      S.add( u )
      connected_signals = [ x.other( u ) for x in u.connections
                            if valid_connection( x ) ]
      Q.extend( connected_signals )
      #yield u
    return S

  # Initially signals contains all the Signal type objects in the model.
  # We perform a depth-first search on the connections of each Signal
  # object, and remove connected objects from the signals set.  The
  # result is a collection of nets describing structural connections in
  # the design. Each independent net will later be transformed into a
  # single SignalValue object.

  while signals:
    s = signals.pop()
    net = iter_dfs( s )
    for i in net:
      #if i is not s: signals.remove( i )
      signals.discard( i )
    nets.append( net )

  return nets, slice_connects

#---------------------------------------------------------------------
# insert_signal_values
#---------------------------------------------------------------------
# Transform each net into a single SignalValue object. Model attributes
# currently referencing Signal objects will be modified to reference
# the SignalValue object of their associated net instead.
dataset/ETHPy150Open cornell-brg/pymtl/pymtl/tools/simulation/sim_utils.py/signals_to_nets/original