3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-04-05 14:04:07 +00:00

sby: core: fixed up the [setup] section

This commit is contained in:
Aki Van Ness 2022-08-04 07:05:32 -04:00
parent 6c959577f3
commit 98fdcd7772
No known key found for this signature in database
GPG key ID: C629E8EC06327BEE

View file

@ -320,6 +320,8 @@ class SbyConfig:
if args is not None: if args is not None:
self.error(f"sby file syntax error: '[setup]' section does not accept any arguments. got {args}") self.error(f"sby file syntax error: '[setup]' section does not accept any arguments. got {args}")
continue
# [stage <NAME> (PARENTS,...)] # [stage <NAME> (PARENTS,...)]
if section == "stage": if section == "stage":
mode = "stage" mode = "stage"
@ -404,24 +406,40 @@ class SbyConfig:
continue continue
if mode == "setup": if mode == "setup":
kvp = line.split() _valid_options = (
if kvp[0] not in ("cutpoint", "disable", "enable", "assume", "define"): "cutpoint", "disable", "enable", "assume", "define"
self.error(f"sby file syntax error: found '{kvp[0]}' but expected one of 'cutpoint', 'disable', 'enable', 'assume', or 'define'") )
args = line.strip().split(maxsplit = 1)
if args is None:
self.error(f"sby file syntax error: unknown key in '[setup]' section")
if len(args) < 2:
self.error(f"sby file syntax error: entry in '[setup]' must have an argument, got {' '.join(args)}")
if args[0] not in _valid_options:
self.error(f"sby file syntax error: expected on of '{', '.join(_valid_options)}' in '[setup]' section, got '{args[0]}'")
else: else:
stmt = kvp[0] opt_key = args[0]
if stmt == 'define': opt_args = args[1].strip().split()
if opt_key == 'define':
if 'define' not in self.setup: if 'define' not in self.setup:
self.setup['define'] = {} self.setup['define'] = {}
if len(kvp[1:]) < 2: if len(opt_args) != 2:
self.error(f"sby file syntax error: 'define' statement takes 2 arguments, got {len(kvp[1:])}") self.error(f"sby file syntax error: 'define' statement in '[setup]' section takes exactly 2 arguments, got {len(opt_args)}")
elif kvp[1][0] != '@':
self.error(f"sby file syntax error: 'define' statement expects an '@' prefixed name as the first parameter, got {line}") if opt_args[0][0] != '@':
else: self.error(f"sby file syntax error: 'define' statement in '[setup]' section expects an '@' prefixed name as the first parameter, got {opt_args[0]}")
name = kvp[1][1:]
self.setup['define'][name] = kvp[2:] name = opt_args[0][1:]
self.setup['define'][name] = opt_args[2:]
else: else:
self.setup[stmt] = kvp[1:] self.setup[opt_key] = opt_args[1:]
continue continue
if mode == "stage": if mode == "stage":
@ -453,11 +471,18 @@ class SbyConfig:
self.error(f"sby file syntax error: 'setsel' statement in '[stage]' section expects an '@' prefixed name as the first parameter, got {opt_args[0]}") self.error(f"sby file syntax error: 'setsel' statement in '[stage]' section expects an '@' prefixed name as the first parameter, got {opt_args[0]}")
name = opt_args[0][1:] name = opt_args[0][1:]
if stage_name not in self.stage:
self.stage[stage_name] = dict()
self.stage[stage_name][opt_key] = { self.stage[stage_name][opt_key] = {
'name': name, 'pattern': opt_args[2:] 'name': name, 'pattern': opt_args[2:]
} }
else: else:
if stage_name not in self.stage:
self.stage[stage_name] = dict()
self.stage[stage_name][opt_key] = opt_args[1:] self.stage[stage_name][opt_key] = opt_args[1:]
continue continue
@ -483,6 +508,9 @@ class SbyConfig:
self.error(f"sby file syntax error: In an incomprehensible mode '{mode}'") self.error(f"sby file syntax error: In an incomprehensible mode '{mode}'")
if len(self.stage.keys()) == 0:
self.stage['default'] = { 'enable': '*' }
def error(self, logmessage): def error(self, logmessage):
raise SbyAbort(logmessage) raise SbyAbort(logmessage)