vvp: Remove restriction on time types for cbNextSimTime.

IEEE 1364-1995 has different wording to later versions of the standard,
stating "For reason cbNextSimTime, the time structure is ignored." So
it's possible old VPI code might not pass a valid time pointer or time
structure. So remove the checks that the time pointer is non-null and
that the time type is not vpiSuppressTime.

To allow a user to select the time type, we have to assume that if
the time pointer is non-null, it is a valid pointer and not just an
uninitialised field.
This commit is contained in:
Martin Whitaker 2024-02-06 18:47:54 +00:00
parent 9d04809280
commit ad400ac468
6 changed files with 32 additions and 26 deletions

View File

@ -37,20 +37,26 @@ static PLI_INT32 register_nextsimtime(struct t_cb_data* cb);
static PLI_INT32 nextsimtime_cb(struct t_cb_data* cb) {
s_vpi_time timerec;
#ifdef TEST_SCALED_TIME
timerec.type = vpiScaledRealTime;
#ifdef TEST_NULL_TIME
(void)cb;
#else
assert(cb->time && (cb->time->type == TIME_TYPE));
#endif
#if defined(TEST_SCALED_TIME) || defined(TEST_SIM_TIME)
timerec = *(cb->time);
#else
timerec.type = vpiSimTime;
vpi_get_time(NULL, &timerec);
#endif
vpi_get_time(vpi_handle_by_name("main", NULL), &timerec);
#ifdef TEST_SCALED_TIME
vpi_printf("nextsimtime: %f vpi_get_time: %f\n",
cb->time->real, timerec.real);
vpi_printf("nextsimtime: %f\n", timerec.real);
#else
uint64_t nextsimtime = ((uint64_t)cb->time->high << 32) | cb->time->low;
uint64_t time = ((uint64_t)timerec.high << 32) | timerec.low;
vpi_printf("nextsimtime: %" PLI_UINT64_FMT " vpi_get_time: %" PLI_UINT64_FMT "\n",
nextsimtime, time);
vpi_printf("nextsimtime: %" PLI_UINT64_FMT "\n", time);
#endif
register_nextsimtime(NULL);
return 0;

View File

@ -1,3 +1,8 @@
Compiling vpi/nextsimtime_null_time.c...
Making nextsimtime_null_time.vpi from nextsimtime_null_time.o...
ERROR: VPI: cbNextSimTime time pointer must be valid.
time 0: 0
nextsimtime: 1000
time 1: 1
nextsimtime: 4000
time 4: 4
nextsimtime: 5000

View File

@ -1,8 +1,8 @@
Compiling vpi/nextsimtime_scaled_time.c...
Making nextsimtime_scaled_time.vpi from nextsimtime_scaled_time.o...
time 0: 0
nextsimtime: 1.000000 vpi_get_time: 1.000000
nextsimtime: 1.000000
time 1: 1
nextsimtime: 4.000000 vpi_get_time: 4.000000
nextsimtime: 4.000000
time 4: 4
nextsimtime: 5.000000 vpi_get_time: 5.000000
nextsimtime: 5.000000

View File

@ -1,8 +1,8 @@
Compiling vpi/nextsimtime_sim_time.c...
Making nextsimtime_sim_time.vpi from nextsimtime_sim_time.o...
time 0: 0
nextsimtime: 1000 vpi_get_time: 1000
nextsimtime: 1000
time 1: 1
nextsimtime: 4000 vpi_get_time: 4000
nextsimtime: 4000
time 4: 4
nextsimtime: 5000 vpi_get_time: 5000
nextsimtime: 5000

View File

@ -1,3 +1,8 @@
Compiling vpi/nextsimtime_suppress_time.c...
Making nextsimtime_suppress_time.vpi from nextsimtime_suppress_time.o...
ERROR: VPI: cbNextSimTime time type cannot be vpiSuppressTime.
time 0: 0
nextsimtime: 1000
time 1: 1
nextsimtime: 4000
time 4: 4
nextsimtime: 5000

View File

@ -646,16 +646,6 @@ static simulator_callback* make_prepost(p_cb_data data)
EndOfSimulation = obj;
break;
case cbNextSimTime:
if (!data->time) {
vpi_printf("ERROR: VPI: cbNextSimTime time pointer must be valid.\n");
vpi_control(vpiFinish, 1);
break;
}
if (data->time->type == vpiSuppressTime) {
vpi_printf("ERROR: VPI: cbNextSimTime time type cannot be vpiSuppressTime.\n");
vpi_control(vpiFinish, 1);
break;
}
obj->next = NextSimTime;
NextSimTime = obj;
break;