Skip to content

Commit

Permalink
sby: core: fixed the setup script generation and ensured the model fo…
Browse files Browse the repository at this point in the history
…r the setup was implemented
  • Loading branch information
lethalbit committed Feb 9, 2023
1 parent 19061bc commit b53bcf8
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions sbysrc/sby_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,25 +548,29 @@ def error(self, logmessage):

def gen_setup_script(self):
script = '# Autogenerated by SBY stage setup\n'
script += 'select *'
script += 'read_ilang design.il\n'
script += 'select *\n'

def cutpoint(v):
return f"cutpoint {v}"
return f"cutpoint {v}\n"

def disable(v):
return f"select -del {v}"
return f"select -del {v}\n"

def enable(v):
return f"select -add {v}"
return f"select -add {v}\n"

def assume(v):
return f"chformal -assert2assume {v}"
return f"chformal -assert2assume {v}\n"

def define(v):
return f"select -set {v}"
defines = str()
for defn in v:
defines += f"select -set {v}\n"
return defines

def invoke(v):
return f"{v}"
return f"{v}\n"

for k, v in self.setup.items():
script += {
Expand All @@ -576,11 +580,12 @@ def invoke(v):
'assume': assume(v),
'define': define(v),
'invoke': invoke(v)
}.get(k, '') + '\n'
}.get(k, '')

script += 'select -set _setup %\n'
script += 'select @_setup %n\n'
script += 'chformal -assert -remove %\n'
script += 'write_ilang design_setup.il\n'
return script


Expand Down Expand Up @@ -1015,9 +1020,14 @@ def make_model(self, model_name):
os.makedirs(f"{self.workdir}/model")

if model_name == "prep":
has_setup = len(self.setup) > 0

with open(f"""{self.workdir}/model/design_prep.ys""", "w") as f:
print(f"# running in {self.workdir}/model/", file=f)
print(f"""read_ilang design.il""", file=f)
if has_setup:
print(f"""read_ilang design_setup.il""", file=f)
else:
print(f"""read_ilang design.il""", file=f)
print("scc -select; simplemap; select -clear", file=f)
print("memory_nordff", file=f)
if self.opt_multiclock:
Expand Down Expand Up @@ -1045,7 +1055,7 @@ def make_model(self, model_name):
proc = SbyProc(
self,
model_name,
self.model("base"),
self.model("setup" if has_setup else "base"),
"cd {}/model; {} -ql design_{s}.log design_{s}.ys".format(self.workdir, self.exe_paths["yosys"], s=model_name)
)
proc.checkretcode = True
Expand Down Expand Up @@ -1195,6 +1205,19 @@ def instance_hierarchy_error_callback(retcode):

return [proc]

if model_name == "setup":
with open(f"{self.workdir}/model/design_setup.ys", "w") as f:
f.write(self.gen_setup_script())

proc = SbyProc(
self,
"setup",
self.model("base"),
f"""cd {self.workdir}/model; {self.exe_paths["yosys"]} -ql design_setup.log design_setup.ys"""
)

return [proc]

self.error(f"Invalid model name: {model_name}")

def model(self, model_name):
Expand Down

0 comments on commit b53bcf8

Please sign in to comment.