utils/vlog: run make format_python Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
diff --git a/vlog_to_model.py b/vlog_to_model.py index 1ab0c91..d5d5c76 100755 --- a/vlog_to_model.py +++ b/vlog_to_model.py
@@ -25,6 +25,7 @@ from yosys.json import YosysJSON import xmlinc + def is_registered(tmod, bits, iodir, clk): """Checks if a specific i/o port is registered @@ -41,15 +42,18 @@ if tmod.cell_clk_conn(cell) != tmod.port_conns(clk): continue - if iodir == "input" and ((set(bits) & set(tmod.cell_conn_list(cell, "D"))) == set(bits)): + if iodir == "input" and ( + (set(bits) & set(tmod.cell_conn_list(cell, "D"))) == set(bits)): return True - elif iodir == "output" and ((set(bits) & set(tmod.cell_conn_list(cell, "Q"))) == set(bits)): + elif iodir == "output" and ( + (set(bits) & set(tmod.cell_conn_list(cell, "Q"))) == set(bits)): return True else: continue return is_reg + def is_registered_path(tmod, pin, pout): """Checks if a i/o path is sequential. If that is the case no combinational_sink_port is needed @@ -61,11 +65,14 @@ if ctype != "$dff": continue - if tmod.port_conns(pin) == tmod.cell_conn_list(cell, "D") and tmod.port_conns(pout) == tmod.cell_conn_list(cell, "Q"): - return True + if tmod.port_conns(pin) == tmod.cell_conn_list( + cell, "D") and tmod.port_conns(pout) == tmod.cell_conn_list( + cell, "Q"): + return True return False + parser = argparse.ArgumentParser(description=__doc__.strip()) parser.add_argument( 'infiles',
diff --git a/vlog_to_pbtype.py b/vlog_to_pbtype.py index a9b0571..5df87fc 100755 --- a/vlog_to_pbtype.py +++ b/vlog_to_pbtype.py
@@ -143,7 +143,7 @@ if '\\' in name: ts = name.find('\\') tf = name.rfind('\\') - return name[ts+1:tf] + return name[ts + 1:tf] return name @@ -170,15 +170,19 @@ d_cname = get_pin_name(dest) dir_xml = ET.SubElement(ic_xml, 'direct') - in_port_xml = ET.SubElement(dir_xml, 'port', { - 'name': s_cellpin, - 'type': "input" - }) - out_port_xml = ET.SubElement(dir_xml, 'port', { - 'name': d_cellpin, - 'type': "output", - 'from': d_cname - }) + in_port_xml = ET.SubElement( + dir_xml, 'port', { + 'name': s_cellpin, + 'type': "input" + } + ) + out_port_xml = ET.SubElement( + dir_xml, 'port', { + 'name': d_cellpin, + 'type': "output", + 'from': d_cname + } + ) # Find out whether or not the module we are generating content for is a blackbox is_blackbox = (mod.attr("blackbox", 0) == 1) or not mod.cells @@ -213,11 +217,13 @@ for pin, net in inp_cons: drvs = mod.net_drivers(net) assert len(drvs) > 0, ( - "ERROR: pin {}.{} has no driver, interconnect will be missing\n{}". - format(pb_name, pin, mod)) + "ERROR: pin {}.{} has no driver, interconnect will be missing\n{}" + .format(pb_name, pin, mod) + ) assert len(drvs) < 2, ( - "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) + ) for drv_cell, drv_pin in drvs: interconn.append(((drv_cell, drv_pin), (cname, pin))) @@ -236,13 +242,13 @@ if not drv: continue assert len(drv) == 1, ( - "ERROR: net {} has multiple drivers {}, interconnect will be over specified". - format(net, drv)) + "ERROR: net {} has multiple drivers {}, interconnect will be over specified" + .format(net, drv) + ) for snk in mod.conn_io(net, "output"): - conn = ((mod.name, drv[0]), (mod.name,snk)) + conn = ((mod.name, drv[0]), (mod.name, snk)) interconn.append(conn) - ic_xml = ET.SubElement(xml_parent, "interconnect") # Process interconnect for source, dest in interconn: @@ -387,9 +393,9 @@ return pb_type_xml - parser = argparse.ArgumentParser( - description=__doc__.strip(), formatter_class=argparse.RawTextHelpFormatter) + description=__doc__.strip(), formatter_class=argparse.RawTextHelpFormatter +) parser.add_argument( 'infiles', metavar='input.v', @@ -399,20 +405,25 @@ 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( - '--outfile', '-o', + '--outfile', + '-o', type=argparse.FileType('w'), default="pb_type.xml", help="""\ Output filename, default 'model.xml' -""") +""" +) + def main(args): iname = os.path.basename(args.infiles[0]) @@ -429,15 +440,18 @@ 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) pb_type_xml = make_pb_type(yj, tmod) - args.outfile.write(ET.tostring(pb_type_xml, pretty_print=True).decode('utf-8')) + args.outfile.write( + ET.tostring(pb_type_xml, pretty_print=True).decode('utf-8') + ) print("Generated {} from {}".format(args.outfile.name, iname)) args.outfile.close()
diff --git a/yosys/json.py b/yosys/json.py index 51bb445..9d3005d 100755 --- a/yosys/json.py +++ b/yosys/json.py
@@ -18,7 +18,8 @@ def __str__(self): return "YosysModule({},\n{})".format( - self.name, pprint.pformat(self.data)) + self.name, pprint.pformat(self.data) + ) @property def ports(self): @@ -34,7 +35,9 @@ """ plist = [] for port, pdata in sorted(self.data["ports"].items()): - plist.append((port, len(pdata["bits"]), pdata["bits"], pdata["direction"])) + plist.append( + (port, len(pdata["bits"]), pdata["bits"], pdata["direction"]) + ) return plist @property @@ -76,7 +79,9 @@ @property def nets(self): """List the net ids available in the design.""" - return list(sorted(set(n['bits'][0] for n in self.data["netnames"].values()))) + return list( + sorted(set(n['bits'][0] for n in self.data["netnames"].values())) + ) def cell_type(self, cell): """Return the type of a given cell""" @@ -326,4 +331,3 @@ src = self.module(module).attr("src") cpos = src.rfind(":") return src[0:cpos] -
diff --git a/yosys/run.py b/yosys/run.py index f8096f2..cf2e3c2 100755 --- a/yosys/run.py +++ b/yosys/run.py
@@ -144,8 +144,7 @@ p = "proc;" outfile = tempfile.mktemp() - sel_cmd = "{} cd {}; select -write {} {}".format( - p, module, outfile, expr) + sel_cmd = "{} cd {}; select -write {} {}".format(p, module, outfile, expr) commands(sel_cmd, infiles) pins = [] with open(outfile, 'r') as f: @@ -169,8 +168,9 @@ module: Name of module to run command on innet: Name of input net to find sinks of """ - return do_select(infiles, module, "{} %co* o:* %i {} %d".format( - innet, innet)) + return do_select( + infiles, module, "{} %co* o:* %i {} %d".format(innet, innet) + ) def list_clocks(infiles, module): @@ -183,7 +183,8 @@ """ return do_select( infiles, module, - "c:* %x:+[CLK]:+[clk]:+[clock]:+[CLOCK] a:CLOCK=1 %u c:* %d x:* %i") + "c:* %x:+[CLK]:+[clk]:+[clock]:+[CLOCK] a:CLOCK=1 %u c:* %d x:* %i" + ) def get_clock_assoc_signals(infiles, module, clk): @@ -197,8 +198,9 @@ """ return do_select( infiles, module, - "select -list {} %a %co* %x i:* o:* %u %i a:ASSOC_CLOCK={} %u {} %d".format( - clk, clk, clk)) + "select -list {} %a %co* %x i:* o:* %u %i a:ASSOC_CLOCK={} %u {} %d". + format(clk, clk, clk) + ) # Find things which affect the given output @@ -221,9 +223,8 @@ clk: Name of clock to find associated signals """ return do_select( - infiles, module, - "select -list w:*{} %a %co* o:* %i".format( - signal)) + infiles, module, "select -list w:*{} %a %co* o:* %i".format(signal) + ) def get_related_inputs_for_input(infiles, module, signal): @@ -235,7 +236,9 @@ module: Name of module to run command on clk: Name of clock to find associated signals """ - return [x for x in do_select( - infiles, module, - "select -list w:*{} %a %co* %x i:* %i".format( - signal)) if x != signal] + return [ + x for x in do_select( + infiles, module, + "select -list w:*{} %a %co* %x i:* %i".format(signal) + ) if x != signal + ]