Add argparse.ArgumentParser based CliArguments class

This wrapper lives in a seperate module and class so that possible
processing of arguments can be done before the config dictionary
gets passed to the compiler.
This commit is contained in:
Dennis Potter 2021-05-08 11:17:56 +02:00
parent f1d9ba2656
commit ea998b7db0
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF
3 changed files with 75 additions and 8 deletions

0
srdl2sv/cli/__init__.py Normal file
View File

63
srdl2sv/cli/cli.py Normal file
View File

@ -0,0 +1,63 @@
import argparse
import os
from itertools import chain
class CliArguments():
def __init__(self):
self.parser = argparse.ArgumentParser(
description="SystemRDL 2 SystemVerilog compiler")
self.parser.add_argument(
"-v",
"--verbosity",
action="count",
help="Increase output verbosity.")
self.parser.add_argument(
"-q",
"--quiet",
action="store_true")
self.parser.add_argument(
"-o",
"--out_dir",
type=str,
help="Define output directory to dump files.\
If directory is non-existent, it will be created.")
self.parser.add_argument(
"-d",
"--search_paths",
type=str,
nargs="+",
help="Point to one (or more) directories that will\
be searched for RDL files.")
self.parser.add_argument(
"-r",
"--recursive_search",
action="store_true",
help="If set, the dependency directories will be\
searched recursively.");
self.parser.add_argument(
"IN_RDL",
type=str,
nargs="+",
help="Location of RDL file(s) with root addrmap.")
def get_config(self) -> dict():
args = self.parser.parse_args()
config = dict()
config['input_file'] = args.IN_RDL
config['verbosity'] = args.verbosity
config['quiet'] = args.quiet
if args.recursive_search:
config['search_paths'] = [x[0] for y in args.search_paths for x in os.walk(y)]
else:
config['search_paths'] = args.search_paths
return config

View File

@ -1,27 +1,31 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Standard modules
import sys import sys
import os
import re
import time import time
from systemrdl import RDLCompiler, RDLCompileError, RDLWalker, RDLListener, node # Imported modules
from systemrdl.node import FieldNode from systemrdl import RDLCompiler, RDLCompileError
# Local modules
from components.addrmap import AddrMap from components.addrmap import AddrMap
from cli.cli import CliArguments
if __name__ == "__main__": if __name__ == "__main__":
# Take start timestamp # Take start timestamp
start = time.time() start = time.time()
# Construct command line arguments
cli_arguments = CliArguments()
config = cli_arguments.get_config()
# Compile and elaborate files provided from the command line # Compile and elaborate files provided from the command line
input_files = sys.argv[1:]
rdlc = RDLCompiler() rdlc = RDLCompiler()
try: try:
for input_file in input_files: for input_file in config['input_file']:
rdlc.compile_file(input_file) rdlc.compile_file(
input_file, incl_search_paths=config['search_paths'])
root = rdlc.elaborate() root = rdlc.elaborate()
except RDLCompileError: except RDLCompileError: