Пример #1
0
static void check_command_line_args(void)
{
      struct t_vpi_vlog_info vlog_info;
      int idx;

      static int sdf_command_line_done = 0;
      if (sdf_command_line_done)
	    return;

      vpi_get_vlog_info(&vlog_info);

      for (idx = 0 ;  idx < vlog_info.argc ;  idx += 1) {
	    if (strcmp(vlog_info.argv[idx],"-sdf-warn") == 0) {
		  sdf_flag_warning = 1;

	    } else if (strcmp(vlog_info.argv[idx],"-sdf-info") == 0) {
		  sdf_flag_inform = 1;

	    } else if (strcmp(vlog_info.argv[idx],"-sdf-verbose") == 0) {
		  sdf_flag_warning = 1;
		  sdf_flag_inform = 1;
	    }
      }

      sdf_command_line_done = 1;
}
Пример #2
0
/*
 * acc_fetch_argc implemented using VPI interface
 */
int acc_fetch_argc(void)
{
      s_vpi_vlog_info vpi_vlog_info;

      /* get command line info */
      if (! vpi_get_vlog_info(&vpi_vlog_info))
	    return 0;

      /* return argc */
      return vpi_vlog_info.argc;
}
Пример #3
0
static void thunker_register(void)
{
      struct t_vpi_vlog_info vlog_info;
      void*mod;
      void*boot;
      struct t_tfcell*tf;
      int idx;

      vpi_get_vlog_info(&vlog_info);

      for (idx = 0 ;  idx < vlog_info.argc ;  idx += 1) {
	    char*module, *cp, *bp;
	    if (strncmp("-cadpli=", vlog_info.argv[idx], 8) != 0)
		  continue;

	    cp = vlog_info.argv[idx] + 8;
	    assert(cp);

	    bp = strchr(cp, ':');
	    assert(bp);

	    module = malloc(bp-cp+1);
	    strncpy(module, cp, bp-cp);
	    module[bp-cp] = 0;

	    mod = ivl_dlopen(module);
	    if (mod == 0) {
		  vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror());
		  free(module);
		  continue;
	    }

	    bp += 1;
	    boot = ivl_dlsym(mod, bp);
	    if (boot == 0) {
		  vpi_printf("%s: Symbol %s not found.\n",
			     vlog_info.argv[idx], bp);
		  free(module);
		  continue;
	    }

	    free(module);
	    assert(boot);

	    tf = (*((funcvp)boot))();
	    assert(tf);

	    veriusertfs_register_table(tf);
      }
}
Пример #4
0
int VpiStartupCbHdl::run_callback(void) {
    s_vpi_vlog_info info;
    gpi_sim_info_t sim_info;

    vpi_get_vlog_info(&info);

    sim_info.argc = info.argc;
    sim_info.argv = info.argv;
    sim_info.product = info.product;
    sim_info.version = info.version;

    gpi_embed_init(&sim_info);

    return 0;
}
Пример #5
0
/*
 * Get any command line flags. For now we only have a debug flag.
 */
static void check_command_line_flags(void)
{
      struct t_vpi_vlog_info vlog_info;
      static unsigned command_line_processed = 0;

	/* If we have already processed the arguments then just return. */
      if (command_line_processed) return;

      vpi_get_vlog_info(&vlog_info);

      for (int idx = 0; idx < vlog_info.argc; idx += 1) {
	    if (strcmp(vlog_info.argv[idx], "-table-model-debug") == 0) {
		  table_model_debug = 1;
	    }
      }

      command_line_processed = 1;
}
Пример #6
0
/*
 * Compare the +arguments passed to the simulator with the argument
 * passed to the $test$plusargs. If there is a simulator argument that
 * is like this argument, then return true. Otherwise return false.
 */
static PLI_INT32 sys_test_plusargs_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      s_vpi_value val;
      s_vpi_vlog_info info;
      int idx;
      int flag = 0;
      size_t slen, len;

      (void)name; /* Parameter is not used. */

      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      val.format = vpiStringVal;
      vpi_get_value(vpi_scan(argv), &val);
      slen = strlen(val.value.str);

      vpi_get_vlog_info(&info);

	/* Look for a +arg that matches the prefix supplied. */
      for (idx = 0 ;  idx < info.argc ;  idx += 1) {

	      /* Skip arguments that are not +args. */
	    if (info.argv[idx][0] != '+')
		  continue;

	    len = strlen(info.argv[idx]+1);
	    if (len < slen)
		  continue;

	    if (strncmp(val.value.str, info.argv[idx]+1, slen) != 0)
		  continue;

	    flag = 1;
	    break;
      }

      val.format = vpiIntVal;
      val.value.integer = flag;
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Пример #7
0
int exm_waves(const char** filename, int* depth) {
  s_vpi_value vpi_value;
  s_vpi_vlog_info vlog_info;
  static std::string arg = "";

  vpi_get_vlog_info(&vlog_info);

  // Scan options for +waves plusarg
  for (int i=0; i<vlog_info.argc; i++) {
    if (strncmp(vlog_info.argv[i], "+waves", 6) == 0) {
      if (strlen(vlog_info.argv[i]) > 7) {
        arg = vlog_info.argv[i]+7;
      } else {
        arg = default_waves.filename;
      }
    }
  }

  if (arg.length() < 1) {
    // no argument
    return 0;
  }

  // look for depth in format +waves+filename+depth
  size_t pos = arg.find_first_of("+,");
  if (pos != std::string::npos) {
    *depth = atoi(arg.substr(pos+1).c_str());
    arg.erase(pos);
  } else {
    *depth = default_waves.depth;
  }
  if (arg.length() < 1) {
    // e.g. +waves++5
    arg = default_waves.filename;
  }

  *filename = arg.c_str();

  return 1;
}
Пример #8
0
static void simbus_setup(void)
{
      struct t_vpi_vlog_info vlog_info;
      int idx;
      int version_flag = 1;
      vpi_get_vlog_info(&vlog_info);

      for (idx = 0 ; idx < vlog_info.argc ; idx += 1) {

	    if (strncmp(vlog_info.argv[idx],"-simbus-debug-mask=",19) == 0) {
		  simbus_debug_mask = strtoul(vlog_info.argv[idx]+19,0,0);

	    } else if (strcmp(vlog_info.argv[idx],"-simbus-version") == 0) {
		  version_flag = 1;
	    } else if (strcmp(vlog_info.argv[idx],"-no-simbus-version") == 0) {
		  version_flag = 0;
	    }
      }

      if (version_flag)
	    vpi_printf("SIMBUS VPI version: %s\n", simbus_version);

      if (simbus_debug_mask == 0) {
	    const char*text = getenv("SIMBUS_DEBUG_MASK");
	    if (text)
		  simbus_debug_mask = strtoul(text, 0, 0);
      }

      if (simbus_debug_mask)
	    vpi_printf("Using -simbus-debug-mask=0x%04x\n", simbus_debug_mask);

      for (idx = 0 ; idx < MAX_INSTANCES ; idx += 1) {
	    instance_table[idx].name = 0;
	    instance_table[idx].fd = -1;
	    instance_table[idx].trig = 0;
      }
}
Пример #9
0
static PLI_INT32 sys_value_plusargs_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      s_vpi_vlog_info info;
      s_vpi_value fmt;
      s_vpi_value res;
      char msg[64];
      char*cp;
      int idx;
      int flag = 0;
      size_t slen, len;

      vpiHandle callh  = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      fmt.format = vpiStringVal;
      vpi_get_value(vpi_scan(argv), &fmt);

	/* Check for the start of a format string. */
      cp = strchr(fmt.value.str, '%');
      if (cp == 0) {
	    snprintf(msg, sizeof(msg), "ERROR: %s:%d:",
	             vpi_get_str(vpiFile, callh),
	             (int)vpi_get(vpiLineNo, callh));
	    msg[sizeof(msg)-1] = 0;

	    vpi_printf("%s %s is missing a format code.\n", msg, name);
	    vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", fmt.value.str);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* This is the length of string we will look for. */
      slen = cp - fmt.value.str;

	/* Skip a zero. */
      cp += 1;
      if (*cp == '0') cp += 1;

	/* Check the format code. */
      switch (*cp) {
	  case 'd':
	  case 'D':
	  case 'o':
	  case 'O':
	  case 'h':
	  case 'H':
	  case 'x':
	  case 'X':
	  case 'b':
	  case 'B':
	  case 'e':
	  case 'E':
	  case 'f':
	  case 'F':
	  case 'g':
	  case 'G':
	  case 's':
	  case 'S':
	    break;
	  default:
	    snprintf(msg, sizeof(msg), "ERROR: %s:%d:",
	             vpi_get_str(vpiFile, callh),
	             (int)vpi_get(vpiLineNo, callh));
	    msg[sizeof(msg)-1] = 0;

	    vpi_printf("%s %s has an invalid format string:\n", msg, name);
	    vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", fmt.value.str);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* Warn if there is any trailing garbage. */
      if (*(cp+1) != '\0') {
	    snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
	             vpi_get_str(vpiFile, callh),
	             (int)vpi_get(vpiLineNo, callh));
	    msg[sizeof(msg)-1] = 0;

	    vpi_printf("%s Skipping trailing garbage in %s's format string:\n",
	               msg, name);
	    vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", fmt.value.str);
	    *(cp+1) = '\0';
      }

      vpi_get_vlog_info(&info);

	/* Look for a +arg that matches the prefix supplied. */
      for (idx = 0 ;  idx < info.argc ;  idx += 1) {
	    char*sp, *tp, *end;
            size_t sp_len;

	      /* Skip arguments that are not +args. */
	    if (info.argv[idx][0] != '+')
		  continue;

	    len = strlen(info.argv[idx]+1);
	    if (len < slen)
		  continue;

	    if (strncmp(fmt.value.str, info.argv[idx]+1, slen) != 0)
		  continue;

	    sp = info.argv[idx]+1+slen;
            sp_len = strlen(sp);
	    switch (*cp) {
		case 'd':
		case 'D':
		  res.format = vpiDecStrVal;
		    /* A decimal string can set the value to "x" or "z". */
		  if (sp_len == strspn(sp, "xX_") ||
		      sp_len == strspn(sp, "zZ_")) {
			res.value.str = sp;
		    /* A decimal string must contain only these characters.
		     * A decimal string can not start with an "_" character.
		     * A "-" can only be at the start of the string. */
		  } else if (sp_len != strspn(sp, "-0123456789_") ||
		             *sp == '_' ||
		             ((tp = strrchr(sp, '-')) && tp != sp)) {
			res.value.str = "x";
			snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			         vpi_get_str(vpiFile, callh),
			         (int)vpi_get(vpiLineNo, callh));
			msg[sizeof(msg)-1] = 0;
			vpi_printf("%s Invalid decimal value passed to %s:\n",
			           msg, name);
			vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", sp);
		  } else {
			res.value.str = sp;
		  }
		  break;
		case 'o':
		case 'O':
		  res.format = vpiOctStrVal;
		    /* An octal string must contain only these characters.
		     * An octal string can not start with an "_" character.
		     * A "-" can only be at the start of the string. */
		  if (sp_len != strspn(sp, "-01234567_xXzZ") ||
		      *sp == '_' || ((tp = strrchr(sp, '-')) && tp != sp)) {
			res.value.str = "x";
			snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			         vpi_get_str(vpiFile, callh),
			         (int)vpi_get(vpiLineNo, callh));
			msg[sizeof(msg)-1] = 0;
			vpi_printf("%s Invalid octal value passed to %s:\n",
			           msg, name);
			vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", sp);
		  } else {
			res.value.str = sp;
		  }
		  break;
		case 'h':
		case 'H':
		case 'x':
		case 'X':
		  res.format = vpiHexStrVal;
		    /* A hex. string must contain only these characters.
		     * A hex. string can not start with an "_" character.
		     * A "-" can only be at the start of the string. */
		  if (sp_len != strspn(sp, "-0123456789aAbBcCdDeEfF_xXzZ") ||
		      *sp == '_' || ((tp = strrchr(sp, '-')) && tp != sp)) {
			res.value.str = "x";
			snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			         vpi_get_str(vpiFile, callh),
			         (int)vpi_get(vpiLineNo, callh));
			msg[sizeof(msg)-1] = 0;
			vpi_printf("%s Invalid hex value passed to %s:\n",
			           msg, name);
			vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", sp);
		  } else {
			res.value.str = sp;
		  }
		  break;
		case 'b':
		case 'B':
		  res.format = vpiBinStrVal;
		    /* A binary string must contain only these characters.
		     * A binary string can not start with an "_" character.
		     * A "-" can only be at the start of the string. */
		  if (sp_len != strspn(sp, "-01_xXzZ") ||
		      *sp == '_' || ((tp = strrchr(sp, '-')) && tp != sp)) {
			res.value.str = "x";
			snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			         vpi_get_str(vpiFile, callh),
			         (int)vpi_get(vpiLineNo, callh));
			msg[sizeof(msg)-1] = 0;
			vpi_printf("%s Invalid binary value passed to %s:\n",
			           msg, name);
			vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ", sp);
		  } else {
			res.value.str = sp;
		  }
		  break;
		case 'e':
		case 'E':
		case 'f':
		case 'F':
		case 'g':
		case 'G':
		  res.format = vpiRealVal;
		  res.value.real = strtod(sp, &end);
		    /* If we didn't get a full conversion print a warning. */
		  if (*end) {
			  /* We had an invalid value passed. */
			if (end == sp) {
			      snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			               vpi_get_str(vpiFile, callh),
			               (int)vpi_get(vpiLineNo, callh));
			      msg[sizeof(msg)-1] = 0;
			      vpi_printf("%s Invalid real value passed to "
			                 "%s:\n", msg, name);
			      vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ",
			                 sp);
			  /* We have extra garbage at the end. */
			} else {
			      snprintf(msg, sizeof(msg), "WARNING: %s:%d:",
			               vpi_get_str(vpiFile, callh),
			               (int)vpi_get(vpiLineNo, callh));
			      msg[sizeof(msg)-1] = 0;
			      vpi_printf("%s Extra character(s) \"%s\" found "
			                 "in %s's real string:\n",
			                 msg, end, name);
			      vpi_printf("%*s \"%s\".\n", (int)strlen(msg), " ",
			                 sp);
			}
		  }
		  break;
		case 's':
		case 'S':
		  res.format = vpiStringVal;
		  res.value.str = sp;
		  break;
		default:
		  assert(0);
	    }

	    vpi_put_value(vpi_scan(argv), &res, 0, vpiNoDelay);
	    flag = 1;
	    break;
      }

      res.format = vpiIntVal;
      res.value.integer = flag;
      vpi_put_value(callh, &res, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Пример #10
0
void sys_fst_register(void)
{
      int idx;
      struct t_vpi_vlog_info vlog_info;
      s_vpi_systf_data tf_data;
      vpiHandle res;

	/* Scan the extended arguments, looking for fst optimization flags. */
      vpi_get_vlog_info(&vlog_info);

	/* The "speed" option is not used in this dumper. */
      for (idx = 0 ;  idx < vlog_info.argc ;  idx += 1) {
	    if (strcmp(vlog_info.argv[idx],"-fst-space") == 0) {
		  lxm_optimum_mode = LXM_SPACE;

	    } else if (strcmp(vlog_info.argv[idx],"-fst-speed") == 0) {
		  lxm_optimum_mode = LXM_SPEED;

	    } else if (strcmp(vlog_info.argv[idx],"-fst-space-speed") == 0) {
		  lxm_optimum_mode = LXM_BOTH;
	    } else if (strcmp(vlog_info.argv[idx],"-fst-speed-space") == 0) {
		  lxm_optimum_mode = LXM_BOTH;
	    }
      }

      /* All the compiletf routines are located in vcd_priv.c. */

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpall";
      tf_data.calltf    = sys_dumpall_calltf;
      tf_data.compiletf = sys_no_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpall";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpfile";
      tf_data.calltf    = sys_dumpfile_calltf;
      tf_data.compiletf = sys_one_string_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpfile";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpflush";
      tf_data.calltf    = sys_dumpflush_calltf;
      tf_data.compiletf = sys_no_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpflush";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumplimit";
      tf_data.calltf    = sys_dumplimit_calltf;
      tf_data.compiletf = sys_one_numeric_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumplimit";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpoff";
      tf_data.calltf    = sys_dumpoff_calltf;
      tf_data.compiletf = sys_no_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpoff";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpon";
      tf_data.calltf    = sys_dumpon_calltf;
      tf_data.compiletf = sys_no_arg_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpon";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);

      tf_data.type      = vpiSysTask;
      tf_data.tfname    = "$dumpvars";
      tf_data.calltf    = sys_dumpvars_calltf;
      tf_data.compiletf = sys_dumpvars_compiletf;
      tf_data.sizetf    = 0;
      tf_data.user_data = "$dumpvars";
      res = vpi_register_systf(&tf_data);
      vpip_make_systf_system_defined(res);
}
Пример #11
0
static PLI_INT32 simbus_connect_calltf(char*my_name)
{
      int idx;
      char buf[4096];
      s_vpi_value value;
      s_vpi_vlog_info vlog;

      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle arg;
      assert(argv);

	/* Get the one and only argument, and get its string value. */
      arg = vpi_scan(argv);
      assert(arg);

      value.format = vpiStringVal;
      vpi_get_value(arg, &value);
      char*dev_name = strdup(value.value.str);

      DEBUG(SIMBUS_DEBUG_CALLS, "Call $connect(%s)\n", dev_name);

	/* Synthesize a bus server argument string and search for it
	   on the command line. That string will have the host and
	   port number (or just port number) for the bus that we are
	   supposed to connect to. */
      snprintf(buf, sizeof buf,
	       "+simbus-%s-bus=", dev_name);

      vpi_get_vlog_info(&vlog);
      char*host_string = 0;
      for (idx = 0 ; idx < vlog.argc ; idx += 1) {
	    if (strncmp(vlog.argv[idx], buf, strlen(buf)) == 0) {
		  host_string = strdup(vlog.argv[idx]+strlen(buf));
		  break;
	    }
      }

      if (host_string == 0) {
	    vpi_printf("%s:%d: %s(%s) cannot find %s<server> on command line\n",
		       vpi_get_str(vpiFile, sys),
		       (int)vpi_get(vpiLineNo, sys),
		       my_name, dev_name, buf);

	    free(dev_name);
	    value.format = vpiIntVal;
	    value.value.integer = -1;
	    vpi_put_value(sys, &value, 0, vpiNoDelay);
	    return 0;
      }

      DEBUG(SIMBUS_DEBUG_CALLS, "$connect(%s): host string=%s\n", dev_name, host_string);

      int server_fd = -1;
      if (strncmp(host_string, "tcp:", 4) == 0) {
	    server_fd = tcp_server(sys, my_name, dev_name, host_string+4);

      } else if (strncmp(host_string, "pipe:", 5) == 0) {
	    server_fd = pipe_server(sys, my_name, dev_name, host_string+5);

      } else {
	    server_fd = tcp_server(sys, my_name, dev_name, host_string);
      }

      if (server_fd == -1) {
	    DEBUG(SIMBUS_DEBUG_CALLS, "$connect(%s): Failed connect to server.\n", dev_name);
	    free(dev_name);
	    free(host_string);
	    value.format = vpiIntVal;
	    value.value.integer = -1;
	    vpi_put_value(sys, &value, 0, vpiNoDelay);
	    return 0;
      }

	/* Send HELLO message to the server. */

      snprintf(buf, sizeof buf, "HELLO %s", dev_name);

	/* Add to the HELLO string a string of setting tokens for all
	   the remaining arguments of the $simbus_connect statement. */
      char *bp = buf + strlen(buf);
      size_t bp_len = sizeof buf - (bp-buf);

      assert(argv);
      for (arg = vpi_scan(argv) ; arg ; arg = vpi_scan(argv)) {
	    value.format = vpiStringVal;
	    vpi_get_value(arg, &value);
	    if (value.format != vpiStringVal) {
		  vpi_printf("%s:%d: $connect(%s) Can't get string for argument.\n",
			     vpi_get_str(vpiFile, sys),
			     vpi_get(vpiLineNo,sys),
			     dev_name);
		  continue;
	    }

	    DEBUG(SIMBUS_DEBUG_CALLS, "$connect(%s): HELLO key: %s\n", dev_name, value.value.str);

	      /* Remove leading and trailing white space. */
	    char*sp = value.value.str;
	    while (*sp && isspace(*sp))
		  sp += 1;

	    char*ep = sp+strlen(sp);
	    while (ep > sp && isspace(ep[-1])) {
		  ep -= 1;
		  ep[0] = 0;
	    }

	    if (ep==sp) {
		  continue;
	    }

	    if (strchr(sp, ' ') || ! strchr(sp, '=')) {
		  vpi_printf("%s:%d: %s(%s): Malformed string argument: %s\n",
			     vpi_get_str(vpiFile, sys),
			     vpi_get(vpiLineNo,sys),
			     my_name, host_string, sp);
		  continue;
	    }

	    if ((ep-sp)+1 >= bp_len) {
		  vpi_printf("%s:%d: %s(%s): Internal error: Ran out of string space.\n",
			     vpi_get_str(vpiFile, sys),
			     vpi_get(vpiLineNo,sys),
			     my_name, host_string);
		  continue;
	    }

	    *bp++ = ' ';
	    bp_len -= 1;

	    strcpy(bp, sp);
	    bp += (ep-sp);
	    bp_len -= (ep-sp);
      }

      *bp++ = '\n';
      *bp = 0;

      DEBUG(SIMBUS_DEBUG_PROTOCOL, "Send %s", buf);
      int rc = write(server_fd, buf, strlen(buf));
      assert(rc == strlen(buf));

	/* Read response from server. */
      rc = read(server_fd, buf, sizeof buf);
      assert(rc > 0);
      assert(strchr(buf, '\n'));
      DEBUG(SIMBUS_DEBUG_PROTOCOL, "Recv %s", buf);

      if (strcmp(buf, "NAK\n") == 0) {
	    vpi_printf("%s:%d: %s(%s) Server %s doesn't want me.\n",
		       vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys),
		       my_name, host_string, dev_name);

	    free(dev_name);
	    free(host_string);
	    close(server_fd);
	    value.format = vpiIntVal;
	    value.value.integer = -1;
	    vpi_put_value(sys, &value, 0, vpiNoDelay);
	    return 0;
      }

      unsigned ident = 0;
      if (strncmp(buf, "YOU-ARE ", 8) == 0) {
	    sscanf(buf, "YOU-ARE %u", &ident);
      } else {
	    vpi_printf("%s:%d: %s(%s) Server %s protocol error.\n",
		       vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys),
		       my_name, dev_name, host_string);

	    free(dev_name);
	    free(host_string);
	    close(server_fd);
	    value.format = vpiIntVal;
	    value.value.integer = -1;
	    vpi_put_value(sys, &value, 0, vpiNoDelay);
	    return 0;
      }

	/* Create an instance for this connection. */
      idx = 0;
      while (instance_table[idx].name && idx < MAX_INSTANCES) {
	    idx += 1;
      }

      assert(idx < MAX_INSTANCES);
      instance_table[idx].name = dev_name;
      instance_table[idx].fd = server_fd;
	/* Empty the read buffer. */
      instance_table[idx].read_buf[0] = 0;
      instance_table[idx].read_fil = 0;

      vpi_printf("%s:%d: %s(%s) Bus server %s ready.\n",
		 vpi_get_str(vpiFile, sys), (int)vpi_get(vpiLineNo, sys),
		 my_name, dev_name, host_string);

      DEBUG(SIMBUS_DEBUG_CALLS, "Return %d from $connect\n", idx);
      value.format = vpiIntVal;
      value.value.integer = idx;
      vpi_put_value(sys, &value, 0, vpiNoDelay);
      return 0;
}
Пример #12
0
static void sys_lxt_or_vcd_register()
{
      int idx;
      struct t_vpi_vlog_info vlog_info;

      const char*dumper;

	/* Get the dumper of choice from the IVERILOG_DUMPER
	   environment variable. */
      dumper = getenv("IVERILOG_DUMPER");
      if (dumper) {
	    char*cp = strchr(dumper,'=');
	    if (cp != 0)
		  dumper = cp + 1;

      } else {
	    dumper = "vcd";
      }

	/* Scan the extended arguments, looking for flags that select
	   major features. This can override the environment variable
	   settings. */
      vpi_get_vlog_info(&vlog_info);

      for (idx = 0 ;  idx < vlog_info.argc ;  idx += 1) {

            if (strcmp(vlog_info.argv[idx],"-fst") == 0) {
		  dumper = "fst";

	    } else if (strcmp(vlog_info.argv[idx],"-fst-space") == 0) {
		  dumper = "fst";

	    } else if (strcmp(vlog_info.argv[idx],"-fst-speed") == 0) {
		  dumper = "fst";

	    } else if (strcmp(vlog_info.argv[idx],"-fst-space-speed") == 0) {
		  dumper = "fst";
	    } else if (strcmp(vlog_info.argv[idx],"-fst-speed-space") == 0) {
		  dumper = "fst";

	    } else if (strcmp(vlog_info.argv[idx],"-fst-none") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt") == 0) {
		  dumper = "lxt";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt-space") == 0) {
		  dumper = "lxt";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt-speed") == 0) {
		  dumper = "lxt";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt-none") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt2") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt2-space") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt2-speed") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lxt2-none") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-lx2") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lx2-space") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lx2-speed") == 0) {
		  dumper = "lxt2";

	    } else if (strcmp(vlog_info.argv[idx],"-lx2-none") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-vcd") == 0) {
		  dumper = "vcd";

	    } else if (strcmp(vlog_info.argv[idx],"-vcd-off") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-vcd-none") == 0) {
		  dumper = "none";

	    } else if (strcmp(vlog_info.argv[idx],"-none") == 0) {
		  dumper = "none";

	    }
      }

      if (strcmp(dumper, "vcd") == 0)
	    sys_vcd_register();

      else if (strcmp(dumper, "VCD") == 0)
	    sys_vcd_register();

      else if (strcmp(dumper, "fst") == 0)
	    sys_fst_register();

      else if (strcmp(dumper, "FST") == 0)
	    sys_fst_register();

      else if (strcmp(dumper, "lxt") == 0)
	    sys_lxt_register();

      else if (strcmp(dumper, "LXT") == 0)
	    sys_lxt_register();

      else if (strcmp(dumper, "lxt2") == 0)
	    sys_lxt2_register();

      else if (strcmp(dumper, "LXT2") == 0)
	    sys_lxt2_register();

      else if (strcmp(dumper, "lx2") == 0)
	    sys_lxt2_register();

      else if (strcmp(dumper, "LX2") == 0)
	    sys_lxt2_register();

      else if (strcmp(dumper, "none") == 0)
	    sys_vcdoff_register();

      else if (strcmp(dumper, "NONE") == 0)
	    sys_vcdoff_register();

      else {
	    vpi_mcd_printf(1, "system.vpi: Unknown dumper format: %s,"
		           " using VCD instead.\n", dumper);
	    sys_vcd_register();
      }
}