Esempio n. 1
0
const char* VpiSignalObjHdl::get_signal_value_binstr(void)
{
    FENTER
    s_vpi_value value_s = {vpiBinStrVal};
    p_vpi_value value_p = &value_s;

    vpi_get_value(GpiObjHdl::get_handle<vpiHandle>(), value_p);
    check_vpi_error();

    return value_p->value.str;
}
Esempio n. 2
0
static PLI_INT32 sys_ferror_calltf(PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle reg;
      s_vpi_value val;
      char *msg;
      PLI_INT32 size;
      unsigned chars;
      PLI_UINT32 fd_mcd;

	/* Get the file pointer. */
      val.format = vpiIntVal;
      vpi_get_value(vpi_scan(argv), &val);
      fd_mcd = val.value.integer;

	/* Get the register to put the string result and figure out how many
	 * characters it will hold. */
      reg = vpi_scan(argv);
      size = vpi_get(vpiSize, reg);
      chars = size / 8;
      vpi_free_object(argv);

	/* If we do not already have an error check that the fd is valid.
	 * The assumption is that the other routines have set errno to
	 * EBADF when they encounter a bad file descriptor, so we do not
	 * need to check here. We also need to special case this since
	 * $fopen() will return 0 (a bad file descriptor) when it has a
	 * problem (sets errno). */
      if (!errno && !vpi_get_file(fd_mcd) ) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor (0x%x) given to %s.\n",
	               (unsigned int)fd_mcd, name);
	    errno = EBADF;
      }

	/* Return the error code. */
      val.format = vpiIntVal;
      val.value.integer = errno;
      vpi_put_value(callh, &val, 0, vpiNoDelay);

	/* Only return the number of characters that will fit in the reg. */
      msg = (char *) malloc(chars);
      if (errno != 0) strncpy(msg, strerror(errno), chars-1);
      else strncpy(msg, "", chars-1);
      msg[chars-1] = '\0';
      val.format = vpiStringVal;
      val.value.str = msg;
      vpi_put_value(reg, &val, 0, vpiNoDelay);
      free(msg);

      return 0;
}
Esempio n. 3
0
static PLI_INT32 sys_dumpvars_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle item;
      s_vpi_value value;
      unsigned depth = 0;

      if (dump_file == 0) {
	    open_dumpfile(callh);
	    if (dump_file == 0) {
		  if (argv) vpi_free_object(argv);
		  return 0;
	    }
      }

      if (install_dumpvars_callback()) {
	    if (argv) vpi_free_object(argv);
	    return 0;
      }

        /* Get the depth if it exists. */
      if (argv) {
	    value.format = vpiIntVal;
	    vpi_get_value(vpi_scan(argv), &value);
	    depth = value.value.integer;
      }
      if (!depth) depth = 10000;

        /* This dumps all the modules in the design if none are given. */
      if (!argv || !(item = vpi_scan(argv))) {
	    argv = vpi_iterate(vpiModule, 0x0);
	    assert(argv);  /* There must be at least one top level module. */
	    item = vpi_scan(argv);
      }

      for ( ; item; item = vpi_scan(argv)) {

	    int dep = draw_scope(item);

	    scan_item(depth, item, 0);
	      /* The scope list must be sorted after we scan an item.  */
	    vcd_names_sort(&lxt_tab);

	    while (dep--) pop_scope();
      }

	/* Most effective compression. */
      if (lxm_optimum_mode == LXM_SPACE) {
	    lt_set_no_interlace(dump_file);
      }

      return 0;
}
Esempio n. 4
0
/*
 * tf_getp and friends, implemented using VPI interface
 */
PLI_INT32 tf_igetp(PLI_INT32 n, void *obj)
{
      vpiHandle sys_h, sys_i, arg_h = 0;
      s_vpi_value value;
      int rtn = 0;

      assert(n > 0);

      /* get task/func handle */
      sys_h = (vpiHandle)obj;
      sys_i = vpi_iterate(vpiArgument, sys_h);

      /* find nth arg */
      while (n > 0) {
	    if (!(arg_h = vpi_scan(sys_i))) { goto out; }
	    n--;
      }

      /* If it is a constant string, return a pointer to it else int value */
      if (vpi_get(vpiType, arg_h) == vpiConstant &&
	  vpi_get(vpiConstType, arg_h) == vpiStringConst)
      {
	    value.format = vpiStringVal;
	    vpi_get_value(arg_h, &value);
	    rtn = (int) value.value.str;	/* Oh my */
      } else {
	    value.format = vpiIntVal;
	    vpi_get_value(arg_h, &value);
	    rtn = value.value.integer;
      }

      vpi_free_object(sys_i);

out:
      if (pli_trace) {
	    fprintf(pli_trace, "tf_igetp(n=%d, obj=%p) --> %d\n",
		  n, obj, rtn);
      }

      return rtn;
}
Esempio n. 5
0
int exm_python_vpi_file(char* arg) {
  vpiHandle href;
  vpiHandle arglist;
  s_vpi_value vpi_value;

  href = vpi_handle(vpiSysTfCall, 0);
  arglist = vpi_iterate(vpiArgument, href);
  vpi_value.format = vpiStringVal;
  vpi_get_value(vpi_scan(arglist), &vpi_value);

  return exm_python_file(vpi_value.value.str);
}
static void show_this_item(struct vcd_info*info)
{
      s_vpi_value value;

      if (vpi_get(vpiType, info->item) == vpiRealVar) {
	    value.format = vpiRealVal;
	    vpi_get_value(info->item, &value);
	    fprintf(dump_file, "r%.16g %s\n", value.value.real, info->ident);

      } else if (vpi_get(vpiSize, info->item) == 1) {
	    value.format = vpiBinStrVal;
	    vpi_get_value(info->item, &value);
	    fprintf(dump_file, "%s%s\n", value.value.str, info->ident);
      } else {
	    value.format = vpiBinStrVal;
	    vpi_get_value(info->item, &value);
	    fprintf(dump_file, "b%s %s\n",
		    truncate_bitvec(value.value.str),
		    info->ident);
      }
}
Esempio n. 7
0
/*
 * FUNCTION: uvm_register_get_max_size()
 *
 * This C code checks to see if there is PLI handle
 * with a value set to define the maximum bit width.
 *
 * If no such variable is found, then the default 
 * width of 1024 is used.
 *
 * This function should only get called once or twice,
 * its return value is cached in the caller.
 *
 */
static int uvm_register_get_max_size()
{
  vpiHandle ms;
  s_vpi_value value_s = { vpiIntVal };
  ms = vpi_handle_by_name("uvm_register_pkg::UVM_REGISTER_MAX_WIDTH", 0);
  if(ms == 0) 
    return 1024;  /* If nothing else is defined, this is the DEFAULT */
  vpi_get_value(ms, &value_s);
  vpi_printf("UVM_Register DPI-C : Lookup of 'uvm_register_pkg::UVM_REGISTER_MAX_WIDTH' successful. ");
  vpi_printf("Setting new maximum width to %0d\n", value_s.value.integer);
  return value_s.value.integer;
}
Esempio n. 8
0
void get_command_data(char *userdata){

  vpiHandle systfref, args_iter, argh;

  struct t_vpi_value argval;

  int value,i;

  int n = 0;

  uint32_t data;
  
  char* recv_buf;

  recv_buf = (char *) &data; // cast data as our receive char buffer

 read_command_data_again:  
  n = read(rsp_to_vpi_pipe[0],recv_buf,4);
  
  if ((n < 4) && errno==EAGAIN)
    goto read_command_data_again;
  else if (n < 4)
    {
      printf("jp_vpi: get_command_data errno: %d\n",errno);
      perror("jp_vpi: get_command_data read failed");
    }
  if (DBG_JP_VPI) printf("jp_vpi: get_command_data = 0x%.8x\n",data);

  // Obtain a handle to the argument list
  systfref = vpi_handle(vpiSysTfCall, NULL);
  
  // Now call iterate with the vpiArgument parameter
  args_iter = vpi_iterate(vpiArgument, systfref); 

  // get a handle on the variable passed to the function
  argh = vpi_scan(args_iter);

  // now store the command value back in the sim
  argval.format = vpiIntVal;
  
  // Now set the data value
  vpi_get_value(argh, &argval);
  argval.value.integer = (uint32_t) data;
  
  // And vpi_put_value() it back into the sim
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
  
  // Cleanup and return
  vpi_free_object(args_iter);
   
   return;

}
Esempio n. 9
0
int _mon_check_getput() {
    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t.onebit", NULL);
    CHECK_RESULT_NZ(vh2);

    s_vpi_value v;
    v.format = vpiIntVal;
    vpi_get_value(vh2, &v);
    CHECK_RESULT(v.value.integer, 0);

    s_vpi_time t;
    t.type = vpiSimTime;
    t.high = 0;
    t.low = 0;
    v.value.integer = 1;
    vpi_put_value(vh2, &v, &t, vpiNoDelay);

    vpi_get_value(vh2, &v);
    CHECK_RESULT(v.value.integer, 1);

    return 0;
}
Esempio n. 10
0
void get_command_address(char *userdata){

  vpiHandle systfref, args_iter, argh;

  struct t_vpi_value argval;

  int value,i;

  int n;

  uint32_t data;
  
  char* recv_buf;

  recv_buf = (char *) &data; // cast data as our receive char buffer

  n = read(rsp_to_vpi_pipe[0],recv_buf,4);
  if (n<0)
    {
      //client has closed connection
      //attempt to close and return gracefully
      return;
    }      
  
  if (DBG_JP_VPI) printf("jp_vpi: get_command_address adr=0x%.8x\n",data);

  // now put the address into the argument passed to the task
  
  // Obtain a handle to the argument list
  systfref = vpi_handle(vpiSysTfCall, NULL);
  
  // Now call iterate with the vpiArgument parameter
  args_iter = vpi_iterate(vpiArgument, systfref); 

  // get a handle on the variable passed to the function
  argh = vpi_scan(args_iter);

  // now store the command value back in the sim
  argval.format = vpiIntVal;
  
  // Now set the address value
  vpi_get_value(argh, &argval);
  argval.value.integer = (uint32_t) data;
  
  // And vpi_put_value() it back into the sim
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
  
  // Cleanup and return
  vpi_free_object(args_iter);
   
   return;

}
Esempio n. 11
0
/*
 * This C code checks to see if there is PLI handle
 * with a value set to define the maximum bit width.
 *
 * If no such variable is found, then the default 
 * width of 1024 is used.
 *
 * This function should only get called once or twice,
 * its return value is cached in the caller.
 *
 */
static int uvm_hdl_max_width()
{
  vpiHandle ms;
  s_vpi_value value_s = { vpiIntVal, { 0 } };
  ms = vpi_handle_by_name(
      (PLI_BYTE8*) "uvm_pkg::UVM_HDL_MAX_WIDTH", 0);
  if(ms == 0) 
    return 1024;  /* If nothing else is defined, 
                     this is the DEFAULT */
  vpi_get_value(ms, &value_s);
  return value_s.value.integer;
}
Esempio n. 12
0
static PLI_INT32 sys_fputc_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle arg;
      s_vpi_value val;
      PLI_UINT32 fd_mcd;
      FILE *fp;
      unsigned char chr;
      (void) name;  /* Not used! */

	/* Get the character. */
      arg = vpi_scan(argv);
      val.format = vpiIntVal;
      vpi_get_value(arg, &val);
      chr = val.value.integer;


	/* Get the file/MC descriptor. */
      arg = vpi_scan(argv);
      vpi_free_object(argv);
      val.format = vpiIntVal;
      vpi_get_value(arg, &val);
      fd_mcd = val.value.integer;

	/* Put the character and return the result. */
      fp = vpi_get_file(fd_mcd);
      val.format = vpiIntVal;
      if (!fp || IS_MCD(fd_mcd)) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor (0x%x) given to %s.\n", fd_mcd,
	               name);
	    val.value.integer = EOF;
      } else
	    val.value.integer = fputc(chr, fp);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      return 0;
}
Esempio n. 13
0
int _mon_check_quad() {
    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t.quads", NULL);
    CHECK_RESULT_NZ(vh2);

    s_vpi_value v;
    t_vpi_vecval vv[2];
    bzero(&vv,sizeof(vv));

    s_vpi_time t;
    t.type = vpiSimTime;
    t.high = 0;
    t.low = 0;

    VlVpiHandle vhidx2 = vpi_handle_by_index(vh2, 2);
    CHECK_RESULT_NZ(vhidx2);
    VlVpiHandle vhidx3 = vpi_handle_by_index(vh2, 3);
    CHECK_RESULT_NZ(vhidx2);

    v.format = vpiVectorVal;
    v.value.vector = vv;
    v.value.vector[1].aval = 0x12819213UL;
    v.value.vector[0].aval = 0xabd31a1cUL;
    vpi_put_value(vhidx2, &v, &t, vpiNoDelay);

    v.format = vpiVectorVal;
    v.value.vector = vv;
    v.value.vector[1].aval = 0x1c77bb9bUL;
    v.value.vector[0].aval = 0x3784ea09UL;
    vpi_put_value(vhidx3, &v, &t, vpiNoDelay);

    vpi_get_value(vhidx2, &v);
    CHECK_RESULT(v.value.vector[1].aval, 0x12819213UL);
    CHECK_RESULT(v.value.vector[1].bval, 0);

    vpi_get_value(vhidx3, &v);
    CHECK_RESULT(v.value.vector[1].aval, 0x1c77bb9bUL);
    CHECK_RESULT(v.value.vector[1].bval, 0);

    return 0;
}
Esempio n. 14
0
static PLI_INT32 sys_fopenrwa_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle file = vpi_scan(argv);
      s_vpi_value val;
      char *mode;
      unsigned idx, len;

      vpi_free_object(argv);

	/* Get the mode. */
      mode = name + strlen(name) - 1;

	/* Get the filename. */
      val.format = vpiStringVal;
      vpi_get_value(file, &val);

	/* Verify that we have a string and that it is not NULL. */
      if (val.format != vpiStringVal || !*(val.value.str)) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s's file name argument is not a valid string.\n",
	                name);
	    return 0;
      }

	/*
	 * Verify that the file name is composed of only printable
	 * characters.
	 */
      len = strlen(val.value.str);
      for (idx = 0; idx < len; idx++) {
	    if (! isprint(val.value.str[idx])) {
		  char msg [64];
		  snprintf(msg, 64, "WARNING: %s:%d:",
		           vpi_get_str(vpiFile, callh),
		           (int)vpi_get(vpiLineNo, callh));
		  vpi_printf("%s %s's file name argument contains non-"
		             "printable characters.\n", msg, name);
		  vpi_printf("%*s \"%s\"\n", (int) strlen(msg), " ", val.value.str);
		  return 0;
	    }
      }

	/* Open the file and return the result. */
      val.format = vpiIntVal;
      val.value.integer = vpi_fopen(val.value.str, mode);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      return 0;
}
Esempio n. 15
0
static PLI_INT32 PLIbook_PowCalltf(PLI_BYTE8 *user_data)
#endif
{
  s_vpi_value value_s;
  vpiHandle   systf_handle, arg_itr, arg_handle;
  PLI_INT32   base, expo;
  double      result;

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

  //vpi_printf("\n$my_pow PLI calltf function.\n\n");

  systf_handle = vpi_handle(vpiSysTfCall, NULL);
  arg_itr = vpi_iterate(vpiArgument, systf_handle);
  if (arg_itr == NULL) {
    vpi_printf("ERROR: $my_pow failed to obtain systf arg handles\n");
    return(0);
  }

  /* read base from systf arg 1 (compiletf has already verified) */
  arg_handle = vpi_scan(arg_itr);
  value_s.format = vpiIntVal;
  vpi_get_value(arg_handle, &value_s);
  base = value_s.value.integer;

  /* read exponent from systf arg 2 (compiletf has already verified) */
  arg_handle = vpi_scan(arg_itr);
  vpi_free_object(arg_itr); /* not calling scan until returns null */
  vpi_get_value(arg_handle, &value_s);
  expo = value_s.value.integer;

  /* calculate result of base to power of exponent */
  result = pow( (double)base, (double)expo );

  /* write result to simulation as return value $my_pow */
  value_s.value.integer = (PLI_INT32)result;
  vpi_put_value(systf_handle, &value_s, NULL, vpiNoDelay);
  return(0);
}
Esempio n. 16
0
static PLI_INT32 sys_mti_random_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh, argv, seed = 0;
      s_vpi_value val;
      int i_seed = COOKIE;
      struct context_s *context;

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

	/* Get the argument list and look for a seed. If it is there,
	   get the value and reseed the random number generator. */
      callh = vpi_handle(vpiSysTfCall, 0);
      argv = vpi_iterate(vpiArgument, callh);
      val.format = vpiIntVal;
      if (argv) {
	    seed = vpi_scan(argv);
	    vpi_free_object(argv);
	    vpi_get_value(seed, &val);
	    i_seed = val.value.integer;

	      /* Since there is a seed use the current
	         context or create a new one */
	    context = (struct context_s *)vpi_get_userdata(callh);
	    if (!context) {
		  context = (struct context_s *)calloc(1, sizeof(*context));
		  context->mti = NP1;

		    /* squirrel away context */
		  vpi_put_userdata(callh, (void *)context);
	    }

	      /* If the argument is not the Icarus cookie, then
		 reseed context */
	    if (i_seed != COOKIE) sgenrand(context, i_seed);
      } else {
	    /* use global context */
          context = &global_context;
      }

        /* Calculate and return the result */
      val.value.integer = genrand(context);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

        /* mark seed with cookie */
      if (seed && i_seed != COOKIE) {
	    val.value.integer = COOKIE;
	    vpi_put_value(seed, &val, 0, vpiNoDelay);
      }

      return 0;
}
Esempio n. 17
0
static PLI_INT32 sys_dumplimit_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      s_vpi_value val;

      /* Get the value and set the dump limit. */
      val.format = vpiIntVal;
      vpi_get_value(vpi_scan(argv), &val);
      dump_limit = val.value.integer;

      vpi_free_object(argv);
      return 0;
}
static int sys_fgets_calltf(char *name)
{
      unsigned int mcd;
      FILE*fd;
      s_vpi_value value, rval;

      char*txt;
      unsigned txt_len;

      vpiHandle sys  = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle str  = vpi_scan(argv);
      vpiHandle mch  = vpi_scan(argv);

      value.format = vpiIntVal;
      vpi_get_value(mch, &value);
      mcd = value.value.integer;

      fd = vpi_get_file(mcd);
      if (!fd || IS_MCD(mcd)) {
	    rval.format = vpiIntVal;
	    rval.value.integer = 0;
	    vpi_put_value(sys, &rval, 0, vpiNoDelay);
	    return 0;
      }

      txt_len = vpi_get(vpiSize, str) / 8;
      txt = malloc(txt_len + 1);

      if (fgets(txt, txt_len, fd) == 0) {
	    rval.format = vpiIntVal;
	    rval.value.integer = 0;
	    vpi_put_value(sys, &rval, 0, vpiNoDelay);
	    free(txt);
	    return 0;
      }

      rval.format = vpiIntVal;
      rval.value.integer = strlen(txt);
      vpi_put_value(sys, &rval, 0, vpiNoDelay);

      value.format = vpiStringVal;
      value.value.str = txt;
      vpi_put_value(str, &value, 0, vpiNoDelay);

      free(txt);

      return 0;
}
Esempio n. 19
0
/*
 * FUNCTION: uvm_register_set_hdl
 *
 * Given a path, look the path name up using the PLI,
 * and return its 'value'.
 */
void uvm_register_get_hdl(char *path, p_vpi_vecval value)
{
  static int maxsize = -1;
  int i, size, chunks;
  vpiHandle r;
  s_vpi_value value_s;
  r = vpi_handle_by_name(path, 0);
  if(r == 0)
  {
    vpi_printf("FATAL uvm_register : unable to locate hdl path %s\n", path);
    vpi_printf(" Either the name is incorrect, or you may not have PLI visibility to that name");
    vpi_printf(" To gain PLI visibility, make sure you use +acc=rmb when you invoke vlog");
    vpi_printf("   vlog +acc=rmb ....");
    tf_dofinish();
  }
  else
  {
    if(maxsize == -1) 
        maxsize = uvm_register_get_max_size();

    size = vpi_get(vpiSize, r);
    if(size > maxsize)
    {
      vpi_printf("FATAL uvm_register : hdl path '%s' is %0d bits,\n", path, size);
      vpi_printf(" but the maximum size is %0d, redefine using a compile\n", maxsize);
      vpi_printf(" flag. i.e. %s\n", "vlog ... +define+UVM_REGISTER_MAX_WIDTH=<value>");
      tf_dofinish();
    }
    chunks = (size-1)/32 + 1;

    value_s.format = vpiVectorVal;
    vpi_get_value(r, &value_s);
    /*dpi and vpi are reversed*/
    /* -> Not on Questa, and not in the LRM */
    for(i=0;i<chunks; ++i)
    {
#ifdef NCSIM
      // Code for NC.
      // Reverse a/b on NC.
      value[i].aval = value_s.value.vector[i].bval;
      value[i].bval = value_s.value.vector[i].aval;
#else
      // Code for Questa
      value[i].aval = value_s.value.vector[i].aval;
      value[i].bval = value_s.value.vector[i].bval;
#endif
    }
  }
}
Esempio n. 20
0
/*
 * Routine to implement the double argument math functions.
 */
static PLI_INT32 va_double_argument_calltf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
    vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
    s_vpi_value val;
    double first_arg;
    va_double_t* fun_data;

    (void) ud;  /* Not used! */

    /* Retrieve the function and argument data. */
    fun_data = vpi_get_userdata(callh);

    /* Calculate the result */
    val.format = vpiRealVal;
    vpi_get_value(fun_data->arg1, &val);
    first_arg = val.value.real;
    vpi_get_value(fun_data->arg2, &val);
    val.value.real = (fun_data->func)(first_arg, val.value.real);

    /* Return the result */
    vpi_put_value(callh, &val, 0, vpiNoDelay);

    return 0;
}
Esempio n. 21
0
static PLI_INT32 sys_mti_dist_uniform_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh, argv, seed, start, end;
      s_vpi_value val;
      long i_seed, i_start, i_end;

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

	/* Get the argument handles and convert them. */
      callh = vpi_handle(vpiSysTfCall, 0);
      argv = vpi_iterate(vpiArgument, callh);
      seed = vpi_scan(argv);
      start = vpi_scan(argv);
      end = vpi_scan(argv);

      val.format = vpiIntVal;
      vpi_get_value(seed, &val);
      i_seed = val.value.integer;

      vpi_get_value(start, &val);
      i_start = val.value.integer;

      vpi_get_value(end, &val);
      i_end = val.value.integer;

	/* Calculate and return the result. */
      val.value.integer = mti_dist_uniform(&i_seed, i_start, i_end);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

	/* Return the seed. */
      val.value.integer = i_seed;
      vpi_put_value(seed, &val, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Esempio n. 22
0
static PLI_INT32 watchreal_cb(p_cb_data cb)
{
      s_vpi_value value;
      vpiHandle arg = (vpiHandle) (cb->user_data);

      value.format = vpiRealVal;
      vpi_get_value(arg, &value);
      assert(value.format == vpiRealVal);

      vpi_printf("watchreal: %s = %f\n",
		 vpi_get_str(vpiName, arg),
		 value.value.real);

      return 0;
}
Esempio n. 23
0
static PLI_INT32 simbus_poll_calltf(char*my_name)
{
      int poll_state;
      s_vpi_value value;

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

      vpiHandle bus_h = vpi_scan(argv);
      assert(bus_h);

      value.format = vpiIntVal;
      vpi_get_value(bus_h, &value);

      int bus = value.value.integer;
      assert(bus >= 0 && bus < MAX_INSTANCES);

      vpiHandle trig = vpi_scan(argv);
      assert(trig);

      vpi_free_object(argv);

      DEBUG(SIMBUS_DEBUG_CALLS, "Call $poll(%d...)\n", bus);

      poll_state = check_readable(bus);

      value.format = vpiScalarVal;
      value.value.scalar = poll_state? vpi1 : vpi0;
      vpi_put_value(trig, &value, 0, vpiNoDelay);

      if (poll_state == 0) {
	    struct t_cb_data cb_data;
	    struct t_vpi_time cb_time;
	    cb_time.type = vpiSuppressTime;
	    cb_data.reason = cbReadWriteSynch;
	    cb_data.cb_rtn = poll_for_simbus_bus;
	    cb_data.time   = &cb_time;
	    vpi_register_cb(&cb_data);

	    instance_table[bus].trig = trig;

      } else {
	    instance_table[bus].trig = 0;
      }

      DEBUG(SIMBUS_DEBUG_CALLS, "return $poll(%d...)\n", bus);
      return 0;
}
Esempio n. 24
0
File: vpi1.c Progetto: Jonsba/ghdl
void
vpi_proc (void)
{
  vpiHandle net;
  s_vpi_value val;

  net = vpi_handle_by_name ("test_load.dat_o", NULL);
  if (net == NULL)
    {
      printf ("cannot get net\n");
      return;
    }
  val.format = vpiBinStrVal;
  vpi_get_value (net, &val);
  printf ("value: %s\n", val.value.str);
}
Esempio n. 25
0
/*
 * Implement $fflush system function
 */
static PLI_INT32 sys_fflush_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle arg;
      s_vpi_value val;
      PLI_UINT32 fd_mcd;
      FILE *fp;
      errno = 0;

	/* If we have no argument then flush all the streams. */
      if (argv == 0) {
	    fflush(NULL);
	    return 0;
      }

	/* Get the file/MC descriptor and verify that it is valid. */
      arg = vpi_scan(argv);
      vpi_free_object(argv);
      val.format = vpiIntVal;
      vpi_get_value(arg, &val);
      fd_mcd = val.value.integer;

	/* If the MCD is zero we have nothing to do so just return. */
      if (fd_mcd == 0) return 0;

      if ((! IS_MCD(fd_mcd) && vpi_get_file(fd_mcd) == NULL) ||
          ( IS_MCD(fd_mcd) && vpi_mcd_printf(fd_mcd, "%s", "") == EOF) ||
          (! fd_mcd)) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor/MCD (0x%x) given to %s.\n",
	               (unsigned int)fd_mcd, name);
	    errno = EBADF;
	    return 0;
      }

      if (IS_MCD(fd_mcd)) {
	    vpi_mcd_flush(fd_mcd);
      } else {
	      /* If we have a valid file descriptor flush the file. */
	    fp = vpi_get_file(fd_mcd);
	    if (fp) fflush(fp);
      }

      return 0;
}
Esempio n. 26
0
static PLI_INT32 sys_dumplimit_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      s_vpi_value val;

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

      /* Get the value and set the dump limit. */
      val.format = vpiIntVal;
      vpi_get_value(vpi_scan(argv), &val);
      dump_limit = val.value.integer;
      fstWriterSetDumpSizeLimit(dump_file, dump_limit);

      vpi_free_object(argv);
      return 0;
}
Esempio n. 27
0
static PLI_INT32 listparams_calltf(PLI_BYTE8*name)
#endif
{
      vpiHandle sys  = vpi_handle(vpiSysTfCall,0);
      vpiHandle scope= vpi_handle(vpiScope, sys);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle item;

      while ( (item = vpi_scan(argv)) ) {
	    s_vpi_value value;
	    value.format = vpiStringVal;
	    vpi_get_value(item, &value);
	    param_by_name(scope, value.value.str);
      }

      return 0;
}
Esempio n. 28
0
static PLI_INT32 next_sim_time_callback(struct t_cb_data*cb)
{
      vpiHandle obj = (vpiHandle)cb->user_data;
      s_vpi_value val;
      s_vpi_time  tim;

      val.format = vpiIntVal;
      vpi_get_value(obj, &val);

      tim.type = vpiSimTime;
      vpi_get_time(obj, &tim);

      vpi_printf("Callback time=%d %s=%d\n", (int)tim.low,
		 vpi_get_str(vpiName, obj),
		 (int)val.value.integer);
      return 0;
}
Esempio n. 29
0
int _mon_check_value_callbacks() {
    vpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.count", NULL);
    CHECK_RESULT_NZ(vh1);

    s_vpi_value v;
    v.format = vpiIntVal;
    vpi_get_value(vh1, &v);

    t_cb_data cb_data;
    cb_data.reason = cbValueChange;
    cb_data.cb_rtn = _value_callback;
    cb_data.obj = vh1;
    cb_data.value = &v;

    vpiHandle vh = vpi_register_cb(&cb_data);
    CHECK_RESULT_NZ(vh);

    vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.half_count", NULL);
    CHECK_RESULT_NZ(vh1);

    cb_data.obj = vh1;
    cb_data.cb_rtn = _value_callback_half;

    vh = vpi_register_cb(&cb_data);
    CHECK_RESULT_NZ(vh);

    vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.quads", NULL);
    CHECK_RESULT_NZ(vh1);

    v.format = vpiVectorVal;
    cb_data.obj = vh1;
    cb_data.cb_rtn = _value_callback_quad;

    vh = vpi_register_cb(&cb_data);
    CHECK_RESULT_NZ(vh);

    vh1 = vpi_handle_by_index(vh1, 2);
    CHECK_RESULT_NZ(vh1);

    cb_data.obj = vh1;
    cb_data.cb_rtn = _value_callback_quad;

    vh = vpi_register_cb(&cb_data);
    CHECK_RESULT_NZ(vh);
    return 0;
}
Esempio n. 30
0
static PLI_INT32 sys_sdf_annotate_calltf(PLI_BYTE8*name)
{
      s_vpi_value value;
      vpiHandle sys = vpi_handle(vpiSysTfCall,0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);

	/* The first argument is the path to the SDF file. */
      vpiHandle path = vpi_scan(argv);
      assert(path);

      value.format = vpiStringVal;
      vpi_get_value(path, &value);

      if ((value.format != vpiStringVal) || !value.value.str) {
	    vpi_printf("ERROR: %s: File name argument (type=%d)"
		       " does not have a string value.\n",
		       name, vpi_get(vpiType, path));
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

      char*path_str = strdup(value.value.str);
      FILE*sdf_fd = fopen(path_str, "r");
      if (sdf_fd == 0) {
	    vpi_printf("ERROR: %s: Unable to open SDF file `%s'."
		       " Skipping annotation.\n", name, path_str);
	    return 0;
      }

	/* The optional second argument is the scope to annotate. */
      sdf_scope = vpi_scan(argv);
      if (sdf_scope)
	    vpi_free_object(argv);
      if (sdf_scope == 0) {
	    sdf_scope = vpi_handle(vpiScope,sys);
      }

      sdf_cur_cell = 0;

      sdf_process_file(sdf_fd, path_str);

      fclose(sdf_fd);
      free(path_str);
      return 0;
}