import os
path = os.path

from myhdl import *

# Icarus
def setupCosimulationIcarus(**kwargs):
    name = kwargs['name']
    objfile = "%s.o" % name
    if path.exists(objfile):
        os.remove(objfile)
    analyze_cmd = "iverilog -o %s %s.v tb_%s.v" % (objfile, name, name)
    os.system(analyze_cmd)
    simulate_cmd = "vvp -m ../../../../cosimulation/icarus/myhdl.vpi %s" % objfile
    return Cosimulation(simulate_cmd, **kwargs)

# cver
def setupCosimulationCver(**kwargs):
    name = kwargs['name']
    cmd = "cver -q +loadvpi=../../../../cosimulation/cver/myhdl_vpi:vpi_compat_bootstrap " + \
          "%s.v tb_%s.v " % (name, name)
    return Cosimulation(cmd, **kwargs)

def verilogCompileIcarus(name):
    objfile = "%s.o" % name
    if path.exists(objfile):
        os.remove(objfile)
    analyze_cmd = "iverilog -o %s %s.v tb_%s.v" % (objfile, name, name)
    os.system(analyze_cmd)

    
def verilogCompileCver(name):
    cmd = "cver -c %s.v" % name
    os.system(cmd)
    


setupCosimulation = setupCosimulationIcarus
#setupCosimulation = setupCosimulationCver

verilogCompile = verilogCompileIcarus
#verilogCompile = verilogCompileCver

@@ -18,16 +18,33 @@
 os.path%0A
+import subprocess
 %0Afrom my
@@ -229,33 +229,34 @@
 alyze_cmd = 
-%22
+%5B'
 iverilog
  -o %25s %25s.v 
@@ -247,66 +247,77 @@
 ilog
- -o %25s %25s.v 
+', '-o', objfile, '%25s.v' %25name, '
 tb_%25s.v
-%22 %25 (objfile, name, name)%0A    os.system
+' %25 name%5D%0A    subprocess.call
 (ana
@@ -349,16 +349,23 @@
 d = 
-%22vvp -m 
+%5B'vvp', '-m', '
 ../.
@@ -405,22 +405,18 @@
 .vpi
- %25s%22 %25
+',
  objfile
 %0A   
@@ -411,16 +411,17 @@
  objfile
+%5D
 %0A    ret

switch to list-of-command-arguments in cosimulation testcases