sim: remove temporary files and socket

This commit is contained in:
Sebastien Bourdeauducq 2012-03-06 14:20:26 +01:00
parent 7230508e7c
commit 06de17b16c
2 changed files with 17 additions and 4 deletions

View file

@ -69,10 +69,13 @@ class Simulator:
rst_signal=rst_signal, rst_signal=rst_signal,
return_ns=True) return_ns=True)
sim_runner.start(c_top, c_fragment)
self.ipc.accept()
self.cycle_counter = 0 self.cycle_counter = 0
self.interrupt = False self.interrupt = False
self.sim_runner = sim_runner
self.sim_runner.start(c_top, c_fragment)
self.ipc.accept()
self.fragment.call_sim(self, 0) self.fragment.call_sim(self, 0)
self.ipc.send(MessageGo()) self.ipc.send(MessageGo())

View file

@ -1,4 +1,5 @@
import subprocess import subprocess
import os
def _str2file(filename, contents): def _str2file(filename, contents):
f = open(filename, "w") f = open(filename, "w")
@ -6,16 +7,25 @@ def _str2file(filename, contents):
f.close() f.close()
class Runner: class Runner:
def __init__(self, top_file="migensim_top.v", dut_file="migensim_dut.v", extra_files=None, vvp_file=None): def __init__(self, extra_files=None, top_file="migensim_top.v", dut_file="migensim_dut.v", vvp_file=None, keep_files=False):
if extra_files is None: extra_files = [] if extra_files is None: extra_files = []
if vvp_file is None: vvp_file = dut_file + "vp" if vvp_file is None: vvp_file = dut_file + "vp"
self.extra_files = extra_files
self.top_file = top_file self.top_file = top_file
self.dut_file = dut_file self.dut_file = dut_file
self.extra_files = extra_files
self.vvp_file = vvp_file self.vvp_file = vvp_file
self.keep_files = keep_files
def start(self, c_top, c_dut): def start(self, c_top, c_dut):
_str2file(self.top_file, c_top) _str2file(self.top_file, c_top)
_str2file(self.dut_file, c_dut) _str2file(self.dut_file, c_dut)
subprocess.check_call(["iverilog", "-o", self.vvp_file, self.top_file, self.dut_file] + self.extra_files) subprocess.check_call(["iverilog", "-o", self.vvp_file, self.top_file, self.dut_file] + self.extra_files)
subprocess.Popen(["vvp", "-mmigensim", self.vvp_file]) subprocess.Popen(["vvp", "-mmigensim", self.vvp_file])
def __del__(self):
if not self.keep_files:
for f in [self.top_file, self.dut_file, self.vvp_file]:
try:
os.remove(f)
except OSError:
pass