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

Add tasks in .sby files

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-03-05 13:09:20 +01:00
parent a94f21abab
commit 92b247260a
2 changed files with 69 additions and 7 deletions

View file

@ -23,6 +23,7 @@ from sby_core import SbyJob
sbyfile = None
workdir = None
taskname = None
opt_force = False
opt_backup = False
opt_tmpdir = False
@ -30,7 +31,7 @@ exe_paths = dict()
def usage():
print("""
sby [options] [<jobname>.sby]
sby [options] [<jobname>.sby [taskname]]
-d <dirname>
set workdir name. default: <jobname> (without .sby)
@ -44,6 +45,9 @@ sby [options] [<jobname>.sby]
-t
run in a temporary workdir (remove when finished)
-T taskname
set the taskname (useful when sby file is read from stdin)
--yosys <path_to_executable>
--abc <path_to_executable>
--smtbmc <path_to_executable>
@ -55,7 +59,7 @@ sby [options] [<jobname>.sby]
sys.exit(1)
try:
opts, args = getopt.getopt(sys.argv[1:], "d:btf", ["yosys=",
opts, args = getopt.getopt(sys.argv[1:], "d:btfT:", ["yosys=",
"abc=", "smtbmc=", "suprove=", "aigbmc=", "avy="])
except:
usage()
@ -69,6 +73,8 @@ for o, a in opts:
opt_backup = True
elif o == "-t":
opt_tmpdir = True
elif o == "-T":
taskname = a
elif o == "--yosys":
exe_paths["yosys"] = a
elif o == "--abc":
@ -84,13 +90,17 @@ for o, a in opts:
else:
usage()
if len(args) > 1:
if len(args) > 2:
usage()
if len(args) == 1:
if len(args) > 0:
sbyfile = args[0]
assert sbyfile.endswith(".sby")
if len(args) > 1:
assert taskname is None
taskname = args[1]
early_logmsgs = list()
def early_log(msg):
@ -99,6 +109,8 @@ def early_log(msg):
if workdir is None and sbyfile is not None and not opt_tmpdir:
workdir = sbyfile[:-4]
if taskname is not None:
workdir += "_" + taskname
if workdir is not None:
if opt_backup:
@ -119,7 +131,7 @@ else:
opt_tmpdir = True
workdir = tempfile.mkdtemp()
job = SbyJob(sbyfile, workdir, early_logmsgs)
job = SbyJob(sbyfile, taskname, workdir, early_logmsgs)
for k, v in exe_paths.items():
job.exe_paths[k] = v

View file

@ -126,7 +126,7 @@ class SbyTask:
class SbyJob:
def __init__(self, filename, workdir, early_logs):
def __init__(self, filename, taskname, workdir, early_logs):
self.options = dict()
self.used_options = set()
self.engines = list()
@ -169,16 +169,66 @@ class SbyJob:
with (open(filename, "r") if filename else sys.stdin) as f:
with open("%s/config.sby" % workdir, "w") as cfgfile:
pycode = None
tasks_section = False
task_tags_active = set()
task_tags_all = set()
task_skip_block = False
for line in f:
line = line.rstrip("\n")
line = line.rstrip("\r")
if line == "--pycode-begin--":
if tasks_section and line.startswith("["):
tasks_section = False
tasks_skip = False
if task_skip_block:
if line == "":
task_skip_block = False
else:
for t in task_tags_all:
if line.startswith(t+":"):
line = line[len(t)+1:].lstrip()
if t not in task_tags_active:
if line == "":
task_skip_block = True
tasks_skip = True
break
if line.startswith("~"+t+":"):
line = line[len(t)+2:].lstrip()
if t in task_tags_active:
if line == "":
task_skip_block = True
tasks_skip = True
break
if tasks_skip or task_skip_block:
continue
if tasks_section:
line = line.split()
if len(line) > 0:
if taskname is None:
taskname = line[0]
self.log("Configuration file contains tasks. Running default task '%s'." % taskname)
for t in line:
if taskname == line[0]:
task_tags_active.add(t)
task_tags_all.add(t)
elif line == "[tasks]":
tasks_section = True
elif line == "--pycode-begin--":
pycode = ""
elif line == "--pycode-end--":
gdict = globals().copy()
gdict["cfgfile"] = cfgfile
gdict["filename"] = filename
gdict["taskname"] = taskname
exec("def output(*args, **kwargs):\n print(*args, **kwargs, file=cfgfile)\n" + pycode, gdict)
pycode = None
else:
if pycode is None:
print(line, file=cfgfile)