vvp: Factor out and extend code for finding timescale scope for a VPI object.

This commit is contained in:
Martin Whitaker 2024-02-05 23:21:45 +00:00
parent 872fcd13ae
commit f3f2dddf9a
1 changed files with 38 additions and 37 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2023 Stephen Williams (steve@icarus.com) * Copyright (c) 2008-2024 Stephen Williams (steve@icarus.com)
* Copyright (c) 2023 Leo Moser (leo.moser@pm.me) * Copyright (c) 2023 Leo Moser (leo.moser@pm.me)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
@ -495,74 +495,75 @@ char* vpi_get_str(PLI_INT32 property, vpiHandle ref)
return res; return res;
} }
int vpip_time_units_from_handle(vpiHandle obj) static __vpiScope*vpip_timescale_scope_from_handle(vpiHandle obj)
{ {
struct __vpiSysTaskCall*task; struct __vpiSysTaskCall*task;
__vpiScope*scope;
struct __vpiSignal*signal; struct __vpiSignal*signal;
struct __vpiRealVar*real;
__vpiNamedEvent*event; __vpiNamedEvent*event;
if (obj == 0)
return vpip_get_time_precision();
switch (obj->get_type_code()) { switch (obj->get_type_code()) {
case vpiSysTaskCall: case vpiSysTaskCall:
task = dynamic_cast<__vpiSysTaskCall*>(obj); task = dynamic_cast<__vpiSysTaskCall*>(obj);
return task->scope->time_units; return task->scope;
case vpiModule: case vpiModule:
scope = dynamic_cast<__vpiScope*>(obj); return dynamic_cast<__vpiScope*>(obj);
return scope->time_units;
case vpiNet: case vpiNet:
case vpiReg: case vpiReg:
case vpiIntegerVar:
case vpiBitVar:
case vpiByteVar:
case vpiShortIntVar:
case vpiIntVar:
case vpiLongIntVar:
signal = dynamic_cast<__vpiSignal*>(obj); signal = dynamic_cast<__vpiSignal*>(obj);
scope = vpip_scope(signal); return vpip_scope(signal);
return scope->time_units;
case vpiRealVar:
real = dynamic_cast<__vpiRealVar*>(obj);
return vpip_scope(real);
case vpiNamedEvent: case vpiNamedEvent:
event = dynamic_cast<__vpiNamedEvent*>(obj); event = dynamic_cast<__vpiNamedEvent*>(obj);
scope = event->get_scope(); return event->get_scope();
return scope->time_units;
case vpiMemory:
case vpiMemoryWord:
case vpiPartSelect:
return dynamic_cast<__vpiScope*>(obj->vpi_handle(vpiScope));
default: default:
fprintf(stderr, "ERROR: vpip_time_units_from_handle called with " fprintf(stderr, "ERROR: vpip_scope_from_handle called with "
"object handle type=%d\n", obj->get_type_code()); "object handle type=%d\n", obj->get_type_code());
assert(0); assert(0);
return 0; return 0;
} }
} }
int vpip_time_precision_from_handle(vpiHandle obj) int vpip_time_units_from_handle(vpiHandle obj)
{ {
struct __vpiSysTaskCall*task;
__vpiScope*scope;
struct __vpiSignal*signal;
if (obj == 0) if (obj == 0)
return vpip_get_time_precision(); return vpip_get_time_precision();
switch (obj->get_type_code()) { __vpiScope*scope = vpip_timescale_scope_from_handle(obj);
case vpiSysTaskCall: if (scope == 0)
task = dynamic_cast<__vpiSysTaskCall*>(obj); return vpip_get_time_precision();
return task->scope->time_precision;
case vpiModule: return scope->time_units;
scope = dynamic_cast<__vpiScope*>(obj);
return scope->time_precision;
case vpiNet:
case vpiReg:
signal = dynamic_cast<__vpiSignal*>(obj);
scope = vpip_scope(signal);
return scope->time_precision;
default:
fprintf(stderr, "ERROR: vpip_time_precision_from_handle called "
"with object handle type=%d\n", obj->get_type_code());
assert(0);
return 0;
} }
int vpip_time_precision_from_handle(vpiHandle obj)
{
if (obj == 0)
return vpip_get_time_precision();
__vpiScope*scope = vpip_timescale_scope_from_handle(obj);
if (scope == 0)
return vpip_get_time_precision();
return scope->time_precision;
} }
double vpip_scaled_time_from_handle(vvp_time64_t time, vpiHandle obj) double vpip_scaled_time_from_handle(vvp_time64_t time, vpiHandle obj)