Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zhajio1988 committed Mar 11, 2019
1 parent dabfec0 commit a5af3a2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 30 deletions.
10 changes: 5 additions & 5 deletions bin/build.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ compile_option = +define+UVM_REG_BYTE_ADDRESSING_FIX
sim_option = -assert quiet
sim_option = +WORK_MODE=RTL_ONLY
sim_option = "+uvm_set_action=*,UVM/COMP/NAME,UVM_WARNING,UVM_NO_ACTION +uvm_set_action=*,UVM/RSRC/NOREGEX,UVM_WARNING,UVM_NO_ACTION"
#pre_compile_option = $PRJ_HOME/bin/pre_compile.csh
#post_compile_option = $PRJ_HOME/bin/post_compile.csh
#pre_sim_option = $PRJ HOME/bin/pre_sim.csh
#post_sim_option = $PRJ HOME/bin/post_sim.csh
pre_compile_option = $PRJ_HOME/bin/pre_compile.csh
post_compile_option = $PRJ_HOME/bin/post_compile.csh
pre_sim_option = $PRJ HOME/bin/pre_sim.csh
post_sim_option = $PRJ HOME/bin/post_sim.csh

[[dla_fpga]]
[[dla_regr]]
compile_option = -timescale=lns/l0ps
compile_option = -cpp ${GCC_HOME}/${GCC_VERSION}/bin/g++
compile_option = -cc ${GCC_HOME}/${GCC_VERSION}/bin/gcc
Expand Down
2 changes: 1 addition & 1 deletion globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def defaultReportDir():
else:
return os.path.join(defaultWorkPrjDir(), 'report')

def defaultWorkPrjDir():
def defaultWorkDir():
# if os.environ['USER'] in grp.getgrnam('sg-ic-ipdv').gr_mem:
# return os.path.join('/ic/temp/ipdv', os.environ['USER'], os.path.basename(os.environ['PRJ_HOME']))
# elif os.environ['USER'] in grp.getgrnam('sg-ic-soc').gr_mem:
Expand Down
16 changes: 10 additions & 6 deletions readCfgFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ def build(self):
if 'build' in self.subSection:
return self.subSection['build']

def getBuild(self, build=''):
return self.build.getBuild(build)


def compileOption(self, buildName):
return self.build.getBuild(buildName).compileOption + self.build.compileOption if self.build.compileOption else self.build.getBuild(buildName).compileOption
return self.getBuild(buildName).compileOption + self.build.compileOption if self.build.compileOption else self.getBuild(buildName).compileOption

def simOption(self, buildName):
return self.build.getBuild(buildName).simOption + self.build.simOption if self.build.simOption else self.build.getBuild(buildName).simOption
return self.getBuild(buildName).simOption + self.build.simOption if self.build.simOption else self.getBuild(buildName).simOption

def preCompileOption(self, buildName):
return self._toList(self.build.getBuild(buildName).preCompileOption) + self._toList(self.build.preCompileOption)
return self._toList(self.getBuild(buildName).preCompileOption) + self._toList(self.build.preCompileOption)

def preSimOption(self, buildName):
return self._toList(self.build.getBuild(buildName).preSimOption) + self._toList(self.build.preSimOption)
return self._toList(self.getBuild(buildName).preSimOption) + self._toList(self.build.preSimOption)

def postCompileOption(self, buildName):
return self._toList(self.build.getBuild(buildName).postCompileOption) + self._toList(self.build.postCompileOption)
return self._toList(self.getBuild(buildName).postCompileOption) + self._toList(self.build.postCompileOption)

def postSimOption(self, buildName):
return self._toList(self.build.getBuild(buildName).postSimOption) + self._toList(self.build.postSimOption)
return self._toList(self.getBuild(buildName).postSimOption) + self._toList(self.build.postSimOption)

def _toList(self, preOptions):
if isinstance(preOptions, str):
Expand Down
20 changes: 13 additions & 7 deletions userCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class userCliCfg(object):
def __init__(self, parser=None, ini_file=None):
self.parser = parser
self.kwargs = {}
self.args = []
self.args = None
self.config = ConfigObj(infile=defaultCliCfgFile(), stringify=True)
self.section = self.userCliSection

Expand All @@ -18,7 +18,11 @@ def userCliSection(self):
else:
raise AttributeError('userCli section is not defined in %s' % defaultCliCfgFile())

def compileOption(self, args):
def setParsedArgs(self, parsedArgs):
self.args = parsedArgs

def compileOption(self):
args = self.args;
argsList = []
keyVar = ''
for key in self.section:
Expand All @@ -28,10 +32,11 @@ def compileOption(self, args):
if '$' in v:
v = v.replace(key, getattr(args, keyVar))
if 'compile_option' == k:
argsList = argsList + v if isinstance(v, list) else [v]
argsList = argsList + v if isinstance(v, list) else argsList + [v]
return argsList

def simOption(self, args):
def simOption(self):
args = self.args;
argsList = []
keyVar = ''
for key in self.section:
Expand All @@ -41,7 +46,7 @@ def simOption(self, args):
if '$' in v:
v = v.replace(key, getattr(args, keyVar))
if 'sim_option' == k:
argsList = argsList + v if isinstance(v, list) else [v]
argsList = argsList + v if isinstance(v, list) else argsList + [v]
return argsList

def addArguments(self):
Expand Down Expand Up @@ -75,10 +80,11 @@ def addArguments(self):
userCliCfg = userCliCfg(parser)
userCliCfg.addArguments()
args = parser.parse_args(sys.argv[1:])
userCliCfg.setParsedArgs(args)
print(args)
print(args.prof)
print(args.vh)
print(args.wave_name)
print(userCliCfg.compileOption(args))
print(userCliCfg.simOption(args))
print(userCliCfg.compileOption())
print(userCliCfg.simOption())
#print(args.sim_option)
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'''

def createDir(path, force = False):
if force:
if force and os.path.exists(path):
shutil.rmtree(path, True)
if not os.path.exists(path):
os.makedirs(path)
Expand Down
36 changes: 26 additions & 10 deletions yasaCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ def __init__(self, description=None):
"""
:param description: A custom short description of the command line tool
"""
self.parsedArgs = None
self.parser = _create_argument_parser(description)
self.userCliCfg = userCli.userCliCfg(self.parser)
self.userCliCfg.addArguments()
def parse_args(self, argv=None):

def parseArgs(self, argv=None):
"""
Parse command line arguments
:param argv: Use explicit argv instead of actual command line argument
:returns: The parsed argument namespace object
"""
return self.parser.parse_args(args=argv)
self.parsedArgs = self.parser.parse_args(args=argv)
self.userCliCfg.setParsedArgs(self.parsedArgs)
#return args

def getParsedArgs(self):
return self.parsedArgs

def userCliCompileOption(self):
return self.userCliCfg.compileOption()

def userCliSimOption(self):
return self.userCliCfg.simOption()

def _create_argument_parser(description=None, for_documentation=False):
"""
Expand Down Expand Up @@ -123,9 +135,9 @@ def _create_argument_parser(description=None, for_documentation=False):
help=('Number of tests to run in parallel. '
'Test output is not continuously written in verbose mode with p > 1'))

argParser.add_argument("-u", "-unique-sim",
argParser.add_argument("-u", "-unique_sim",
action="store_true",
default=False,
dest='unique_sim',
help="Do not re-use the same simulator process for running different test cases (slower)")

argParser.add_argument("-export-json",
Expand Down Expand Up @@ -159,13 +171,17 @@ def _argParser_for_documentation():
import sys

cli = yasaCli("Yet another simulation architecture top scripts")
#print(cli.parse_args(sys.argv[1:]))
#print(vars(cli.parse_args(sys.argv[1:])))
#print(cli.parse_args(['-h']))
args = cli.parse_args(sys.argv[1:])
#print(cli.parseArgs(sys.argv[1:]))
#print(vars(cli.parseArgs(sys.argv[1:])))
#print(cli.parseArgs(['-h']))
cli.parseArgs(sys.argv[1:])
args = cli.getParsedArgs()
print(args.sim_option)
print(args.wave_name)
print(args.prof)
print(cli.userCliCfg.compileOption(args))
print(cli.userCliCfg.simOption(args))
print(cli.userCliCfg.compileOption())
print(cli.userCliCfg.simOption())
print(cli.userCliCompileOption())
print(cli.userCliSimOption())

print("end")

0 comments on commit a5af3a2

Please sign in to comment.