apply yapf (via format-python target) to the repo Signed-off-by: Elms <elms@freshred.net>
diff --git a/vlog_to_model.py b/vlog_to_model.py index d98ff4d..78f97e3 100755 --- a/vlog_to_model.py +++ b/vlog_to_model.py
@@ -35,19 +35,22 @@ One or more Verilog input files, that will be passed to Yosys internally. They should be enough to generate a flattened representation of the model, so that paths through the model can be determined. -""") +""" +) parser.add_argument( '--top', help="""\ Top level module, will usually be automatically determined from the file name %.sim.v -""") +""" +) parser.add_argument( '--includes', help="""\ Command seperate list of include directories. """, -default="") + default="" +) parser.add_argument('-o', help="""\ Output filename, default 'model.xml' """) @@ -60,8 +63,8 @@ outfile = args.o if args.includes: - for include in args.includes.split(','): - yosys.run.add_include(include) + for include in args.includes.split(','): + yosys.run.add_include(include) aig_json = yosys.run.vlog_to_json(args.infiles, flatten=True, aig=True) @@ -109,16 +112,20 @@ module_basename = os.path.basename(abs_dep) wm = re.match(r"([A-Za-z0-9_]+)\.sim\.v", module_basename) if wm: - model_path = "{}/{}.model.xml".format(module_path, - wm.group(1).lower()) + model_path = "{}/{}.model.xml".format( + module_path, + wm.group(1).lower() + ) else: assert False, "included Verilog file name {} does not follow pattern %%.sim.v".format( - module_basename) + module_basename + ) xmlinc.include_xml( parent=models_xml, href=model_path, outfile=outfile, - xptr="xpointer(models/child::node())") + xptr="xpointer(models/child::node())" + ) else: # Is a leaf model topname = tmod.attr("MODEL_NAME", top) @@ -134,7 +141,8 @@ clk_sigs = dict() for clk in clocks: clk_sigs[clk] = yosys.run.get_clock_assoc_signals( - args.infiles, top, clk) + args.infiles, top, clk + ) for name, width, iodir in ports: attrs = dict(name=name)
diff --git a/vlog_to_pbtype.py b/vlog_to_pbtype.py index 20a91e9..ed301ba 100755 --- a/vlog_to_pbtype.py +++ b/vlog_to_pbtype.py
@@ -54,7 +54,8 @@ import xmlinc parser = argparse.ArgumentParser( - description=__doc__.strip(), formatter_class=argparse.RawTextHelpFormatter) + description=__doc__.strip(), formatter_class=argparse.RawTextHelpFormatter +) parser.add_argument( 'infiles', metavar='input.v', @@ -64,19 +65,22 @@ One or more Verilog input files, that will be passed to Yosys internally. They should be enough to generate a flattened representation of the model, so that paths through the model can be determined. -""") +""" +) parser.add_argument( '--top', help="""\ Top level module, will usually be automatically determined from the file name %.sim.v -""") +""" +) parser.add_argument( '--includes', help="""\ Command seperate list of include directories. """, -default="") + default="" +) parser.add_argument('-o', help="""\ Output filename, default 'model.xml' """) @@ -90,8 +94,8 @@ yosys.run.add_define("PB_TYPE") if args.includes: - for include in args.includes.split(','): - yosys.run.add_include(include) + for include in args.includes.split(','): + yosys.run.add_include(include) vjson = yosys.run.vlog_to_json(args.infiles, flatten=False, aig=False) yj = YosysJSON(vjson) @@ -104,8 +108,9 @@ top = wm.group(1).upper() else: print( - "ERROR file name not of format %.sim.v ({}), cannot detect top level. Manually specify the top level module using --top". - format(iname)) + "ERROR file name not of format %.sim.v ({}), cannot detect top level. Manually specify the top level module using --top" + .format(iname) + ) sys.exit(1) tmod = yj.module(top) @@ -151,11 +156,13 @@ source_pin = get_full_pin_name(source) dest_pin = get_full_pin_name(dest) ic_name = dest_pin.replace(".", "_").replace("[", "_").replace("]", "") - dir_xml = ET.SubElement(ic_xml, 'direct', { - 'name': ic_name, - 'input': source_pin, - 'output': dest_pin - }) + dir_xml = ET.SubElement( + ic_xml, 'direct', { + 'name': ic_name, + 'input': source_pin, + 'output': dest_pin + } + ) # Find out whether or not the module we are generating content for is a blackbox is_blackbox = (mod.attr("blackbox", 0) == 1) @@ -176,11 +183,13 @@ if wm: pb_type_path = "{}/{}.pb_type.xml".format( module_path, - wm.group(1).lower()) + wm.group(1).lower() + ) else: pb_type_path = "{}/pb_type.xml".format(module_path) xmlinc.include_xml( - parent=xml_parent, href=pb_type_path, outfile=outfile) + parent=xml_parent, href=pb_type_path, outfile=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 # into a top level output - or all outputs if "mode" is used. @@ -189,13 +198,15 @@ drvs = mod.net_drivers(net) if len(drvs) == 0: print( - "ERROR: pin {}.{} has no driver, interconnect will be missing". - format(pb_name, pin)) + "ERROR: pin {}.{} has no driver, interconnect will be missing" + .format(pb_name, pin) + ) assert False elif len(drvs) > 1: print( - "ERROR: pin {}.{} has multiple drivers, interconnect will be overspecified". - format(pb_name, pin)) + "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))) @@ -221,7 +232,8 @@ assert len( splitspec ) == 2, 'bad timing specification "{}", must be of format "clock value"'.format( - tmgspec) + tmgspec + ) attrs = {"port": port, "clock": splitspec[0]} if xmltype == "T_clock_to_Q": attrs["max"] = splitspec[1] @@ -248,21 +260,25 @@ # Single, constant delays inp = attr[len(dly_prefix):] inport = "{}.{}".format(mod_pname, inp) - ET.SubElement(xml_parent, "delay_constant", { - "in_port": inport, - "out_port": port, - "max": str(atvalue) - }) + ET.SubElement( + xml_parent, "delay_constant", { + "in_port": inport, + "out_port": port, + "max": str(atvalue) + } + ) elif attr.startswith(dly_mat_prefix): # Constant delay matrices inp = attr[len(dly_mat_prefix):] inport = "{}.{}".format(mod_pname, inp) mat = "\n" + atvalue.replace(";", "\n") + "\n" - xml_mat = ET.SubElement(xml_parent, "delay_matrix", { - "in_port": inport, - "out_port": port, - "type": "max" - }) + xml_mat = ET.SubElement( + xml_parent, "delay_matrix", { + "in_port": inport, + "out_port": port, + "type": "max" + } + ) xml_mat.text = mat @@ -298,13 +314,14 @@ else: 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) + pb_xml_attrs["blif_model" + ] = ".subckt " + mod.attr("MODEL_NAME", mod.name) #TODO: might not always be the case? should be use Verilog `generate`s to detect this? pb_xml_attrs["num_pb"] = "1" pb_type_xml = ET.Element( - "pb_type", pb_xml_attrs, nsmap={'xi': xmlinc.xi_url}) + "pb_type", pb_xml_attrs, nsmap={'xi': xmlinc.xi_url} + ) # Process IOs clocks = yosys.run.list_clocks(args.infiles, mod.name) @@ -333,7 +350,9 @@ flatten=False, aig=False, mode=smode, - module_with_mode=mod.name)) + 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/yosys/json.py b/yosys/json.py index ef2bc92..0fe8622 100755 --- a/yosys/json.py +++ b/yosys/json.py
@@ -136,8 +136,9 @@ if len(pdata["bits"]) == 1: conn_io.append(port) else: - conn_io.append("{}[{}]".format( - port, pdata["bits"].index(net))) + conn_io.append( + "{}[{}]".format(port, pdata["bits"].index(net)) + ) return conn_io def conn_ports(self, net, pdir): @@ -159,8 +160,12 @@ if len(condata) == 1: conn_ports.append((cell, port)) else: - conn_ports.append((cell, "{}[{}]".format( - port, condata.index(net)))) + conn_ports.append( + ( + cell, + "{}[{}]".format(port, condata.index(net)) + ) + ) return conn_ports def net_drivers(self, net): @@ -215,8 +220,11 @@ def module(self, module): """Get a given module (by name) as a `YosysModule`""" if module not in self.data["modules"]: - raise KeyError("No yosys module named {} (only have {})".format( - module, self.data["modules"].keys())) + raise KeyError( + "No yosys module named {} (only have {})".format( + module, self.data["modules"].keys() + ) + ) return YosysModule(module, self.data["modules"][module]) def modules_with_attr(self, attr_name, attr_value):
diff --git a/yosys/run.py b/yosys/run.py index 9393425..1f19b1e 100755 --- a/yosys/run.py +++ b/yosys/run.py
@@ -34,6 +34,7 @@ """ Add a path to search when reading verilog to the list of includes set in Yosys""" includes.append(path) + def get_includes(): """Return a list of include directories, as a list of arguments to pass to Yosys `read_verilog`""" return " ".join(["-I" + _ for _ in includes]) @@ -47,8 +48,9 @@ commands : string of Yosys commands to run infiles : list of input files """ - commands = "read_verilog {} {} {}; ".format(get_defines(), get_includes(), - " ".join(infiles)) + commands + commands = "read_verilog {} {} {}; ".format( + get_defines(), get_includes(), " ".join(infiles) + ) + commands params = ["-q", "-p", commands] return get_output(params) @@ -65,11 +67,9 @@ return get_output(params) -def vlog_to_json(infiles, - flatten=False, - aig=False, - mode=None, - module_with_mode=None): +def vlog_to_json( + infiles, flatten=False, aig=False, mode=None, module_with_mode=None +): """ Convert Verilog to a JSON representation using Yosys @@ -129,7 +129,8 @@ outfile = tempfile.mktemp() sel_cmd = "prep -top {} -flatten; cd {}; select -write {} {}".format( - module, module, outfile, expr) + module, module, outfile, expr + ) commands(sel_cmd, infiles) pins = [] with open(outfile, 'r') as f: @@ -153,8 +154,9 @@ module: Name of module to run command on innet: Name of input net to find sinks of """ - return do_select(infiles, module, "{} %coe* o:* %i {} %d".format( - innet, innet)) + return do_select( + infiles, module, "{} %coe* o:* %i {} %d".format(innet, innet) + ) def list_clocks(infiles, module): @@ -180,4 +182,6 @@ return do_select( infiles, module, "select -list {} %x* i:* o:* %u %i a:ASSOC_CLOCK={} %u {} %d".format( - clk, clk, clk)) + clk, clk, clk + ) + )