From: Luke Kenneth Casson Leighton Date: Sat, 31 Mar 2018 07:23:48 +0000 (+0100) Subject: big python3 interoperability update X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=132e433aada704244aa29e24f3b049f5e64fb5de;p=pinmux.git big python3 interoperability update --- diff --git a/src/bsv/actual_pinmux.py b/src/bsv/actual_pinmux.py index 2db4418..337bd92 100644 --- a/src/bsv/actual_pinmux.py +++ b/src/bsv/actual_pinmux.py @@ -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" + \ diff --git a/src/bsv/interface_decl.py b/src/bsv/interface_decl.py index d27b4ff..d9eed87 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -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) diff --git a/src/bsv/pinmux_generator.py b/src/bsv/pinmux_generator.py index b2b3998..3431bf1 100644 --- a/src/bsv/pinmux_generator.py +++ b/src/bsv/pinmux_generator.py @@ -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 = ''' /* diff --git a/src/parse.py b/src/parse.py index a02ff8f..02c9ea9 100644 --- a/src/parse.py +++ b/src/parse.py @@ -103,4 +103,4 @@ class Parse(object): if __name__ == '__main__': p = Parse() - print p.N_IO + print (p.N_IO) diff --git a/src/spec/__init__.py b/src/spec/__init__.py index 34f390c..383cab3 100644 --- a/src/spec/__init__.py +++ b/src/spec/__init__.py @@ -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, diff --git a/src/spec/c_class.py b/src/spec/c_class.py index 648bd30..0bc7f11 100644 --- a/src/spec/c_class.py +++ b/src/spec/c_class.py @@ -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 "* " - print "* " - print "* " - print "* p8 " - print "* " - print "* " - print "* " - print "* ULPI OTG PHY, ST " - print "* ULPI OTG PHY, TI TUSB1210 " - - return pinouts, bankspec, fixedpins + of.write ("""# Reference Datasheets + +datasheets and pinout links +* +* +* +* p8 +* +* +* +* ULPI OTG PHY, ST +* ULPI OTG PHY, TI TUSB1210 + +""") + + return pinouts, bankspec, pinbanks, fixedpins diff --git a/src/spec/gen.py b/src/spec/gen.py index 6c9f563..cfc59a0 100644 --- a/src/spec/gen.py +++ b/src/spec/gen.py @@ -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])) diff --git a/src/spec/ifaceprint.py b/src/spec/ifaceprint.py index c1891f7..4af0e59 100644 --- a/src/spec/ifaceprint.py +++ b/src/spec/ifaceprint.py @@ -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)