Ejemplo n.º 1
0
static PLI_INT32
EndOfCompile(s_cb_data *data)
{
    s_vpi_time timerec = { vpiSimTime, 0, 0, 0 };
    s_vpi_value val;

    vpiHandle b0_handle;
    vpiHandle wr_handle;
    vpiHandle in_handle;

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

    b0_handle = vpi_handle_by_name("test.B0", 0);
    assert(b0_handle);

    wr_handle = vpi_handle_by_name("test.WR", 0);
    assert(wr_handle);

    in_handle = vpi_handle_by_name("test.IN", 0);
    assert(in_handle);

    timerec.low = 500;
    val.value.str = "01";
    val.format = vpiBinStrVal;
    vpi_put_value(in_handle, &val,  &timerec, vpiInertialDelay);

    val.value.str = "zz";
    val.format = vpiBinStrVal;
    vpi_put_value(b0_handle, &val,  &timerec, vpiInertialDelay);

    val.format = vpiIntVal;

    val.value.integer = 0;
    vpi_put_value(wr_handle, &val, &timerec, vpiInertialDelay);

    timerec.low = 500;
    val.value.integer = 0;
    vpi_put_value(wr_handle, &val,  &timerec, vpiInertialDelay);

    val.value.integer = 1;
    timerec.low = 1000;
    vpi_put_value(wr_handle, &val,  &timerec, vpiInertialDelay);

    timerec.low = 1500;
    vpi_put_value(wr_handle, &val,  &timerec, vpiInertialDelay);

    timerec.low = 2000;
    val.value.integer = 0;
    vpi_put_value(wr_handle, &val,  &timerec, vpiInertialDelay);

    timerec.low = 3000;
    val.value.integer = 0;
    vpi_put_value(wr_handle, &val,  &timerec, vpiInertialDelay);

    return 0;
}
Ejemplo n.º 2
0
/*
 * Given a path, look the path name up using the PLI,
 * and set it to 'value'.
 */
static int uvm_hdl_set_vlog(char *path, p_vpi_vecval value, PLI_INT32 flag)
{
  static int maxsize = -1;
  vpiHandle r;
  s_vpi_value value_s = { vpiIntVal, { 0 } };
  s_vpi_time  time_s = { vpiSimTime, 0, 0, 0.0 };

  //vpi_printf("uvm_hdl_set_vlog(%s,%0x)\n",path,value[0].aval);

  #ifdef QUESTA
  int result = 0;
  result = uvm_hdl_set_vlog_partsel(path,value,flag);
  if (result < 0)
    return 0;
  if (result == 1)
    return 1;

  if (!strncmp(path,"$root.",6))
    r = vpi_handle_by_name(path+6, 0);
  else
  #endif
  r = vpi_handle_by_name(path, 0);

  if(r == 0)
  {
      vpi_printf((PLI_BYTE8*) "UVM_ERROR: set: unable to locate hdl path (%s)\n",path);
      vpi_printf((PLI_BYTE8*) " Either the name is incorrect, or you may not have PLI/ACC visibility to that name\n");
    return 0;
  }
  else
  {
    if(maxsize == -1) 
        maxsize = uvm_hdl_max_width();

    if (flag == vpiReleaseFlag) {
      //size = vpi_get(vpiSize, r);
      //value_p = (p_vpi_vecval)(malloc(((size-1)/32+1)*8*sizeof(s_vpi_vecval)));
      //value = &value_p;
    }
    value_s.format = vpiVectorVal;
    value_s.value.vector = value;
    vpi_put_value(r, &value_s, &time_s, flag);  
    //if (value_p != NULL)
    //  free(value_p);
    if (value == NULL) {
      value = value_s.value.vector;
    }
  }
#ifndef VCS
  //vpi_release_handle(r);
#endif
  return 1;
}
Ejemplo n.º 3
0
int evaScopeGet(char *path, int *succ){
  vpiHandle   net;
  s_vpi_value val;
  net = vpi_handle_by_name(path, NULL);

  if( net == NULL){
    fprintf(stderr,"@evaScopeGet: %s  not exist !\n", path);
    return 0;
  }

  int Vector_size = vpi_get(vpiSize, net);

  if(Vector_size > 32){
    fprintf(stderr,"@evaScopeGet: %s vector size %d > 32 not support !\n", path, Vector_size);
    *succ = 0;
    return 0;
  }{
    val.format = vpiIntVal;
    vpi_get_value(net, & val);
    *succ = 1;

    return val.value.integer;
  }
  
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: Jwomers/migen
static int h_write(char *name, int index, int nchunks, const unsigned char *chunks, void *user)
{
	vpiHandle item;
	s_vpi_vecval vector[64];
	int i;
	s_vpi_value value;
	
	item = vpi_handle_by_name(name, NULL);
	if(item == NULL) {
		fprintf(stderr, "Attempted to write non-existing signal %s\n", name);
		return 0;
	}
	if(vpi_get(vpiType, item) == vpiMemory)
		item = vpi_handle_by_index(item, index);
	else
		assert(index == 0);
	
	assert(nchunks <= 255);
	for(i=0;i<64;i++) {
		vector[i].aval = 0;
		vector[i].bval = 0;
	}
	for(i=0;i<nchunks;i++)
		vector[i/4].aval |= chunks[i] << 8*(i % 4);
	
	value.format = vpiVectorVal;
	value.value.vector = vector;
	vpi_put_value(item, &value, &zero_delay, vpiInertialDelay);
	
	return 1;
}
Ejemplo n.º 5
0
int _mon_check_string() {
    static struct {
        const char *name;
        const char *initial;
        const char *value;
    } text_test_obs[] = {
        {"t.text_byte", "B", "xxA"}, // x's dropped
        {"t.text_half", "Hf", "xxT2"}, // x's dropped
        {"t.text_word", "Word", "Tree"},
        {"t.text_long", "Long64b", "44Four44"},
        {"t.text"     , "Verilog Test module", "lorem ipsum"},
    };

    for (int i=0; i<5; i++) {
        VlVpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)text_test_obs[i].name, NULL);
        CHECK_RESULT_NZ(vh1);

        s_vpi_value v;
        s_vpi_time t = { vpiSimTime, 0, 0};
        s_vpi_error_info e;

        v.format = vpiStringVal;
        vpi_get_value(vh1, &v);
        if (vpi_chk_error(&e)) {
            printf("%%vpi_chk_error : %s\n", e.message);
        }

        CHECK_RESULT_CSTR_STRIP(v.value.str, text_test_obs[i].initial);

        v.value.str = (PLI_BYTE8*)text_test_obs[i].value;
        vpi_put_value(vh1, &v, &t, vpiNoDelay);
    }

    return 0;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
/*
 * FUNCTION: uvm_register_check_hdl
 *
 * Given a path, look the path name up using the PLI,
 * but don't set or get. Just check.
 *
 * Return 0 if NOT found.
 * Return 1 if found.
 */
int uvm_register_check_hdl(char *path)
{
  vpiHandle r = vpi_handle_by_name(path, 0);
  if(r == 0)
    return 0;
  else 
    return 1;
}
Ejemplo n.º 8
0
/*
 * Given a path, look the path name up using the PLI,
 * but don't set or get. Just check.
 *
 * Return 0 if NOT found.
 * Return 1 if found.
 */
int uvm_hdl_check_path(char *path)
{
  vpiHandle r;

  #ifdef QUESTA
  if (!strncmp(path,"$root.",6)) {
    r = vpi_handle_by_name(path+6, 0);
  }
  else
  #endif
  r = vpi_handle_by_name(path, 0);

  if(r == 0)
      return 0;
  else 
    return 1;
}
Ejemplo n.º 9
0
/*
 * FUNCTION: uvm_register_set_hdl
 *
 * Given a path, look the path name up using the PLI,
 * and set it to 'value'.
 */
void uvm_register_set_hdl(char *path, p_vpi_vecval value)
{
  static int maxsize = -1;
  int i, size, chunks;
  vpiHandle r;
  s_vpi_value value_s;
  p_vpi_vecval value_p;
  s_vpi_time  time_s = { vpiSimTime, 0, 0 };
  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();

#ifdef NCSIM
    // Code for NC
    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;
    // Probably should be:
    //   value_p = (p_vpi_vecval)(calloc(1, chunks*8*sizeof(s_vpi_vecval)));
    value_p = (p_vpi_vecval)(malloc(chunks*8*sizeof(s_vpi_vecval)));
    value_s.format = vpiVectorVal;
    value_s.value.vector = value_p;
    /* Copy a/b, reversing on NC. */
    /*dpi and vpi are reversed*/
    /*  - only in NC. In ModelSim they are the same. */
    for(i=0;i<chunks; ++i)
    {
      // Reverse a/b on NC.
      value_p[i].aval = value[i].bval;
      value_p[i].bval = value[i].aval;
    }
    vpi_put_value(r, &value_s, &time_s, vpiNoDelay);  
    free (value_p);
#else
    // Code for Questa
    value_s.format = vpiVectorVal;
    value_s.value.vector = value;
    vpi_put_value(r, &value_s, &time_s, vpiNoDelay);  
#endif
  }
  return;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: Jwomers/migen
static int h_read(char *name, int index, void *user)
{
	struct migensim_softc *sc = (struct migensim_softc *)user;
	vpiHandle item;
	s_vpi_value value;
	int size;
	int i;
	int nvals;
	unsigned int vals[64];
	int nchunks;
	unsigned char chunks[255];
	
	item = vpi_handle_by_name(name, NULL);
	if(item == NULL) {
		fprintf(stderr, "Attempted to read non-existing signal %s\n", name);
		return 0;
	}
	if(vpi_get(vpiType, item) == vpiMemory)
		item = vpi_handle_by_index(item, index);
	else
		assert(index == 0);
	
	value.format = vpiVectorVal;
	vpi_get_value(item, &value);
	size = vpi_get(vpiSize, item);
	nvals = (size + 31)/32;
	assert(nvals <= 64);
	for(i=0;i<nvals;i++)
		vals[i] = value.value.vector[i].aval & ~value.value.vector[i].bval;
	nchunks = (size + 7)/8;
	assert(nchunks <= 255);
	for(i=0;i<nchunks;i++) {
		switch(i % 4) {
			case 0:
				chunks[i] = vals[i/4] & 0xff;
				break;
			case 1:
				chunks[i] = (vals[i/4] & 0xff00) >> 8;
				break;
			case 2:
				chunks[i] = (vals[i/4] & 0xff0000) >> 16;
				break;
			case 3:
				chunks[i] = (vals[i/4] & 0xff000000) >> 24;
				break;
		}
	}
	
	if(!ipc_read_reply(sc->ipc, nchunks, chunks)) {
		perror("ipc_read_reply");
		return 0;
	}
	
	return 1;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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
    }
  }
}
Ejemplo n.º 14
0
Archivo: vpi1.c Proyecto: 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);
}
Ejemplo n.º 15
0
int tenyr_sim_genesis(p_cb_data data)
{
    struct tenyr_sim_state *d = *(void**)data->user_data = calloc(1, sizeof *d);

#if DEBUG
    d->debug = DEBUG;
#endif

    if (d->debug > 4)
        vpi_printf("%s ; userdata = %p\n", __func__, data->user_data);

    extern int tenyr_sim_clock(p_cb_data data);
    vpiHandle clock = vpi_handle_by_name("Top.tenyr.clk_core0", NULL);
    s_cb_data cbd = {
        .reason    = cbValueChange,
        .cb_rtn    = tenyr_sim_clock,
        .obj       = clock,
        .time      = &(s_vpi_time ){ .type   = vpiSimTime },
        .value     = &(s_vpi_value){ .format = vpiIntVal  },
        .user_data = data->user_data,
Ejemplo n.º 16
0
static PLI_INT32
CallbackRegister(s_cb_data *data)
{
    vpiHandle hand;
    s_cb_data cb_data;
    s_vpi_time timerec = { vpiSimTime, 0, 0, 0 };

    hand = vpi_handle_by_name("test.e", 0);
    assert(hand);

    cb_data.time = &timerec;
    cb_data.value = 0;
    cb_data.user_data = (char *)hand;
    cb_data.obj = hand;
    cb_data.reason = cbValueChange;
    cb_data.cb_rtn = Callback;
    Handle = vpi_register_cb(&cb_data);

    return (0);
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
GpiObjHdl* VpiImpl::native_check_create(std::string &name, GpiObjHdl *parent)
{
    int32_t type;
    vpiHandle new_hdl;
    GpiObjHdl *new_obj = NULL; 
    std::vector<char> writable(name.begin(), name.end());
    writable.push_back('\0');

    new_hdl = vpi_handle_by_name(&writable[0], NULL);

    if (!new_hdl)
        return NULL;

    if (vpiUnknown == (type = vpi_get(vpiType, new_hdl))) {
        vpi_free_object(new_hdl);
        return new_obj;
    }

    /* What sort of isntance is this ?*/
    switch (type) {
        case vpiNet:
        case vpiReg:
        case vpiParameter:
            new_obj = new VpiSignalObjHdl(this, new_hdl);
            break;
        case vpiStructVar:
        case vpiModule:
        case vpiInterface:
        case vpiModport:
            new_obj = new GpiObjHdl(this, new_hdl);
            break;
        default:
            LOG_INFO("Not sure what to do with type %d for entity (%s)", type, name.c_str());
            return NULL;
    }

    new_obj->initialise(name);

    return new_obj;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
static PLI_INT32
EndOfCompile(s_cb_data *data)
{
    vpiHandle hand;
    s_vpi_time timerec = { vpiSimTime, 0, 0, 0 };
    s_vpi_value val;
    int i;

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

    hand = vpi_handle_by_name("test.r", 0);
    assert(hand);

    // Get current state
    val.format = vpiIntVal;
    vpi_get_value(hand, &val);

    // Add a few transitions
    for (i = 0; i < 6; i++) {

	if (i < 3) {
	    // delay 10+i time units
	    timerec.low = 1000 * (i + 1);
	} else {
	    timerec.type = vpiScaledRealTime;
	    timerec.low = 0;
	    timerec.real = 10000.0 * (i+1);
	}

	// Toggle state
	val.value.integer ^= 1;

	// Put new state
	vpi_put_value(hand, &val, &timerec, vpiPureTransportDelay);
    }

    return 0;
}
Ejemplo n.º 21
0
int _mon_check_varlist() {
    const char* p;

    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t.sub", NULL);
    CHECK_RESULT_NZ(vh2);

    VlVpiHandle vh10 = vpi_iterate(vpiReg, vh2);
    CHECK_RESULT_NZ(vh10);

    VlVpiHandle vh11 = vpi_scan(vh10);
    CHECK_RESULT_NZ(vh11);
    p = vpi_get_str(vpiFullName, vh11);
    CHECK_RESULT_CSTR(p, "t.sub.subsig1");

    VlVpiHandle vh12 = vpi_scan(vh10);
    CHECK_RESULT_NZ(vh12);
    p = vpi_get_str(vpiFullName, vh12);
    CHECK_RESULT_CSTR(p, "t.sub.subsig2");

    VlVpiHandle vh13 = vpi_scan(vh10);
    CHECK_RESULT(vh13,0);

    return 0;
}
Ejemplo n.º 22
0
static void scan_item(unsigned depth, vpiHandle item, int skip)
{
      struct t_cb_data cb;
      struct vcd_info* info;

      enum fstVarType type = FST_VT_MAX;
      enum fstScopeType stype = FST_ST_MAX;
      enum fstVarDir dir;
      const char *name;
      const char *fullname;
      char *escname;
      const char *ident;
      fstHandle new_ident;
      int nexus_id;
      unsigned size;
      PLI_INT32 item_type;

	/* Get the displayed type for the various $var and $scope types. */
	/* Not all of these are supported now, but they should be in a
	 * future development version. */
      item_type = vpi_get(vpiType, item);
      switch (item_type) {
	  case vpiNamedEvent: type = FST_VT_VCD_EVENT; break;
	  case vpiIntVar:
	  case vpiIntegerVar: type = FST_VT_VCD_INTEGER; break;
	  case vpiParameter:  type = FST_VT_VCD_PARAMETER; break;
	    /* Icarus converts realtime to real. */
	  case vpiRealVar:    type = FST_VT_VCD_REAL; break;
	  case vpiMemoryWord:
	  case vpiBitVar:
	  case vpiByteVar:
	  case vpiShortIntVar:
	  case vpiLongIntVar:
	  case vpiReg:        type = FST_VT_VCD_REG; break;
	    /* Icarus converts a time to a plain register. */
	  case vpiTimeVar:    type = FST_VT_VCD_TIME; break;
	  case vpiNet:
	    switch (vpi_get(vpiNetType, item)) {
		case vpiWand:    type = FST_VT_VCD_WAND; break;
		case vpiWor:     type = FST_VT_VCD_WOR; break;
		case vpiTri:     type = FST_VT_VCD_TRI; break;
		case vpiTri0:    type = FST_VT_VCD_TRI0; break;
		case vpiTri1:    type = FST_VT_VCD_TRI1; break;
		case vpiTriReg:  type = FST_VT_VCD_TRIREG; break;
		case vpiTriAnd:  type = FST_VT_VCD_TRIAND; break;
		case vpiTriOr:   type = FST_VT_VCD_TRIOR; break;
		case vpiSupply1: type = FST_VT_VCD_SUPPLY1; break;
		case vpiSupply0: type = FST_VT_VCD_SUPPLY0; break;
		default:         type = FST_VT_VCD_WIRE; break;
	    }
	    break;

	  case vpiNamedBegin: stype = FST_ST_VCD_BEGIN; break;
	  case vpiNamedFork:  stype = FST_ST_VCD_FORK; break;
	  case vpiFunction:   stype = FST_ST_VCD_FUNCTION; break;
	  case vpiGenScope:   stype = FST_ST_VCD_GENERATE; break;
	  case vpiModule:     stype = FST_ST_VCD_MODULE; break;
	  case vpiTask:       stype = FST_ST_VCD_TASK; break;

	  default:
	    vpi_printf("FST warning: $dumpvars: Unsupported argument "
	               "type (%s)\n", vpi_get_str(vpiType, item));
	    return;
      }

	/* Do some special processing/checking on array words. Dumping
	 * array words is an Icarus extension. */
      if (item_type == vpiMemoryWord) {
	      /* Turn a non-constant array word select into a constant
	       * word select. */
	    if (vpi_get(vpiConstantSelect, item) == 0) {
		  vpiHandle array = vpi_handle(vpiParent, item);
		  PLI_INT32 idx = vpi_get(vpiIndex, item);
		  item = vpi_handle_by_index(array, idx);
	    }

	      /* An array word is implicitly escaped so look for an
	       * escaped identifier that this could conflict with. */
	      /* This does not work as expected since we always find at
	       * least the array word. We likely need a custom routine. */
            if (vpi_get(vpiType, item) == vpiMemoryWord &&
                vpi_handle_by_name(vpi_get_str(vpiFullName, item), 0)) {
		  vpi_printf("FST warning: array word %s will conflict "
		             "with an escaped identifier.\n",
		             vpi_get_str(vpiFullName, item));
            }
      }

      fullname = vpi_get_str(vpiFullName, item);

	/* Generate the $var or $scope commands. */
      switch (item_type) {
	  case vpiParameter:
	    vpi_printf("FST sorry: $dumpvars: can not dump parameters.\n");
	    break;

	  case vpiNamedEvent:
	  case vpiIntegerVar:
	  case vpiBitVar:
	  case vpiByteVar:
	  case vpiShortIntVar:
	  case vpiIntVar:
	  case vpiLongIntVar:
	  case vpiRealVar:
	  case vpiMemoryWord:
	  case vpiReg:
	  case vpiTimeVar:
	  case vpiNet:

	      /* If we are skipping all signal or this is in an automatic
	       * scope then just return. */
            if (skip || vpi_get(vpiAutomatic, item)) return;

	      /* Skip this signal if it has already been included.
	       * This can only happen for implicitly given signals. */
	    if (vcd_names_search(&fst_var, fullname)) return;

	      /* Declare the variable in the FST file. */
	    name = vpi_get_str(vpiName, item);
	    if (is_escaped_id(name)) {
		  escname = malloc(strlen(name) + 2);
		  sprintf(escname, "\\%s", name);
	    } else escname = strdup(name);

	      /* Some signals can have an alias so handle that. */
	    nexus_id = vpi_get(_vpiNexusId, item);

	    ident = 0;
	    if (nexus_id) ident = find_nexus_ident(nexus_id);

	      /* Named events do not have a size, but other tools use
	       * a size of 1 and some viewers do not accept a width of
	       * zero so we will also use a width of one for events. */
	    if (item_type == vpiNamedEvent) size = 1;
	    else size = vpi_get(vpiSize, item);
	      /* The FST format supports a port direction so if the net
	       * is a port set the direction to one of the following:
	       *   FST_VD_INPUT, FST_VD_OUTPUT or FST_VD_INOUT */
	    dir = FST_VD_IMPLICIT;

	    if (size > 1 || vpi_get(vpiLeftRange, item) != 0) {
		  char *buf = malloc(strlen(escname) + 65);
		  sprintf(buf, "%s [%i:%i]", escname,
                            (int)vpi_get(vpiLeftRange, item),
                            (int)vpi_get(vpiRightRange, item));

		  new_ident = fstWriterCreateVar(dump_file, type,
		                                 dir, size, buf,
		                                 (fstHandle)(long)ident);
		  free(buf);
	    } else {
		  new_ident = fstWriterCreateVar(dump_file, type,
		                                 dir, size, escname,
		                                 (fstHandle)(long)ident);
	    }
	    free(escname);

	    if (!ident) {
		  if (nexus_id) set_nexus_ident(nexus_id,
		                                (const char *)(long)new_ident);

		    /* Add a callback for the signal. */
		  info = malloc(sizeof(*info));

		  info->time.type = vpiSimTime;
		  info->item  = item;
		  info->handle = new_ident;
		  info->scheduled = 0;

		  cb.time      = &info->time;
		  cb.user_data = (char*)info;
		  cb.value     = NULL;
		  cb.obj       = item;
		  cb.reason    = cbValueChange;
		  cb.cb_rtn    = variable_cb_1;

		  info->dmp_next = 0;
		  info->next  = vcd_list;
		  vcd_list    = info;

		  info->cb    = vpi_register_cb(&cb);
	    }

	    break;

	  case vpiModule:
	  case vpiGenScope:
	  case vpiFunction:
	  case vpiTask:
	  case vpiNamedBegin:
	  case vpiNamedFork:

	    if (depth > 0) {
		  char *instname;
		  char *defname = NULL;
		  /* list of types to iterate upon */
		  static int types[] = {
			/* Value */
			vpiNamedEvent,
			vpiNet,
			/* vpiParameter, */
			vpiReg,
			vpiVariables,
			/* Scope */
			vpiFunction,
			vpiGenScope,
			vpiModule,
			vpiNamedBegin,
			vpiNamedFork,
			vpiTask,
			-1
		  };
		  int i;
		  int nskip = (vcd_names_search(&fst_tab, fullname) != 0);

		    /* We have to always scan the scope because the
		     * depth could be different for this call. */
		  if (nskip) {
			vpi_printf("FST warning: ignoring signals in "
			           "previously scanned scope %s.\n", fullname);
		  } else {
			vcd_names_add(&fst_tab, fullname);
		  }

		    /* Set the file and line information for this scope.
		     * Everything has instance information. Only a module
		     * has separate definition information. */
		  instname = vpi_get_str(vpiFile, item);
		  fstWriterSetSourceInstantiationStem(dump_file, instname,
		      (int)vpi_get(vpiLineNo, item), 0);
		  if (item_type == vpiModule) {
			fstWriterSetSourceStem(dump_file,
			    vpi_get_str(vpiDefFile, item),
			    (int)vpi_get(vpiDefLineNo, item), 0);
		  } else {
			fstWriterSetSourceStem(dump_file, instname,
			    (int)vpi_get(vpiLineNo, item), 0);
		  }

		    /* This must be done before the other name is fetched
		     * and the string must always be freed */
		  if (item_type == vpiModule) {
			defname = strdup(vpi_get_str(vpiDefName, item));
		  }
		  name = vpi_get_str(vpiName, item);
		    /* If the two names match only use the vpiName. */
		  if (defname && (strcmp(defname, name) == 0)) {
			free(defname);
			defname = NULL;
		  }
		  fstWriterSetScope(dump_file, stype, name, defname);
		  free(defname);

		  for (i=0; types[i]>0; i++) {
			vpiHandle hand;
			vpiHandle argv = vpi_iterate(types[i], item);
			while (argv && (hand = vpi_scan(argv))) {
			      scan_item(depth-1, hand, nskip);
			}
		  }

		    /* Sort any signals that we added above. */
		  fstWriterSetUpscope(dump_file);
	    }
	    break;
      }
}
Ejemplo n.º 23
0
static void scan_item(unsigned depth, vpiHandle item, int skip)
{
      struct t_cb_data cb;
      struct vcd_info* info;

      const char* name;
      const char* ident;
      int nexus_id;

      /* list of types to iterate upon */
      int i;
      static int types[] = {
	    /* Value */
	    vpiNet,
	    vpiReg,
	    vpiVariables,
	    /* Scope */
	    vpiFunction,
	    vpiModule,
	    vpiNamedBegin,
	    vpiNamedFork,
	    vpiTask,
	    -1
      };

      switch (vpi_get(vpiType, item)) {

	  case vpiMemoryWord:
	    if (vpi_get(vpiConstantSelect, item) == 0) {
		    /* Turn a non-constant array word select into a
		     * constant word select. */
		  vpiHandle array = vpi_handle(vpiParent, item);
		  PLI_INT32 idx = vpi_get(vpiIndex, item);
		  item = vpi_handle_by_index(array, idx);
	    }
	  case vpiIntegerVar:
	  case vpiBitVar:
	  case vpiByteVar:
	  case vpiShortIntVar:
	  case vpiIntVar:
	  case vpiLongIntVar:
	  case vpiTimeVar:
	  case vpiReg:
	  case vpiNet:

	      /* An array word is implicitly escaped so look for an
	       * escaped identifier that this could conflict with. */
            if (vpi_get(vpiType, item) == vpiMemoryWord &&
                vpi_handle_by_name(vpi_get_str(vpiFullName, item), 0)) {
		  vpi_printf("LXT2 warning: dumping array word %s will "
		             "conflict with an escaped identifier.\n",
		             vpi_get_str(vpiFullName, item));
            }

            if (skip || vpi_get(vpiAutomatic, item)) break;

	    name = vpi_get_str(vpiName, item);
	    nexus_id = vpi_get(_vpiNexusId, item);
	    if (nexus_id) {
		  ident = find_nexus_ident(nexus_id);
	    } else {
		  ident = 0;
	    }

	    if (!ident) {
		  char*tmp = create_full_name(name);
		  ident = strdup_sh(&name_heap, tmp);
		  free(tmp);

		  if (nexus_id) set_nexus_ident(nexus_id, ident);

		  info = new_vcd_info();

		  info->item  = item;
		  info->sym   = lxt2_wr_symbol_add(dump_file, ident,
		                                   0 /* array rows */,
		                                   vpi_get(vpiLeftRange, item),
		                                   vpi_get(vpiRightRange, item),
		                                   LXT2_WR_SYM_F_BITS);
		  info->dmp_next = 0;

		  cb.time      = 0;
		  cb.user_data = (char*)info;
		  cb.value     = NULL;
		  cb.obj       = item;
		  cb.reason    = cbValueChange;
		  cb.cb_rtn    = variable_cb_1;

		  info->cb    = vpi_register_cb(&cb);

	    } else {
		  char *n = create_full_name(name);
		  lxt2_wr_symbol_alias(dump_file, ident, n,
				       vpi_get(vpiSize, item)-1, 0);
		  free(n);
            }

	    break;

	  case vpiRealVar:

            if (skip || vpi_get(vpiAutomatic, item)) break;

	    name = vpi_get_str(vpiName, item);
	    { char*tmp = create_full_name(name);
	      ident = strdup_sh(&name_heap, tmp);
	      free(tmp);
	    }
	    info = new_vcd_info();

	    info->item = item;
	    info->sym  = lxt2_wr_symbol_add(dump_file, ident,
	                                    0 /* array rows */,
	                                    vpi_get(vpiSize, item)-1,
	                                    0, LXT2_WR_SYM_F_DOUBLE);
	    info->dmp_next = 0;

	    cb.time      = 0;
	    cb.user_data = (char*)info;
	    cb.value     = NULL;
	    cb.obj       = item;
	    cb.reason    = cbValueChange;
	    cb.cb_rtn    = variable_cb_1;

	    info->cb    = vpi_register_cb(&cb);

	    break;

	  case vpiModule:
	  case vpiNamedBegin:
	  case vpiTask:
	  case vpiFunction:
	  case vpiNamedFork:

	    if (depth > 0) {
		  int nskip;
		  vpiHandle argv;

		  const char* fullname =
			vpi_get_str(vpiFullName, item);

#if 0
		  vpi_printf("LXT2 info: scanning scope %s, %u levels\n",
		             fullname, depth);
#endif
		  nskip = vcd_scope_names_test(fullname);

		  if (!nskip)
			vcd_scope_names_add(fullname);
		  else
		    vpi_printf("LXT2 warning: ignoring signals in "
		               "previously scanned scope %s\n", fullname);

		  name = vpi_get_str(vpiName, item);

                  push_scope(name);

		  for (i=0; types[i]>0; i++) {
			vpiHandle hand;
			argv = vpi_iterate(types[i], item);
			while (argv && (hand = vpi_scan(argv))) {
			      scan_item(depth-1, hand, nskip);
			}
		  }

                  pop_scope();
	    }
	    break;

	  default:
	    vpi_printf("LXT2 warning: $dumpvars: Unsupported parameter "
	               "type (%s)\n", vpi_get_str(vpiType, item));
      }

}
Ejemplo n.º 24
0
static void scan_item(unsigned depth, vpiHandle item, int skip)
{
      struct t_cb_data cb;
      struct vcd_info* info;

      const char *type;
      const char *name;
      const char *fullname;
      const char *prefix;
      const char *ident;
      int nexus_id;
      unsigned size;
      PLI_INT32 item_type;

	/* Get the displayed type for the various $var and $scope types. */
	/* Not all of these are supported now, but they should be in a
	 * future development version. */
      item_type = vpi_get(vpiType, item);
      switch (item_type) {
	  case vpiNamedEvent: type = "event"; break;
	  case vpiIntVar:
	  case vpiIntegerVar: type = "integer"; break;
	  case vpiParameter:  type = "parameter"; break;
	    /* Icarus converts realtime to real. */
	  case vpiRealVar:    type = "real"; break;
	  case vpiMemoryWord:
	  case vpiBitVar:
	  case vpiByteVar:
	  case vpiShortIntVar:
	  case vpiLongIntVar:
	  case vpiReg:        type = "reg"; break;
	    /* Icarus converts a time to a plain register. */
	  case vpiTimeVar:    type = "time"; break;
	  case vpiNet:
	    switch (vpi_get(vpiNetType, item)) {
		case vpiWand:    type = "wand"; break;
		case vpiWor:     type = "wor"; break;
		case vpiTri:     type = "tri"; break;
		case vpiTri0:    type = "tri0"; break;
		case vpiTri1:    type = "tri1"; break;
		case vpiTriReg:  type = "trireg"; break;
		case vpiTriAnd:  type = "triand"; break;
		case vpiTriOr:   type = "trior"; break;
		case vpiSupply1: type = "supply1"; break;
		case vpiSupply0: type = "supply0"; break;
		default:         type = "wire"; break;
	    }
	    break;

	  case vpiNamedBegin: type = "begin"; break;
	  case vpiGenScope:   type = "begin"; break;
	  case vpiNamedFork:  type = "fork"; break;
	  case vpiFunction:   type = "function"; break;
	  case vpiModule:     type = "module"; break;
	  case vpiTask:       type = "task"; break;

	  default:
	    vpi_printf("VCD warning: $dumpvars: Unsupported argument "
	               "type (%s)\n", vpi_get_str(vpiType, item));
	    return;
      }

	/* Do some special processing/checking on array words. Dumping
	 * array words is an Icarus extension. */
      if (item_type == vpiMemoryWord) {
	      /* Turn a non-constant array word select into a constant
	       * word select. */
	    if (vpi_get(vpiConstantSelect, item) == 0) {
		  vpiHandle array = vpi_handle(vpiParent, item);
		  PLI_INT32 idx = vpi_get(vpiIndex, item);
		  item = vpi_handle_by_index(array, idx);
	    }

	      /* An array word is implicitly escaped so look for an
	       * escaped identifier that this could conflict with. */
	      /* This does not work as expected since we always find at
	       * least the array word. We likely need a custom routine. */
            if (vpi_get(vpiType, item) == vpiMemoryWord &&
                vpi_handle_by_name(vpi_get_str(vpiFullName, item), 0)) {
		  vpi_printf("VCD warning: array word %s will conflict "
		             "with an escaped identifier.\n",
		             vpi_get_str(vpiFullName, item));
            }
      }

      fullname = vpi_get_str(vpiFullName, item);

	/* Generate the $var or $scope commands. */
      switch (item_type) {
	  case vpiParameter:
	    vpi_printf("VCD sorry: $dumpvars: can not dump parameters.\n");
	    break;

	  case vpiNamedEvent:
	  case vpiIntegerVar:
	  case vpiBitVar:
	  case vpiByteVar:
	  case vpiShortIntVar:
	  case vpiIntVar:
	  case vpiLongIntVar:
	  case vpiRealVar:
	  case vpiMemoryWord:
	  case vpiReg:
	  case vpiTimeVar:
	  case vpiNet:


	      /* If we are skipping all signal or this is in an automatic
	       * scope then just return. */
            if (skip || vpi_get(vpiAutomatic, item)) return;

	      /* Skip this signal if it has already been included.
	       * This can only happen for implicitly given signals. */
	    if (vcd_names_search(&vcd_var, fullname)) return;

	      /* Declare the variable in the VCD file. */
	    name = vpi_get_str(vpiName, item);
	    prefix = is_escaped_id(name) ? "\\" : "";

	      /* Some signals can have an alias so handle that. */
	    nexus_id = vpi_get(_vpiNexusId, item);

	    ident = 0;
	    if (nexus_id) ident = find_nexus_ident(nexus_id);

	    if (!ident) {
		  ident = strdup(vcdid);
		  gen_new_vcd_id();

		  if (nexus_id) set_nexus_ident(nexus_id, ident);

		    /* Add a callback for the signal. */
		  info = malloc(sizeof(*info));

		  info->time.type = vpiSimTime;
		  info->item  = item;
		  info->ident = ident;
		  info->scheduled = 0;

		  cb.time      = &info->time;
		  cb.user_data = (char*)info;
		  cb.value     = NULL;
		  cb.obj       = item;
		  cb.reason    = cbValueChange;
		  cb.cb_rtn    = variable_cb_1;

		  info->dmp_next = 0;
		  info->next  = vcd_list;
		  vcd_list    = info;

		  info->cb    = vpi_register_cb(&cb);
	    }

	      /* Named events do not have a size, but other tools use
	       * a size of 1 and some viewers do not accept a width of
	       * zero so we will also use a width of one for events. */
	    if (item_type == vpiNamedEvent) size = 1;
	    else size = vpi_get(vpiSize, item);

	    fprintf(dump_file, "$var %s %u %s %s%s",
		    type, size, ident, prefix, name);

	      /* Add a range for vectored values. */
	    if (size > 1 || vpi_get(vpiLeftRange, item) != 0) {
		  fprintf(dump_file, " [%i:%i]",
			  (int)vpi_get(vpiLeftRange, item),
			  (int)vpi_get(vpiRightRange, item));
	    }

	    fprintf(dump_file, " $end\n");
	    break;

	  case vpiModule:
	  case vpiGenScope:
	  case vpiFunction:
	  case vpiTask:
	  case vpiNamedBegin:
	  case vpiNamedFork:

	    if (depth > 0) {
		/* list of types to iterate upon */
		  static int types[] = {
			/* Value */
			vpiNamedEvent,
			vpiNet,
			/* vpiParameter, */
			vpiReg,
			vpiVariables,
			/* Scope */
			vpiFunction,
			vpiGenScope,
			vpiModule,
			vpiNamedBegin,
			vpiNamedFork,
			vpiTask,
			-1
		  };
		  int i;
		  int nskip = (vcd_names_search(&vcd_tab, fullname) != 0);

		    /* We have to always scan the scope because the
		     * depth could be different for this call. */
		  if (nskip) {
			vpi_printf("VCD warning: ignoring signals in "
			           "previously scanned scope %s.\n", fullname);
		  } else {
			vcd_names_add(&vcd_tab, fullname);
		  }

		  name = vpi_get_str(vpiName, item);
		  fprintf(dump_file, "$scope %s %s $end\n", type, name);

		  for (i=0; types[i]>0; i++) {
			vpiHandle hand;
			vpiHandle argv = vpi_iterate(types[i], item);
			while (argv && (hand = vpi_scan(argv))) {
			      scan_item(depth-1, hand, nskip);
			}
		  }

		    /* Sort any signals that we added above. */
		  fprintf(dump_file, "$upscope $end\n");
	    }
	    break;
      }
}
Ejemplo n.º 25
0
                }
                vpi_put_value(data[i].sig, &v, &t, vpiNoDelay);
                vpi_put_value(data[i].rfr, &v, &t, vpiNoDelay);
            }
            if ((callback_count_strs & 1) == 0) data[i].type = 0;
        }
        if (++callback_count_strs == callback_count_strs_max) {
            int success = vpi_remove_cb(cb);
            CHECK_RESULT_NZ(success);
        };
    } else {
        // setup and install
        for (int i=1; i<=128; i++) {
            char buf[32];
            snprintf(buf, sizeof(buf), "t.arr[%d].arr", i);
            CHECK_RESULT_NZ(data[i].scope   = vpi_handle_by_name((PLI_BYTE8*)buf, NULL));
            CHECK_RESULT_NZ(data[i].sig     = vpi_handle_by_name((PLI_BYTE8*)"sig", data[i].scope));
            CHECK_RESULT_NZ(data[i].rfr     = vpi_handle_by_name((PLI_BYTE8*)"rfr", data[i].scope));
            CHECK_RESULT_NZ(data[i].check   = vpi_handle_by_name((PLI_BYTE8*)"check", data[i].scope));
            CHECK_RESULT_NZ(data[i].verbose = vpi_handle_by_name((PLI_BYTE8*)"verbose", data[i].scope));
        }

        static t_cb_data cb_data;
        static s_vpi_value v;
        static VlVpiHandle count_h = vpi_handle_by_name((PLI_BYTE8*)"t.count", NULL);

        cb_data.reason = cbValueChange;
        cb_data.cb_rtn = _mon_check_putget_str; // this function
        cb_data.obj = count_h;
        cb_data.value = &v;
        v.format = vpiIntVal;
Ejemplo n.º 26
0
int _mon_check_var() {
    VlVpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.onebit", NULL);
    CHECK_RESULT_NZ(vh1);

    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t", NULL);
    CHECK_RESULT_NZ(vh2);

    // scope attributes
    const char* p;
    p = vpi_get_str(vpiName, vh2);
    CHECK_RESULT_CSTR(p, "t");
    p = vpi_get_str(vpiFullName, vh2);
    CHECK_RESULT_CSTR(p, "t");

    VlVpiHandle vh3 = vpi_handle_by_name((PLI_BYTE8*)"onebit", vh2);
    CHECK_RESULT_NZ(vh3);

    // onebit attributes
    PLI_INT32 d;
    d = vpi_get(vpiType, vh3);
    CHECK_RESULT(d, vpiReg);
    d = vpi_get(vpiDirection, vh3);
    CHECK_RESULT(d, vpiNoDirection);
    d = vpi_get(vpiVector, vh3);
    CHECK_RESULT(d, 0);

    p = vpi_get_str(vpiName, vh3);
    CHECK_RESULT_CSTR(p, "onebit");
    p = vpi_get_str(vpiFullName, vh3);
    CHECK_RESULT_CSTR(p, "t.onebit");

    // array attributes
    VlVpiHandle vh4 = vpi_handle_by_name((PLI_BYTE8*)"t.fourthreetwoone", NULL);
    CHECK_RESULT_NZ(vh4);
    d = vpi_get(vpiVector, vh4);
    CHECK_RESULT(d, 1);

    t_vpi_value tmpValue;
    tmpValue.format = vpiIntVal;
    {
        VlVpiHandle vh10 = vpi_handle(vpiLeftRange, vh4);
        CHECK_RESULT_NZ(vh10);
        vpi_get_value(vh10, &tmpValue);
        CHECK_RESULT(tmpValue.value.integer,2);
    }
    {
        VlVpiHandle vh10 = vpi_handle(vpiRightRange, vh4);
        CHECK_RESULT_NZ(vh10);
        vpi_get_value(vh10, &tmpValue);
        CHECK_RESULT(tmpValue.value.integer,1);
    }
    {
        VlVpiHandle vh10 = vpi_iterate(vpiMemoryWord, vh4);
        CHECK_RESULT_NZ(vh10);
        VlVpiHandle vh11 = vpi_scan(vh10);
        CHECK_RESULT_NZ(vh11);
        VlVpiHandle vh12 = vpi_handle(vpiLeftRange, vh11);
        CHECK_RESULT_NZ(vh12);
        vpi_get_value(vh12, &tmpValue);
        CHECK_RESULT(tmpValue.value.integer,4);
        VlVpiHandle vh13 = vpi_handle(vpiRightRange, vh11);
        CHECK_RESULT_NZ(vh13);
        vpi_get_value(vh13, &tmpValue);
        CHECK_RESULT(tmpValue.value.integer,3);
    }

    return 0;
}
Ejemplo n.º 27
0
/*
 * Given a path, look the path name up using the PLI
 * and return its 'value'.
 */
static int uvm_hdl_get_vlog(char *path, p_vpi_vecval value, PLI_INT32 flag)
{
  static int maxsize = -1;
  int i, size, chunks;
  vpiHandle r;
  s_vpi_value value_s;

  #ifdef QUESTA
  if (!partsel) {
    maxsize = uvm_hdl_max_width();
    chunks = (maxsize-1)/32 + 1;
    for(i=0;i<chunks-1; ++i) {
      value[i].aval = 0;
      value[i].bval = 0;
    }
  }
  int result = 0;
  result = uvm_hdl_get_vlog_partsel(path,value,flag);
  if (result < 0)
    return 0;
  if (result == 1)
    return 1;

  if (!strncmp(path,"$root.",6))
    r = vpi_handle_by_name(path+6, 0);
  else
  #endif
  r = vpi_handle_by_name(path, 0);

  if(r == 0)
  {
      vpi_printf((PLI_BYTE8*) "UVM_ERROR: get: unable to locate hdl path %s\n", path);
      vpi_printf((PLI_BYTE8*) " Either the name is incorrect, or you may not have PLI/ACC visibility to that name\n");
    // Exiting is too harsh. Just return instead.
    // tf_dofinish();
    return 0;
  }
  else
  {
    if(maxsize == -1) 
        maxsize = uvm_hdl_max_width();

    size = vpi_get(vpiSize, r);
    if(size > maxsize)
    {
    	    vpi_printf((PLI_BYTE8*) "UVM_ERROR: uvm_reg : hdl path '%s' is %0d bits,\n",path,size);
        vpi_printf((PLI_BYTE8*) " but the maximum size is %0d. You can increase the maximum\n",maxsize);
        vpi_printf((PLI_BYTE8*) " via a compile-time flag: +define+UVM_HDL_MAX_WIDTH=<value>\n");
      //tf_dofinish();
#ifndef VCS
        //vpi_release_handle(r);
#endif
      return 0;
    }
    chunks = (size-1)/32 + 1;

    value_s.format = vpiVectorVal;
    vpi_get_value(r, &value_s);
    /*dpi and vpi are reversed*/
    for(i=0;i<chunks; ++i)
    {
      value[i].aval = value_s.value.vector[i].aval;
      value[i].bval = value_s.value.vector[i].bval;
    }
  }
  //vpi_printf("uvm_hdl_get_vlog(%s,%0x)\n",path,value[0].aval);
#ifndef VCS
  //vpi_release_handle(r);
#endif
  return 1;
}