big python3 interoperability update
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 31 Mar 2018 07:23:48 +0000 (08:23 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 31 Mar 2018 07:23:48 +0000 (08:23 +0100)
src/bsv/actual_pinmux.py
src/bsv/interface_decl.py
src/bsv/pinmux_generator.py
src/parse.py
src/spec/__init__.py
src/spec/c_class.py
src/spec/gen.py
src/spec/ifaceprint.py

index 2db44186be650986cbabe077a1b89a2e2cb45c68..337bd92e8a3bcda080f44da879f67d107a6e18d1 100644 (file)
@@ -56,7 +56,7 @@ def init(p, ifaces):
             cname = cell[i + 1]
             temp = transfn(cname)
             x = ifaces.getifacetype(temp)
-            print cname, temp, x
+            print (cname, temp, x)
             assert x is not None, "ERROR: The signal : " + \
                 str(cname) + \
                 " of pinmap.txt isn't present \nin the current" + \
index d27b4ff695c5882cfe47cf1c2837d03b6a00b068..d9eed87d35fee58838468caad05691e6585f2984 100644 (file)
@@ -1,9 +1,12 @@
 import os.path
 
-from UserDict import UserDict
+try:
+    from UserDict import UserDict
+except ImportError:
+    from collections import UserDict
 
-from wire_def import generic_io  # special case
-from wire_def import muxwire  # special case
+from bsv.wire_def import generic_io  # special case
+from bsv.wire_def import muxwire  # special case
 
 
 class Pin(object):
@@ -340,19 +343,19 @@ if __name__ == '__main__':
         l1 = l1.split("\n")
         l2 = l2.split("\n")
         for p1, p2 in zip(l1, l2):
-            print repr(p1)
-            print repr(p2)
-            print
+            print (repr(p1))
+            print (repr(p2))
+            print ()
             assert p1 == p2
 
     ifaces = Interfaces()
 
     ifaceuart = ifaces['uart']
-    print ifaceuart.ifacedef(0)
-    print uartinterface_decl.ifacedef(0)
+    print (ifaceuart.ifacedef(0))
+    print (uartinterface_decl.ifacedef(0))
     assert ifaceuart.ifacedef(0) == uartinterface_decl.ifacedef(0)
 
     ifacetwi = ifaces['twi']
-    print ifacetwi.ifacedef(0)
-    print twiinterface_decl.ifacedef(0)
+    print (ifacetwi.ifacedef(0))
+    print (twiinterface_decl.ifacedef(0))
     assert ifacetwi.ifacedef(0) == twiinterface_decl.ifacedef(0)
index b2b399826ccd3e2c3302e5e6bf0dc88b50a7a9a8..3431bf144b3ebaaafdbab292b86acf7e1db40b2a 100644 (file)
@@ -22,10 +22,10 @@ import time
 import math
 
 # project module imports
-from interface_decl import Interfaces, mux_interface, io_interface
+from bsv.interface_decl import Interfaces, mux_interface, io_interface
 from parse import Parse
-from actual_pinmux import init
-from bus_transactors import axi4_lite
+from bsv.actual_pinmux import init
+from bsv.bus_transactors import axi4_lite
 
 copyright = '''
 /*
index a02ff8fb619bf6f466aff063d9837f343e7e42ab..02c9ea94e241f996b803593393cb9af063ddf44e 100644 (file)
@@ -103,4 +103,4 @@ class Parse(object):
 
 if __name__ == '__main__':
     p = Parse()
-    print p.N_IO
+    print (p.N_IO)
index 34f390c7769fab5572cad040ec5b4a476a0b640a..383cab356bba957132cfc309818db6fd544181e8 100644 (file)
@@ -1,7 +1,7 @@
 from spec import m_class
 from spec import c_class
 from spec import minitest
-from gen import specgen
+from spec.gen import specgen
 
 modules = {'m_class': m_class,
            'c_class': c_class,
index 648bd30007e698670b84241a064e5df88bf12144..0bc7f11abbff93a452d76225edb7b60f23d5b472 100644 (file)
@@ -1,11 +1,10 @@
 #!/usr/bin/env python
 
-from interfaces import Pinouts
-from ifaceprint import display, display_fns, check_functions
-from ifaceprint import display_fixed
+from spec.ifaceprint import display, display_fns, check_functions
+from spec.ifaceprint import display_fixed
 
 
-def pinspec():
+def pinspec(of):
     pinouts = {}
 
     pinbanks = {'A': 16,
@@ -84,17 +83,16 @@ def pinspec():
 
     pinmerge(pinouts, rgmii(bankspec, "", ('G', 0), "G", 1))
 
-    print "# Pinouts (PinMux)"
-    print
-    print "auto-generated by [[pinouts.py]]"
-    print
-    print "[[!toc  ]]"
-    print
-    display(pinouts)
-    print
+    of.write("""# Pinouts (PinMux)
 
-    print "# Pinouts (Fixed function)"
-    print
+auto-generated by [[pinouts.py]]
+
+[[!toc  ]]
+""")
+
+    display(of, pinouts)
+
+    of.write("\n# Pinouts (Fixed function)\n\n")
 
     fixedpins = {
         'CTRL_SYS': [
@@ -176,10 +174,11 @@ def pinspec():
 
     display_fixed(fixedpins, len(pinouts))
 
-    print "# Functions (PinMux)"
-    print
-    print "auto-generated by [[pinouts.py]]"
-    print
+    of.write("""# Functions (PinMux)
+
+auto-generated by [[pinouts.py]]
+
+""")
 
     function_names = {'EINT': 'External Interrupt',
                       'FB': 'MC68k FlexBus',
@@ -216,7 +215,7 @@ def pinspec():
                       }
 
     fns = display_fns(bankspec, pinouts, function_names)
-    print
+    of.write('\n')
 
     # Scenarios below can be spec'd out as either "find first interface"
     # by name/number e.g. SPI1, or as "find in bank/mux" which must be
@@ -241,18 +240,19 @@ def pinspec():
     unused_pins = check_functions("Robotics", bankspec, fns, pinouts,
                                   robotics, robotics_eint, robotics_pwm)
 
-    print "# Reference Datasheets"
-    print
-    print "datasheets and pinout links"
-    print
-    print "* <http://datasheets.chipdb.org/AMD/8018x/80186/amd-80186.pdf>"
-    print "* <http://hands.com/~lkcl/eoma/shenzen/frida/FRD144A2701.pdf>"
-    print "* <http://pinouts.ru/Memory/sdcard_pinout.shtml>"
-    print "* p8 <http://www.onfi.org/~/media/onfi/specs/onfi_2_0_gold.pdf?la=en>"
-    print "* <https://www.heyrick.co.uk/blog/files/datasheets/dm9000aep.pdf>"
-    print "* <http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4393.pdf>"
-    print "* <https://www.nxp.com/docs/en/data-sheet/MCF54418.pdf>"
-    print "* ULPI OTG PHY, ST <http://www.st.com/en/interfaces-and-transceivers/stulpi01a.html>"
-    print "* ULPI OTG PHY, TI TUSB1210 <http://ti.com/product/TUSB1210/>"
-
-    return pinouts, bankspec, fixedpins
+    of.write ("""# Reference Datasheets
+
+datasheets and pinout links
+* <http://datasheets.chipdb.org/AMD/8018x/80186/amd-80186.pdf>
+* <http://hands.com/~lkcl/eoma/shenzen/frida/FRD144A2701.pdf>
+* <http://pinouts.ru/Memory/sdcard_pinout.shtml>
+* p8 <http://www.onfi.org/~/media/onfi/specs/onfi_2_0_gold.pdf?la=en>
+* <https://www.heyrick.co.uk/blog/files/datasheets/dm9000aep.pdf>
+* <http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4393.pdf>
+* <https://www.nxp.com/docs/en/data-sheet/MCF54418.pdf>
+* ULPI OTG PHY, ST <http://www.st.com/en/interfaces-and-transceivers/stulpi01a.html>
+* ULPI OTG PHY, TI TUSB1210 <http://ti.com/product/TUSB1210/>
+
+""")
+
+    return pinouts, bankspec, pinbanks, fixedpins
index 6c9f563c02cc53be082e1835d6dfc1b4fc909023..cfc59a0565c88d0af0d80d5c090ebed8ac542c81 100644 (file)
@@ -16,7 +16,7 @@ def specgen(of, pth, pinouts, bankspec, pinbanks, fixedpins):
         for k in pinouts.fnspec.keys():
             s = pinouts.fnspec[k]
             f.write("%s\t%d\n" % (k.lower(), len(s)))
-            s0 = s[s.keys()[0]]  # hack, take first
+            s0 = s[list(s.keys())[0]]  # hack, take first
             with open(os.path.join(pth, '%s.txt' % k.lower()), 'w') as g:
                 if len(s0.pingroup) == 1:  # only one function, grouped higher
                     for ks in s.keys():  # grouped by interface
@@ -62,6 +62,9 @@ def specgen(of, pth, pinouts, bankspec, pinbanks, fixedpins):
     # lists bankspec, shows where the pin-numbers *start*
         of.write("# Pin Bank starting points and lengths\n\n")
     with open(os.path.join(pth, 'pinspec.txt'), 'w') as g:
-        for bank, pinstart in bankspec.items():
+        keys = list(bankspec.keys())
+        keys.sort()
+        for bank in keys:
+            pinstart = bankspec[bank]
             of.write("* %s %d %d\n" % (bank, pinstart, pinbanks[bank]))
             g.write("%s\t%d\t%d\n" % (bank, pinstart, pinbanks[bank]))
index c1891f7a8f13a6be83f47d5606d62a8ce8521380..4af0e59d6b1bcd2d3355e36f4e493a05c04eeac3 100644 (file)
@@ -65,8 +65,8 @@ def display_fns(of, bankspec, pins, function_names):
                 fns[name] = []
             fns[name].append((pin - bankspec[bank], mux, bank))
 
-    fnidx = fns.keys()
-    fnidx.sort(fnsort)
+    fnidx = list(fns.keys())
+    fnidx.sort(key=fnsplit)
     current_fn = None
     for fname in fnidx:
         fnbase = find_fn(fname, fn_names)