+ idx += 1
+ if idx >= len(cell):
+ return ' // unused'
+ cname = cell[idx]
+ if not cname:
+ return ' // unused'
+ temp = transfn(cname)
+ x = ifaces.getifacetype(temp)
+ #print (cname, x)
+ if x == 'input':
+ return ' // %s is an input' % cname
+ if outenmode and x == 'inout':
+ return ' // bi-directional'
+ if outenmode and x == 'out':
+ return ' // %s is an output' % cname
+
+ return ""
+
+
+def mkmux(p, ifaces, cell, suffix, outenmode):
+ """ creates a straight many-to-one muxer that accepts
+ multiple inputs and, based on an "address" routes
+ a given indexed input through to the (one) output
+ """
+ cellnum = cell[0]
+ comment = 'outen' if outenmode else 'output'
+ fmtstr = "\t\t\twr%s==%d?%s:%s\n" # mux-selector format
+ ret = ''
+ ret += " // %s muxer for cell idx %s\n" % (comment, cellnum)
+ ret += " %s%s=\n" % (cn(cellnum), suffix)
+ i = 0
+ mwid = p.get_muxwidth(cellnum)
+ if mwid > 1:
+ for i in range(0, mwid - 1): # full mux range (minus 1)
+ comment = mkcomment(ifaces, cell, i, outenmode)
+ cf = fmt(ifaces, cell, i, suffix)
+ ret += fmtstr % (cn(cell[0]), i, cf, comment)
+ i += 1
+ comment = mkcomment(ifaces, cell, i, outenmode)
+ ret += "\t\t\t" + fmt(ifaces, cell, i, suffix) # last line
+ ret += ";%s\n" % comment
+
+ return ret
+