Bugfix in smtio vcd handling of $-identifiers

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2019-10-23 00:04:34 +02:00
parent 7b350cacd4
commit f02623abb5
1 changed files with 9 additions and 6 deletions

View File

@ -1032,12 +1032,17 @@ class MkVcd:
print("$var integer 32 t smt_step $end", file=self.f) print("$var integer 32 t smt_step $end", file=self.f)
print("$var event 1 ! smt_clock $end", file=self.f) print("$var event 1 ! smt_clock $end", file=self.f)
def vcdescape(n):
if n.startswith("$") or ":" in n:
return "\\" + n
return n
scope = [] scope = []
for path in sorted(self.nets): for path in sorted(self.nets):
key, width = self.nets[path] key, width = self.nets[path]
uipath = list(path) uipath = list(path)
if "." in uipath[-1]: if "." in uipath[-1] and not uipath[-1].startswith("$"):
uipath = uipath[0:-1] + uipath[-1].split(".") uipath = uipath[0:-1] + uipath[-1].split(".")
for i in range(len(uipath)): for i in range(len(uipath)):
uipath[i] = re.sub(r"\[([^\]]*)\]", r"<\1>", uipath[i]) uipath[i] = re.sub(r"\[([^\]]*)\]", r"<\1>", uipath[i])
@ -1048,15 +1053,13 @@ class MkVcd:
while uipath[:-1] != scope: while uipath[:-1] != scope:
scopename = uipath[len(scope)] scopename = uipath[len(scope)]
if scopename.startswith("$"): print("$scope module %s $end" % vcdescape(scopename), file=self.f)
scopename = "\\" + scopename
print("$scope module %s $end" % scopename, file=self.f)
scope.append(uipath[len(scope)]) scope.append(uipath[len(scope)])
if path in self.clocks and self.clocks[path][1] == "event": if path in self.clocks and self.clocks[path][1] == "event":
print("$var event 1 %s %s $end" % (key, uipath[-1]), file=self.f) print("$var event 1 %s %s $end" % (key, vcdescape(uipath[-1])), file=self.f)
else: else:
print("$var wire %d %s %s $end" % (width, key, uipath[-1]), file=self.f) print("$var wire %d %s %s $end" % (width, key, vcdescape(uipath[-1])), file=self.f)
for i in range(len(scope)): for i in range(len(scope)):
print("$upscope $end", file=self.f) print("$upscope $end", file=self.f)