From: Clifford Wolf Date: Mon, 8 May 2017 13:01:56 +0000 (+0200) Subject: Add support for --pycode-begin/end-- sections X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8817f61de3c11508e941989cb7d7749dca05868d;p=SymbiYosys.git Add support for --pycode-begin/end-- sections --- diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 3a1ba62..17c0254 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -168,6 +168,25 @@ class SbyJob: key = None with open(filename, "r") as f: + with open("%s/config.sby" % workdir, "w") as cfgfile: + pycode = None + for line in f: + line = line.rstrip("\n") + line = line.rstrip("\r") + if line == "--pycode-begin--": + pycode = "" + elif line == "--pycode-end--": + gdict = globals().copy() + gdict["cfgfile"] = cfgfile + 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) + else: + pycode += line + "\n" + + with open("%s/config.sby" % workdir, "r") as f: for line in f: raw_line = line line = line.strip()