From 1ed119c8ac61bf3dec66f3a9062aa21d272eb465 Mon Sep 17 00:00:00 2001 From: Erik Kooistra <kooistra@astron.nl> Date: Thu, 21 Apr 2016 13:30:23 +0000 Subject: [PATCH] Use class Hdl_args to parse command line arguments for HDL library usage. --- tools/oneclick/base/hdl_config.py | 57 ++++++++++++++------------ tools/oneclick/base/modelsim_config.py | 29 ++++--------- tools/oneclick/base/quartus_config.py | 28 +++---------- 3 files changed, 43 insertions(+), 71 deletions(-) diff --git a/tools/oneclick/base/hdl_config.py b/tools/oneclick/base/hdl_config.py index fa984a4856..7ca1ccf064 100644 --- a/tools/oneclick/base/hdl_config.py +++ b/tools/oneclick/base/hdl_config.py @@ -67,6 +67,10 @@ class HdlConfig: The libRootDir parameter is defined in the hdltool_<toolset>.cfg file and is the root directory from where the hdllib.cfg files are searched for. + In parallel to the self.libs.dicts list of dictionaries a list of self.lib_names is created to be able to identify + a HDL library dict also by its library name. Iherefore it is important that the indexing of parallel lists remains + intact at all times. + The technologyNames parameter is defined in the hdltool_<toolset>.cfg file. All generic HDL libraries and these technology specific libraries are kept. If technologyNames is: [] : Keep all HDL libraries that were found. @@ -326,7 +330,29 @@ class HdlConfig: else: copy_tree(sourcePathName, destinationPath) # copy directory tree (will create new destinationPath directory) + +class Hdl_args: + """ Parse command line arguments + """ + def __init__(self, toolsetSelect): + # Parse command line arguments + argparser = argparse.ArgumentParser(description='HDL config command line parser arguments') + argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False) + argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False) + args = vars(argparser.parse_args()) + + # Keep arguments in class record + self.toolset = args['toolset'] + + if self.toolset not in toolsetSelect: + print 'Toolset %s is not supported' % self.toolset + print 'Hint: give argument -h for possible options' + sys.exit(1) + self.toolFileName = 'hdltool_' + self.toolset + '.cfg' + self.verbosity = args['verbosity'] + + if __name__ == '__main__': # Mode # 0 = Read dictionary info from all HDL tool and library configuration files and derive the compile order @@ -338,25 +364,12 @@ if __name__ == '__main__': mode = 0 # Parse command line arguments - toolsetSelect = ['unb1', 'unb2', 'unb2a'] - - argparser = argparse.ArgumentParser(description='Derive HDL library dictionary from hdllib.cfg') - argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False) - argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False) - args = vars(argparser.parse_args()) - - arg_toolset = args['toolset'] - if arg_toolset not in toolsetSelect: - print 'Toolset %s is not supported' % arg_toolset - print 'Hint: give argument -h for possible options' - sys.exit(1) - arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg' - - arg_verbosity = args['verbosity'] + hdl_args = Hdl_args(toolsetSelect=['unb1', 'unb2', 'unb2a']) + + # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories + hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=hdl_args.toolFileName) if mode==0: - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) print '#' print '# HdlConfig:' print '#' @@ -422,8 +435,6 @@ if __name__ == '__main__': if mode==1: key = 'build_dir' new_value = '$HDL_BUILD_DIR' - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) for p in hdl.libs.filePathNames: hdl.libs.change_key_value_in_dict_file(p, key, new_value) @@ -431,8 +442,6 @@ if __name__ == '__main__': insert_key = 'hdl_lib_technology' insert_value = '' insertLineNr = 4 - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) for p in hdl.libs.filePathNames: hdl.libs.insert_key_in_dict_file_at_line_number(p, insert_key, insert_value, insertLineNr) @@ -440,22 +449,16 @@ if __name__ == '__main__': insert_key = '[quartus_project_file]' insert_value = '\n' insert_beforeKey = 'synth_files' - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) for p in hdl.libs.filePathNames: hdl.libs.insert_key_in_dict_file_before_another_key(p, insert_key, insert_value, insert_beforeKey) if mode==4: old_key = 'hdl_lib_uses' new_key = 'hdl_lib_uses_synth' - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) for p in hdl.libs.filePathNames: hdl.libs.rename_key_in_dict_file(p, old_key, new_key) if mode==5: remove_key = 'modelsim_search_libraries' - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) for p in hdl.libs.filePathNames: hdl.libs.remove_key_from_dict_file(p, remove_key) diff --git a/tools/oneclick/base/modelsim_config.py b/tools/oneclick/base/modelsim_config.py index f18c830308..760db671ec 100755 --- a/tools/oneclick/base/modelsim_config.py +++ b/tools/oneclick/base/modelsim_config.py @@ -309,29 +309,14 @@ if __name__ == '__main__': mode = 0 # Parse command line arguments - toolsetSelect = ['unb1', 'unb2', 'unb2a'] - - argparser = argparse.ArgumentParser(description='Create Modelsim mpf files for all hdllib.cfg') - argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False) - argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False) - args = vars(argparser.parse_args()) - - arg_toolset = args['toolset'] - if arg_toolset not in toolsetSelect: - print 'Toolset %s is not supported' % arg_toolset - print 'Hint: give argument -h for possible options' - sys.exit(1) - arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg' - - arg_verbosity = args['verbosity'] + hdl_args = hdl_config.Hdl_args(toolsetSelect=['unb1', 'unb2', 'unb2a']) + + # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories + msim = ModelsimConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=hdl_args.toolFileName) if mode==0: # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - - # Create and use msim object - msim = ModelsimConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) - - if arg_verbosity>=2: + if hdl_args.verbosity>=2: print '#' print '# ModelsimConfig:' print '#' @@ -340,11 +325,11 @@ if __name__ == '__main__': for p in msim.libs.filePaths: print ' ', p - if arg_verbosity>=1: + if hdl_args.verbosity>=1: print '' print 'Derive library compile order = ', msim.derive_lib_order('sim') - if arg_verbosity>=2: + if hdl_args.verbosity>=2: print '' print 'get_lib_build_dirs for simulation:' for sim_dir in msim.get_lib_build_dirs('sim'): diff --git a/tools/oneclick/base/quartus_config.py b/tools/oneclick/base/quartus_config.py index 8a42c42744..cd98c80f56 100755 --- a/tools/oneclick/base/quartus_config.py +++ b/tools/oneclick/base/quartus_config.py @@ -228,29 +228,13 @@ class QuartusConfig(hdl_config.HdlConfig): if __name__ == '__main__': - # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories - # Parse command line arguments - toolsetSelect = ['unb1', 'unb2', 'unb2a'] - - argparser = argparse.ArgumentParser(description='Create Quartus project files for hdllib.cfg') - argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False) - argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False) - args = vars(argparser.parse_args()) - - arg_toolset = args['toolset'] - if arg_toolset not in toolsetSelect: - print 'Toolset %s is not supported' % arg_toolset - print 'Hint: give argument -h for possible options' - sys.exit(1) - arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg' - - arg_verbosity = args['verbosity'] - - # Create and use qsyn object - qsyn = QuartusConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName) + hdl_args = hdl_config.Hdl_args(toolsetSelect=['unb1', 'unb2', 'unb2a']) + + # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories + qsyn = QuartusConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=hdl_args.toolFileName) - if arg_verbosity>=2: + if hdl_args.verbosity>=2: print '#' print '# QuartusConfig:' print '#' @@ -259,7 +243,7 @@ if __name__ == '__main__': for p in qsyn.libs.filePaths: print ' ', p - if arg_verbosity>=1: + if hdl_args.verbosity>=1: print '' print 'HDL libraries with a top level entity for synthesis that are found in $%s:' % qsyn.libRootDir print ' %-40s' % 'HDL library', ': Top level entity' -- GitLab