From 7ea566e6d29f66f74430813cb39a456745c2ff31 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Mon, 19 Oct 2015 19:15:38 -0700 Subject: [PATCH] Update generate scripts to use argparse --- rtl/axis_arb_mux.py | 72 ++++++++++------------------------- rtl/axis_arb_mux_64.py | 72 ++++++++++------------------------- rtl/axis_crosspoint.py | 72 ++++++++++------------------------- rtl/axis_crosspoint_64.py | 72 ++++++++++------------------------- rtl/axis_demux.py | 72 ++++++++++------------------------- rtl/axis_demux_64.py | 72 ++++++++++------------------------- rtl/axis_frame_join.py | 80 ++++++++++++--------------------------- rtl/axis_mux.py | 72 ++++++++++------------------------- rtl/axis_mux_64.py | 72 ++++++++++------------------------- 9 files changed, 184 insertions(+), 472 deletions(-) diff --git a/rtl/axis_arb_mux.py b/rtl/axis_arb_mux.py index 51629e20e..b138386bc 100755 --- a/rtl/axis_arb_mux.py +++ b/rtl/axis_arb_mux.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_arb_mux - +""" Generates an arbitrated AXI Stream mux with the specified number of ports - -Usage: axis_arb_mux [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_arb_mux_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream arbitrated mux {1}...".format(ports, name)) @@ -187,7 +155,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -197,5 +165,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_arb_mux_64.py b/rtl/axis_arb_mux_64.py index ae354538d..6fcb936d7 100755 --- a/rtl/axis_arb_mux_64.py +++ b/rtl/axis_arb_mux_64.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_arb_mux_64 - +""" Generates an arbitrated AXI Stream mux with the specified number of ports - -Usage: axis_arb_mux_64 [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_arb_mux_64_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream arbitrated mux {1}...".format(ports, name)) @@ -192,7 +160,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -202,5 +170,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_crosspoint.py b/rtl/axis_crosspoint.py index c3d28c607..ac193f2d0 100755 --- a/rtl/axis_crosspoint.py +++ b/rtl/axis_crosspoint.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_crosspoint - +""" Generates an AXI Stream crosspoint switch with the specified number of ports - -Usage: axis_crosspoint [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_crosspoint_{0}x{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream crosspoint {1}...".format(ports, name)) @@ -205,7 +173,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -215,5 +183,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_crosspoint_64.py b/rtl/axis_crosspoint_64.py index 537981541..bb871037b 100755 --- a/rtl/axis_crosspoint_64.py +++ b/rtl/axis_crosspoint_64.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_crosspoint_64 - +""" Generates an AXI Stream crosspoint switch with the specified number of ports - -Usage: axis_crosspoint_64 [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_crosspoint_64_{0}x{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream crosspoint {1}...".format(ports, name)) @@ -215,7 +183,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -225,5 +193,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_demux.py b/rtl/axis_demux.py index e696c4b95..8cd57b75d 100755 --- a/rtl/axis_demux.py +++ b/rtl/axis_demux.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_demux - +""" Generates an AXI Stream demux with the specified number of ports - -Usage: axis_demux [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_demux_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream demux {1}...".format(ports, name)) @@ -280,7 +248,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -290,5 +258,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_demux_64.py b/rtl/axis_demux_64.py index 984da1372..8b3271388 100755 --- a/rtl/axis_demux_64.py +++ b/rtl/axis_demux_64.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_demux_64 - +""" Generates an AXI Stream demux with the specified number of ports - -Usage: axis_demux_64 [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_demux_64_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream demux {1}...".format(ports, name)) @@ -294,7 +262,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -304,5 +272,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_frame_join.py b/rtl/axis_frame_join.py index 33252dd59..91c23bb95 100755 --- a/rtl/axis_frame_join.py +++ b/rtl/axis_frame_join.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_frame_join - +""" Generates an AXI Stream frame join module with a specific number of input ports - -Usage: axis_frame_join [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a - + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) + +def generate(ports=4, name=None, output=None): if name is None: name = "axis_frame_join_{0}".format(ports) - - if out_name is None: - out_name = name + ".v" - - print("Opening file '%s'..." % out_name) - - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + + if output is None: + output = name + ".v" + + print("Opening file '{0}'...".format(output)) + + output_file = open(output, 'w') print("Generating {0} port AXI Stream frame joiner {1}...".format(ports, name)) @@ -414,7 +382,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -424,5 +392,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_mux.py b/rtl/axis_mux.py index 8f0881593..16fc4c9f9 100755 --- a/rtl/axis_mux.py +++ b/rtl/axis_mux.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_mux - +""" Generates an AXI Stream mux with the specified number of ports - -Usage: axis_mux [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_mux_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream mux {1}...".format(ports, name)) @@ -297,7 +265,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -307,5 +275,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/rtl/axis_mux_64.py b/rtl/axis_mux_64.py index d011b6e03..cc5b5ede6 100755 --- a/rtl/axis_mux_64.py +++ b/rtl/axis_mux_64.py @@ -1,70 +1,38 @@ #!/usr/bin/env python -"""axis_mux_64 - +""" Generates an AXI Stream mux with the specified number of ports - -Usage: axis_mux_64 [OPTION]... - -?, --help display this help and exit - -p, --ports specify number of ports - -n, --name specify module name - -o, --output specify output file name """ from __future__ import print_function -import io -import sys -import getopt +import argparse import math from jinja2 import Template -class Usage(Exception): - def __init__(self, msg): - self.msg = msg +def main(): + parser = argparse.ArgumentParser(description=__doc__.strip()) + parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports") + parser.add_argument('-n', '--name', type=str, help="module name") + parser.add_argument('-o', '--output', type=str, help="output file name") + + args = parser.parse_args() -def main(argv=None): - if argv is None: - argv = sys.argv try: - try: - opts, args = getopt.getopt(argv[1:], "?n:p:o:", ["help", "name=", "ports=", "output="]) - except getopt.error as msg: - raise Usage(msg) - # more code, unchanged - except Usage as err: - print(err.msg, file=sys.stderr) - print("for help use --help", file=sys.stderr) - return 2 - - ports = 4 - name = None - out_name = None - - # process options - for o, a in opts: - if o in ('-?', '--help'): - print(__doc__) - sys.exit(0) - if o in ('-p', '--ports'): - ports = int(a) - if o in ('-n', '--name'): - name = a - if o in ('-o', '--output'): - out_name = a + generate(**args.__dict__) + except IOError as ex: + print(ex) + exit(1) +def generate(ports=4, name=None, output=None): if name is None: name = "axis_mux_64_{0}".format(ports) - if out_name is None: - out_name = name + ".v" + if output is None: + output = name + ".v" - print("Opening file '%s'..." % out_name) + print("Opening file '{0}'...".format(output)) - try: - out_file = open(out_name, 'w') - except Exception as ex: - print("Error opening \"%s\": %s" %(out_name, ex.strerror), file=sys.stderr) - exit(1) + output_file = open(output, 'w') print("Generating {0} port AXI Stream mux {1}...".format(ports, name)) @@ -313,7 +281,7 @@ endmodule """) - out_file.write(t.render( + output_file.write(t.render( n=ports, w=select_width, name=name, @@ -323,5 +291,5 @@ endmodule print("Done") if __name__ == "__main__": - sys.exit(main()) + main()