sbyfile = None
workdir = None
+taskname = None
opt_force = False
opt_backup = False
opt_tmpdir = False
def usage():
print("""
-sby [options] [<jobname>.sby]
+sby [options] [<jobname>.sby [taskname]]
-d <dirname>
set workdir name. default: <jobname> (without .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>
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()
opt_backup = True
elif o == "-t":
opt_tmpdir = True
+ elif o == "-T":
+ taskname = a
elif o == "--yosys":
exe_paths["yosys"] = a
elif o == "--abc":
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):
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:
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
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()
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)