parameters: (file_names, codes=None)
return_statement: return sess
docstring: Create a new iverilog session by compile the file.
  
      Parameters
      ----------
      file_names : str or list of str
          The name of the file
  
      codes : str or list of str
          The code in str.
  
      Returns
      -------
      sess : VPISession
          The created session.
docstring_summary: Create a new iverilog session by compile the file.
docstring_tokens: Create a new iverilog session by compile the file .
function: def session(file_names, codes=None):
      """Create a new iverilog session by compile the file.
  
      Parameters
      ----------
      file_names : str or list of str
          The name of the file
  
      codes : str or list of str
          The code in str.
  
      Returns
      -------
      sess : VPISession
          The created session.
      """
      if isinstance(file_names, string_types):
          file_names = [file_names]
      path = util.tempdir()
  
      if codes:
          if isinstance(codes, (list, tuple)):
              codes = '\n'.join(codes)
          fcode = path.relpath("temp_code.v")
          with open(fcode, "w") as out_file:
              out_file.write(codes)
          file_names.append(fcode)
  
      for name in file_names:
          if not os.path.exists(name):
              raise ValueError("Cannot find file %s" % name)
  
      target = path.relpath(os.path.basename(file_names[0].rsplit(".", 1)[0]))
      compile_file(file_names, target)
      vpi_path = _find_vpi_path()
  
      cmd = ["vvp"]
      cmd += ["-M", vpi_path]
      cmd += ["-m", "tvm_vpi"]
      cmd += [target]
      env = os.environ.copy()
  
      read_device, write_host = os.pipe()
      read_host, write_device = os.pipe()
  
      if sys.platform == "win32":
          import msvcrt
          env['TVM_DREAD_PIPE'] = str(msvcrt.get_osfhandle(read_device))
          env['TVM_DWRITE_PIPE'] = str(msvcrt.get_osfhandle(write_device))
          read_host = msvcrt.get_osfhandle(read_host)
          write_host = msvcrt.get_osfhandle(write_host)
      else:
          env['TVM_DREAD_PIPE'] = str(read_device)
          env['TVM_DWRITE_PIPE'] = str(write_device)
  
      env['TVM_HREAD_PIPE'] = str(read_host)
      env['TVM_HWRITE_PIPE'] = str(write_host)
  
      try:
          # close_fds does not work well for all python3
          # Use pass_fds instead.
          # pylint: disable=unexpected-keyword-arg
          pass_fds = (read_device, write_device, read_host, write_host)
          proc = subprocess.Popen(cmd, pass_fds=pass_fds, env=env)
      except TypeError:
          # This is effective for python2
          proc = subprocess.Popen(cmd, close_fds=False, env=env)
  
      # close device side pipe
      os.close(read_device)
      os.close(write_device)
  
      sess = _api_internal._vpi_SessMake(read_host, write_host)
      sess.proc = proc
      sess.execpath = path
      return sess
function_tokens: def session ( file_names , codes = None ) : if isinstance ( file_names , string_types ) : file_names = [ file_names ] path = util . tempdir ( ) if codes : if isinstance ( codes , ( list , tuple ) ) : codes = '\n' . join ( codes ) fcode = path . relpath ( "temp_code.v" ) with open ( fcode , "w" ) as out_file : out_file . write ( codes ) file_names . append ( fcode ) for name in file_names : if not os . path . exists ( name ) : raise ValueError ( "Cannot find file %s" % name ) target = path . relpath ( os . path . basename ( file_names [ 0 ] . rsplit ( "." , 1 ) [ 0 ] ) ) compile_file ( file_names , target ) vpi_path = _find_vpi_path ( ) cmd = [ "vvp" ] cmd += [ "-M" , vpi_path ] cmd += [ "-m" , "tvm_vpi" ] cmd += [ target ] env = os . environ . copy ( ) read_device , write_host = os . pipe ( ) read_host , write_device = os . pipe ( ) if sys . platform == "win32" : import msvcrt env [ 'TVM_DREAD_PIPE' ] = str ( msvcrt . get_osfhandle ( read_device ) ) env [ 'TVM_DWRITE_PIPE' ] = str ( msvcrt . get_osfhandle ( write_device ) ) read_host = msvcrt . get_osfhandle ( read_host ) write_host = msvcrt . get_osfhandle ( write_host ) else : env [ 'TVM_DREAD_PIPE' ] = str ( read_device ) env [ 'TVM_DWRITE_PIPE' ] = str ( write_device ) env [ 'TVM_HREAD_PIPE' ] = str ( read_host ) env [ 'TVM_HWRITE_PIPE' ] = str ( write_host ) try : # close_fds does not work well for all python3 # Use pass_fds instead. # pylint: disable=unexpected-keyword-arg pass_fds = ( read_device , write_device , read_host , write_host ) proc = subprocess . Popen ( cmd , pass_fds = pass_fds , env = env ) except TypeError : # This is effective for python2 proc = subprocess . Popen ( cmd , close_fds = False , env = env ) # close device side pipe os . close ( read_device ) os . close ( write_device ) sess = _api_internal . _vpi_SessMake ( read_host , write_host ) sess . proc = proc sess . execpath = path return sess