utils/vlog: Python style improvements

Signed-off-by: David Shah <davey1576@gmail.com>
diff --git a/vlog_to_model.py b/vlog_to_model.py
index daf750a..b2353fa 100755
--- a/vlog_to_model.py
+++ b/vlog_to_model.py
@@ -53,7 +53,7 @@
 if "o" in args and args.o is not None:
     outfile = args.o
 
-aig_json = yosys.run.vlog_to_json(args.infiles, True, True)
+aig_json = yosys.run.vlog_to_json(args.infiles, flatten=True, aig=True)
 
 if args.top is not None:
     yj = YosysJSON(aig_json, args.top)
@@ -71,8 +71,6 @@
     print("ERROR: more than one module in design, cannot detect top level. Manually specify the top level module using --top")
     sys.exit(1)
 
-ET.register_namespace('xi', xmlinc.xi_url)
-
 tmod = yj.top_module
 models_xml = ET.Element("models", nsmap = {'xi': xmlinc.xi_url})
 
@@ -97,9 +95,9 @@
         module_basename = os.path.basename(abs_dep)
         wm = re.match(r"([A-Za-z0-9_]+)\.sim\.v", module_basename)
         if wm:
-            model_path = "%s/%s.model.xml" % (module_path, wm.group(1).lower())
+            model_path = "{}/{}.model.xml" .format(module_path, wm.group(1).lower())
         else:
-            assert False, "included Verilog file name %s does not follow pattern %%.sim.v" % module_basename
+            assert False, "included Verilog file name {} does not follow pattern %%.sim.v".format(module_basename)
         xmlinc.include_xml(models_xml, model_path, outfile, "xpointer(models/child::node())")
 else:
     # Is a leaf model
diff --git a/vlog_to_pbtype.py b/vlog_to_pbtype.py
index ebeb49d..6d8006e 100755
--- a/vlog_to_pbtype.py
+++ b/vlog_to_pbtype.py
@@ -13,7 +13,7 @@
     - `(* CLASS="lut|routing|mux|flipflop|mem" *)` : specify the class of an given
     instance.
 
-    - `(* MODES="mode1, mode2, ..." *)` : specify that the module has more than one functional
+    - `(* MODES="mode1; mode2; ..." *)` : specify that the module has more than one functional
     mode, each with a given name. The module will be evaluated n times, each time setting
     the MODE parameter to the nth value in the list of mode names. Each evaluation will be
     put in a pb_type `<mode>` section named accordingly.
@@ -83,10 +83,9 @@
     outfile = args.o
 
 yosys.run.add_define("PB_TYPE")
-vjson = yosys.run.vlog_to_json(args.infiles, False, False)
+vjson = yosys.run.vlog_to_json(args.infiles, flatten=False, aig=False)
 yj = YosysJSON(vjson)
 
-ET.register_namespace('xi', xmlinc.xi_url)
 
 if args.top is not None:
     top = args.top
@@ -164,9 +163,9 @@
             # Heuristic for autogenerated files from w.py
             wm = re.match(r"([A-Za-z0-9_]+)\.sim\.v", module_basename)
             if wm:
-                pb_type_path = "%s/%s.pb_type.xml" % (module_path, wm.group(1).lower())
+                pb_type_path = "{}/{}.pb_type.xml".format(module_path, wm.group(1).lower())
             else:
-                pb_type_path = "%s/pb_type.xml" % module_path
+                pb_type_path = "{}/pb_type.xml".format(module_path)
             xmlinc.include_xml(xml_parent, pb_type_path, outfile)
             # In order to avoid overspecifying interconnect, there are two directions we currently
             # consider. All interconnect going INTO a cell, and interconnect going out of a cell
@@ -175,10 +174,10 @@
             for pin, net in inp_cons:
                 drvs = mod.net_drivers(net)
                 if len(drvs) == 0:
-                    print("ERROR: pin %s.%s has no driver, interconnect will be missing" % (pb_name, pin))
+                    print("ERROR: pin {}.{} has no driver, interconnect will be missing".format(pb_name, pin))
                     assert False
                 elif len(drvs) > 1:
-                    print("ERROR: pin %s.%s has multiple drivers, interconnect will be overspecified" % (pb_name, pin))
+                    print("ERROR: pin {}.{} has multiple drivers, interconnect will be overspecified".format(pb_name, pin))
                     assert False
                 for drv_cell, drv_pin in drvs:
                     interconn.append(((drv_cell, drv_pin), (cname, pin)))
@@ -211,7 +210,7 @@
 
     # Process timing
     for name, width, iodir in mod.ports:
-        port = "%s.%s" % (mod_pname, name)
+        port = "{}.{}".format(mod_pname, name)
         # Clocked timing
         Tsetup = mod.net_attr(name, "SETUP")
         Thold = mod.net_attr(name, "HOLD")
@@ -227,7 +226,7 @@
             if attr.startswith(dly_prefix):
                 # Single, constant delays
                 inp = attr[len(dly_prefix):]
-                inport = "%s.%s" % (mod_pname, inp)
+                inport = "{}.{}".format(mod_pname, inp)
                 ET.SubElement(xml_parent, "delay_constant", {
                     "in_port": inport,
                     "out_port": port,
@@ -236,7 +235,7 @@
             elif attr.startswith(dly_mat_prefix):
                 # Constant delay matrices
                 inp = attr[len(dly_mat_prefix):]
-                inport = "%s.%s" % (mod_pname, inp)
+                inport = "{}.{}".format(mod_pname, inp)
                 mat = "\n" + atvalue.replace(";", "\n") + "\n"
                 xml_mat = ET.SubElement(xml_parent, "delay_matrix", {
                     "in_port": inport,
@@ -252,7 +251,7 @@
     attrs = mod.module_attrs
     modes = mod.attr("MODES", None)
     if modes is not None:
-        modes = modes.split(",")
+        modes = modes.split(";")
     mod_pname = mod_pb_name(mod)
 
     pb_xml_attrs = dict()
@@ -276,7 +275,7 @@
             pb_xml_attrs["blif_model"] = ".latch"
             pb_xml_attrs["class"] = "flipflop"
         else:
-            assert False, "unknown class %s" % mod_cls
+            assert False, "unknown class {}".format(mod_cls)
     elif is_blackbox and not has_modes:
         pb_xml_attrs["blif_model"] = ".subckt " + mod.attr("MODEL_NAME", mod.name)
 
@@ -305,7 +304,7 @@
             smode = mode.strip()
             mode_xml = ET.SubElement(pb_type_xml, "mode", {"name" : smode})
             # Rerun Yosys with mode parameter
-            mode_yj = YosysJSON(yosys.run.vlog_to_json(args.infiles, False, False, smode, mod.name))
+            mode_yj = YosysJSON(yosys.run.vlog_to_json(args.infiles, flatten=False, aig=False, mode=smode, module_with_mode=mod.name))
             mode_mod = mode_yj.module(mod.name)
             make_pb_content(mode_mod, mode_xml, mod_pname, True)
     else:
diff --git a/xmlinc.py b/xmlinc.py
index b7f470b..55dbe5f 100644
--- a/xmlinc.py
+++ b/xmlinc.py
@@ -5,6 +5,8 @@
 
 xi_include = "{%s}include" % xi_url
 
+ET.register_namespace('xi', xi_url)
+
 def make_relhref(outfile, href):
     outpath = os.path.dirname(os.path.abspath(outfile))
     relpath = os.path.relpath(os.path.dirname(os.path.abspath(href)), outpath)
diff --git a/yosys/json.py b/yosys/json.py
index 24cac80..5d34074 100755
--- a/yosys/json.py
+++ b/yosys/json.py
@@ -118,7 +118,7 @@
                     conns.append((port, condata[0]))
                 else:
                     for i in range(N):
-                        conns.append(("%s[%d]" % (port, i), condata[i]))
+                        conns.append(("{}[{}]".format(port, i), condata[i]))
         return conns
 
     def conn_io(self, net, iodir):
@@ -135,7 +135,7 @@
                     if len(pdata["bits"]) == 1:
                         conn_io.append(port)
                     else:
-                        conn_io.append("%s[%d]" % (port, pdata["bits"].index(net)))
+                        conn_io.append("{}[{}]".format(port, pdata["bits"].index(net)))
         return conn_io
 
     def conn_ports(self, net, pdir):
@@ -157,7 +157,7 @@
                         if len(condata) == 1:
                             conn_ports.append((cell, port))
                         else:
-                            conn_ports.append((cell, "%s[%d]" % (port, condata.index(net))))
+                            conn_ports.append((cell, "{}[{}]".format(port, condata.index(net))))
         return conn_ports
 
 
diff --git a/yosys/run.py b/yosys/run.py
index 0b475ea..4626e38 100755
--- a/yosys/run.py
+++ b/yosys/run.py
@@ -31,7 +31,7 @@
     commands : string of Yosys commands to run
     infiles : list of input files
     """
-    commands = "read_verilog %s %s; " % (get_defines(), " ".join(infiles)) + commands
+    commands = "read_verilog {} {}; ".format(get_defines(), " ".join(infiles)) + commands
     params = ["-q", "-p", commands]
     return get_output(params)
 
@@ -46,7 +46,7 @@
     params = ["-q", "-s", script] + infiles
     return get_output(params)
 
-def vlog_to_json(infiles, flatten = False, aig = False, mode = None, mode_mod = None):
+def vlog_to_json(infiles, flatten = False, aig = False, mode = None, module_with_mode = None):
     """
     Convert Verilog to a JSON representation using Yosys
 
@@ -61,10 +61,10 @@
     prep_opts = "-flatten" if flatten else ""
     json_opts = "-aig" if aig else ""
     if mode is not None:
-        mode_str = 'chparam -set MODE "%s" %s; ' % (mode, mode_mod)
+        mode_str = 'chparam -set MODE "{}" {}; '.format(mode, module_with_mode)
     else:
         mode_str = ""
-    cmds = "%sprep %s; write_json %s" % (mode_str, prep_opts, json_opts)
+    cmds = "{}prep {}; write_json {}".format(mode_str, prep_opts, json_opts)
     j = yosys.utils.strip_yosys_json(commands(cmds, infiles))
     """with open('dump.json', 'w') as dbg:
         print(j,file=dbg)"""
@@ -108,7 +108,7 @@
 
 
     outfile = tempfile.mktemp()
-    sel_cmd = "prep -top %s -flatten; cd %s; select -write %s %s" % (module, module, outfile, expr)
+    sel_cmd = "prep -top {} -flatten; cd {}; select -write {} {}" .format(module, module, outfile, expr)
     commands(sel_cmd, infiles)
     pins = []
     with open(outfile, 'r') as f:
@@ -131,7 +131,7 @@
     module: Name of module to run command on
     innet: Name of input net to find sinks of
     """
-    return do_select(infiles, module, "%s %%coe* o:* %%i %s %%d" % (innet, innet))
+    return do_select(infiles, module, "{} %coe* o:* %i {} %d".format(innet, innet))
 
 def list_clocks(infiles, module):
     """Return a list of clocks in the module
@@ -152,4 +152,4 @@
     module: Name of module to run command on
     clk: Name of clock to find associated signals
     """
-    return do_select(infiles, module, "select -list %s %%x* i:* o:* %%u %%i a:ASSOC_CLOCK=%s %%u %s %%d" % (clk, clk, clk))
+    return do_select(infiles, module, "select -list {} %x* i:* o:* %u %i a:ASSOC_CLOCK={} %u {} %d".format(clk, clk, clk))