Skip to content

Commit

Permalink
sim.pysim: Only close VCD/GTKW files if we opened them ourselves.
Browse files Browse the repository at this point in the history
Fixes #1107.
  • Loading branch information
wanda-phi authored and whitequark committed Feb 27, 2024
1 parent d562d0e commit a430c1d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions amaranth/sim/pysim.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ def __init__(self, fragment, *, vcd_file, gtkw_file=None, traces=()):
# the simulator is still usable if it's not installed for some reason.
import vcd, vcd.gtkw

self.close_vcd = False
self.close_gtkw = False
if isinstance(vcd_file, str):
vcd_file = open(vcd_file, "w")
self.close_vcd = True
if isinstance(gtkw_file, str):
gtkw_file = open(gtkw_file, "w")
self.close_gtkw = True

self.vcd_vars = SignalDict()
self.vcd_file = vcd_file
Expand Down Expand Up @@ -150,9 +154,9 @@ def close(self, timestamp):
for name in self.gtkw_names[signal]:
self.gtkw_save.trace(name)

if self.vcd_file is not None:
if self.close_vcd:
self.vcd_file.close()
if self.gtkw_file is not None:
if self.close_gtkw:
self.gtkw_file.close()


Expand Down

0 comments on commit a430c1d

Please sign in to comment.