From 92b247260af441c222e9056ef52695c4db5585b3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 5 Mar 2018 13:09:20 +0100 Subject: [PATCH] Add tasks in .sby files Signed-off-by: Clifford Wolf --- sbysrc/sby.py | 22 ++++++++++++++----- sbysrc/sby_core.py | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index e643173..03f98c3 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -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] [.sby] +sby [options] [.sby [taskname]] -d set workdir name. default: (without .sby) @@ -44,6 +45,9 @@ sby [options] [.sby] -t run in a temporary workdir (remove when finished) + -T taskname + set the taskname (useful when sby file is read from stdin) + --yosys --abc --smtbmc @@ -55,7 +59,7 @@ sby [options] [.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 diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 95d11a1..eb63783 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -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) -- 2.30.2