+class VcsSim(object):
+ def __init__(self, simv=None, debug=False):
+ if simv:
+ cmd = shlex.split(simv)
+ else:
+ cmd = ["simv"]
+ cmd += ["+jtag_vpi_enable"]
+ if debug:
+ cmd[0] = cmd[0] + "-debug"
+ cmd += ["+vcdplusfile=output/gdbserver.vpd"]
+ logfile = open("simv.log", "w")
+ logfile.write("+ %s\n" % " ".join(cmd))
+ logfile.flush()
+ listenfile = open("simv.log", "r")
+ listenfile.seek(0,2)
+ self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
+ stderr=logfile)
+ done = False
+ while (not done):
+ line = listenfile.readline()
+ if (not line):
+ time.sleep(1)
+ if ("Listening on port 5555" in line):
+ done = True
+
+ def __del__(self):
+ print "DELETE called for VcsSim"
+ try:
+ self.process.kill()
+ self.process.wait()
+ except OSError:
+ pass
+
+