Add support for special command line options in SC
Support for legacy GCC type switches like -O3, -DCFG=1
Support for +plusargs for verilog
Should now be possible to support replacing verilator with sc as is
Preprocessing sys.argv to take split arguments with no spaces before feeding to argparse
Seems to be working!
@@ -138,17 +138,17 @@ class Chip:
switchstr = self._search(self.cfg, *key, mode='get', field='switch')
#Create a map from parser args back to dictionary
+ #Special gcc/verilator compatible short switches get mapped to
+ #the key, all others get mapped to switch
+ if '_' in switchstr:
dest = switchstr.replace('-','')
- argmap[dest] = paramstr
+ else:
+ dest = key[0]
- #Mapping irregular switches(-D, +incdir, -v, -f, -O, etc to key)
if 'source' in key:
argmap['source'] = paramstr
- pass
- elif '+' in switchstr:
- #TODO: implement
- pass
elif typestr == 'bool':
+ argmap[dest] = paramstr
parser.add_argument(switchstr,
metavar='',
dest=dest,
@@ -158,6 +158,7 @@ class Chip:
default = argparse.SUPPRESS)
else:
#all the rest
+ argmap[dest] = paramstr
parser.add_argument(switchstr,
metavar='',
dest=dest,
@@ -166,8 +167,30 @@ class Chip:
default = argparse.SUPPRESS)
- # Get comman line inputs
- cmdargs = vars(parser.parse_args())
+ #Preprocess sys.argv to enable legacy GCC/SV switches with no space
+ scargs = []
+
+ for item in sys.argv:
+ #Split switches with one character and a number after (O0,O1,O2)
+ opt = re.search('(\-\w)(\d+)',item)
+ #Split assign switches (-DCFG_ASIC=1)
+ assign = re.search('(\-\w)(\w+\=\w+)',item)
+ #Split plusargs (+incdir+/path)
+ plusarg = re.search('(\+\w+\+)(.*)',item)
+ if opt:
+ scargs.append(opt.group(1))
+ scargs.append(opt.group(2))
+ elif plusarg:
+ scargs.append(plusarg.group(1))
+ scargs.append(plusarg.group(2))
+ elif assign:
+ scargs.append(assign.group(1))
+ scargs.append(assign.group(2))
+ else:
+ scargs.append(item)
+
+ #Grab argument from pre-process sysargs
+ cmdargs = vars(parser.parse_args(scargs))
#Stuff command line values into dynamic dict
for key, val in cmdargs.items():
@@ -1396,17 +1419,6 @@ class RawFormatter(HelpFormatter):
def _fill_text(self, text, width, indent):
return "\n".join([textwrap.fill(line, width) for line in textwrap.indent(textwrap.dedent(text), indent).splitlines()])
-
-class PlusargAction(argparse.Action):
- def __init__(self, option_strings, dest, nargs=None, **kwargs):
- if nargs is not None:
- raise ValueError("nargs not allowed")
- super().__init__(option_strings, dest, **kwargs)
- def __call__(self, parser, namespace, values, option_string=None):
- print('%r %r %r' % (namespace, values, option_string))
- setattr(namespace, self.dest, values)
-
-
################################################################################
def get_permutations(base_chip, cmdlinecfg):
'''Helper method to generate one or more Chip objects depending on
