Fix non-integer vpi_get_value, bug587.

This commit is contained in:
Wilson Snyder 2012-12-06 09:40:16 -05:00
parent cc47ba2404
commit e68afa53a8
3 changed files with 46 additions and 6 deletions

View File

@ -7,6 +7,8 @@ indicates the contributor was also the author of the fix; Thanks!
*** Support "unsigned int" DPI import functions, msg966. [Alex Lee]
**** Fix non-integer vpi_get_value, bug587. [Rich Porter]
* Verilator 3.843 2012/12/01

View File

@ -101,6 +101,7 @@ public:
// cppcheck-suppress uninitVar // m_value
VerilatedVpioCb(const t_cb_data* cbDatap, QData time)
: m_cbData(*cbDatap), m_time(time) {
m_value.format = cbDatap->value?cbDatap->value->format:vpiSuppressVal;
m_cbData.value = &m_value;
}
virtual ~VerilatedVpioCb() {}

View File

@ -31,6 +31,7 @@
unsigned int main_time = false;
unsigned int callback_count = false;
unsigned int callback_count_half = false;
unsigned int callback_count_quad = false;
//======================================================================
@ -69,6 +70,13 @@ public:
return __LINE__; \
}
#define CHECK_RESULT_HEX(got, exp) \
if ((got != exp)) { \
cout<<hex<<"%Error: "<<FILENM<<":"<<__LINE__ \
<<": GOT = "<<(got)<<" EXP = "<<(exp)<<endl; \
return __LINE__; \
}
#define CHECK_RESULT_CSTR(got, exp) \
if (strcmp((got),(exp))) { \
printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", \
@ -121,15 +129,24 @@ int _mon_check_callbacks() {
}
int _value_callback(p_cb_data cb_data) {
CHECK_RESULT(cb_data->value->value.integer+10, main_time);
callback_count++;
return 0;
CHECK_RESULT(cb_data->value->value.integer+10, main_time);
callback_count++;
return 0;
}
int _value_callback_half(p_cb_data cb_data) {
CHECK_RESULT(cb_data->value->value.integer*2+10, main_time);
callback_count_half++;
return 0;
CHECK_RESULT(cb_data->value->value.integer*2+10, main_time);
callback_count_half++;
return 0;
}
int _value_callback_quad(p_cb_data cb_data) {
for (int index=0;index<2;index++) {
CHECK_RESULT_HEX(cb_data->value->value.vector[1].aval, (unsigned long)((index==2)?0x1c77bb9bUL:0x12819213UL));
CHECK_RESULT_HEX(cb_data->value->value.vector[0].aval, (unsigned long)((index==2)?0x3784ea09UL:0xabd31a1cUL));
}
callback_count_quad++;
return 0;
}
int _mon_check_value_callbacks() {
@ -155,6 +172,25 @@ int _mon_check_value_callbacks() {
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;
@ -371,6 +407,7 @@ int main(int argc, char **argv, char **env) {
}
CHECK_RESULT(callback_count, 501);
CHECK_RESULT(callback_count_half, 250);
CHECK_RESULT(callback_count_quad, 2);
if (!Verilated::gotFinish()) {
vl_fatal(FILENM,__LINE__,"main", "%Error: Timeout; never got a $finish");
}