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

Add support for --pycode-begin/end-- sections

This commit is contained in:
Clifford Wolf 2017-05-08 15:01:56 +02:00
parent a16e90a885
commit 8817f61de3

View file

@ -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()