+class InterfaceFmt(object):
+
+ def ifacepfmtdecpin(self, pin):
+ return pin.ifacepfmt(self.ifacepfmtdecfn)
+
+ def ifacepfmtdecfn(self, name):
+ return name
+
+ def ifacefmtoutfn(self, name):
+ return "wr%s" % name # like wruart
+
+ def ifacefmtdecfn2(self, name):
+ return name # like: uart
+
+ def ifacefmtdecfn3(self, name):
+ """ HACK! """
+ return "%s_outen" % name # like uart_outen
+
+ def ifacefmtinfn(self, name):
+ return "wr%s" % name
+
+ def ifacedef2pin(self, pin):
+ decfn = self.ifacefmtdecfn2
+ outfn = self.ifacefmtoutfn
+ # print pin, pin.outenmode
+ if pin.outenmode:
+ decfn = self.ifacefmtdecfn3
+ outfn = self.ifacefmtoutenfn
+ return pin.ifacedef2(outfn, self.ifacefmtinfn,
+ decfn)
+
+ def vectorifacedef2(self, pins, count, names, bitfmt, *args):
+ tput = []
+ tget = []
+ tputen = []
+ if len(pins) == 0:
+ return ''
+ # XXX HACK! assume in, out and inout, create set of indices
+ # that are repeated three times.
+ plens = []
+ # ARG even worse hack for LCD *sigh*...
+ if names[1] is None and names[2] is None:
+ plens = range(len(pins))
+ else:
+ for i in range(0, len(pins), 3):
+ plens += [i / 3, i / 3, i / 3]
+ for (typ, txt) in map(self.ifacedef3pin, plens, pins):
+ if typ == 'tput':
+ tput.append(txt)
+ elif typ == 'tget':
+ tget.append(txt)
+ elif typ == 'tputen':
+ tputen.append(txt)
+ tput = '\n'.join(tput).format(*args)
+ tget = '\n'.join(tget).format(*args)
+ tputen = '\n'.join(tputen).format(*args)
+ bitfmt = bitfmt.format(count)
+ template = ["""\
+ interface {3} = interface Put#({0})
+ method Action put({2} in);
+{1}
+ endmethod
+ endinterface;
+""",
+ """\
+ interface {3} = interface Put#({0})
+ method Action put({2} in);
+{1}
+ endmethod
+ endinterface;
+""",
+ """\
+ interface {3} = interface Get#({0})
+ method ActionValue#({2}) get;
+ {2} tget;
+{1}
+ return tget;
+ endmethod
+ endinterface;
+"""]
+ res = ''
+ tlist = [tput, tputen, tget]
+ for i, n in enumerate(names):
+ if n:
+ res += template[i].format(count, tlist[i], bitfmt, n)
+ return '\n' + res + '\n'
+
+
+class Interface(PeripheralIface, InterfaceFmt):