litex/migen/sim/icarus.py

32 lines
928 B
Python
Raw Normal View History

2012-03-05 14:31:41 -05:00
import subprocess
2012-03-06 08:20:26 -05:00
import os
2012-03-05 14:31:41 -05:00
def _str2file(filename, contents):
f = open(filename, "w")
f.write(contents)
f.close()
class Runner:
2012-03-06 08:20:26 -05:00
def __init__(self, extra_files=None, top_file="migensim_top.v", dut_file="migensim_dut.v", vvp_file=None, keep_files=False):
2012-03-05 14:31:41 -05:00
if extra_files is None: extra_files = []
if vvp_file is None: vvp_file = dut_file + "vp"
2012-03-06 08:20:26 -05:00
self.extra_files = extra_files
2012-03-05 14:31:41 -05:00
self.top_file = top_file
self.dut_file = dut_file
self.vvp_file = vvp_file
2012-03-06 08:20:26 -05:00
self.keep_files = keep_files
2012-03-05 14:31:41 -05:00
def start(self, c_top, c_dut):
_str2file(self.top_file, c_top)
_str2file(self.dut_file, c_dut)
subprocess.check_call(["iverilog", "-o", self.vvp_file, self.top_file, self.dut_file] + self.extra_files)
subprocess.Popen(["vvp", "-mmigensim", self.vvp_file])
2012-03-06 08:20:26 -05:00
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