Make $time and $realtime available to $display uniquely.

This commit is contained in:
steve 2003-02-01 05:50:04 +00:00
parent e549a2c5c3
commit fec6a10771
4 changed files with 120 additions and 19 deletions

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_user.h,v 1.17 2003/01/26 21:15:59 steve Exp $"
#ident "$Id: vpi_user.h,v 1.18 2003/02/01 05:50:27 steve Exp $"
#endif
@ -192,6 +192,10 @@ typedef struct t_vpi_value {
# define vpiOctConst 4
# define vpiHexConst 5
# define vpiStringConst 6
#define vpiFuncType 44
# define vpiIntFunc 1
# define vpiRealFunc 2
# define vpiTimeFunc 3
#define vpiSigned 65
/* IVL private properties */
#define _vpiNexusId 128
@ -367,6 +371,9 @@ EXTERN_C_END
/*
* $Log: vpi_user.h,v $
* Revision 1.18 2003/02/01 05:50:27 steve
* Make $time and $realtime available to $display uniquely.
*
* Revision 1.17 2003/01/26 21:15:59 steve
* Rework expression parsing and elaboration to
* accommodate real/realtime values and expressions.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.150 2003/01/27 00:14:37 steve Exp $"
#ident "$Id: compile.cc,v 1.151 2003/02/01 05:50:04 steve Exp $"
#endif
# include "arith.h"
@ -445,7 +445,7 @@ void compile_vpi_lookup(vpiHandle *handle, char*label)
}
if (strcmp(label, "$realtime") == 0) {
*handle = vpip_sim_time(vpip_peek_current_scope());
*handle = vpip_sim_realtime(vpip_peek_current_scope());
free(label);
return;
}
@ -1513,6 +1513,9 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag,
/*
* $Log: compile.cc,v $
* Revision 1.151 2003/02/01 05:50:04 steve
* Make $time and $realtime available to $display uniquely.
*
* Revision 1.150 2003/01/27 00:14:37 steve
* Support in various contexts the $realtime
* system task.

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.h,v 1.45 2003/01/27 00:14:37 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.46 2003/02/01 05:50:04 steve Exp $"
#endif
# include "vpi_user.h"
@ -145,6 +145,7 @@ struct __vpiScope {
const char*name;
/* The scope has a system time of its own. */
struct __vpiSystemTime scoped_time;
struct __vpiSystemTime scoped_realtime;
/* Keep an array of internal scope items. */
struct __vpiHandle**intern;
unsigned nintern;
@ -337,6 +338,7 @@ extern void vpip_execute_vpi_call(vthread_t thr, vpiHandle obj);
*/
vpiHandle vpip_sim_time(struct __vpiScope*scope);
vpiHandle vpip_sim_realtime(struct __vpiScope*scope);
extern int vpip_get_time_precision(void);
extern void vpip_set_time_precision(int pres);
@ -393,6 +395,9 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
/*
* $Log: vpi_priv.h,v $
* Revision 1.46 2003/02/01 05:50:04 steve
* Make $time and $realtime available to $display uniquely.
*
* Revision 1.45 2003/01/27 00:14:37 steve
* Support in various contexts the $realtime
* system task.

View File

@ -17,19 +17,20 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_time.cc,v 1.9 2002/12/21 00:55:58 steve Exp $"
#ident "$Id: vpi_time.cc,v 1.10 2003/02/01 05:50:04 steve Exp $"
#endif
# include "vpi_priv.h"
# include "schedule.h"
# include <stdio.h>
# include <math.h>
# include <assert.h>
/*
* The $time system function is supported in VPI contexts (i.e. an
* argument to a system task/function) as a magical time variable. The
* VPI sees it as a vpiTimeVar object, but reads from it get the
* current value instead of some assigned value.
* argument to a system task/function) as a vpiSysFuncCall object. The
* $display function divines that this is a function call and uses a
* vpi_get_value to get the value.
*/
/*
@ -53,22 +54,82 @@ vvp_time64_t vpip_timestruct_to_time(const struct t_vpi_time*ts)
}
static int timevar_get(int code, vpiHandle ref)
static int timevar_time_get(int code, vpiHandle ref)
{
switch (code) {
case vpiSize:
return 64;
return 64;
case vpiSigned:
return 0;
return 0;
case vpiFuncType:
return vpiTimeFunc;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_time_get_str(int code, vpiHandle ref)
{
switch (code) {
case vpiName:
return "$time";
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_realtime_get_str(int code, vpiHandle ref)
{
switch (code) {
case vpiName:
return "$realtime";
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static int timevar_realtime_get(int code, vpiHandle ref)
{
switch (code) {
case vpiSize:
return 64;
case vpiSigned:
return 0;
case vpiFuncType:
return vpiRealFunc;
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static vpiHandle timevar_handle(int code, vpiHandle ref)
{
struct __vpiSystemTime*rfp
= reinterpret_cast<struct __vpiSystemTime*>(ref);
switch (code) {
case vpiScope:
return &rfp->scope->base;
default:
return 0;
}
}
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
{
static char buf_obj[128];
@ -77,7 +138,8 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
the caller. */
static struct t_vpi_time time_value;
struct __vpiSystemTime*rfp = reinterpret_cast<struct __vpiSystemTime*>(ref);
struct __vpiSystemTime*rfp
= reinterpret_cast<struct __vpiSystemTime*>(ref);
unsigned long x, num_bits;
vvp_time64_t simtime = schedule_simtime();
int units = rfp->scope->time_units;
@ -95,6 +157,11 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
vp->format = vpiTimeVal;
break;
case vpiRealVal:
vp->value.real = pow(10, vpi_time_precision-rfp->scope->time_units)
* schedule_simtime();
break;
case vpiBinStrVal:
x = simtime;
num_bits = 8 * sizeof(unsigned long);
@ -130,15 +197,24 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
}
static const struct __vpirt vpip_system_time_rt = {
vpiTimeVar,
timevar_get,
0,
vpiSysFuncCall,
timevar_time_get,
timevar_time_get_str,
timevar_get_value,
0,
0,
timevar_handle,
0
};
static const struct __vpirt vpip_system_realtime_rt = {
vpiSysFuncCall,
timevar_realtime_get,
timevar_realtime_get_str,
timevar_get_value,
0,
timevar_handle,
0
};
vpiHandle vpip_sim_time(struct __vpiScope*scope)
{
@ -147,6 +223,13 @@ vpiHandle vpip_sim_time(struct __vpiScope*scope)
return &scope->scoped_time.base;
}
vpiHandle vpip_sim_realtime(struct __vpiScope*scope)
{
scope->scoped_realtime.base.vpi_type = &vpip_system_realtime_rt;
scope->scoped_realtime.scope = scope;
return &scope->scoped_realtime.base;
}
int vpip_get_time_precision(void)
{
return vpi_time_precision;
@ -160,6 +243,9 @@ void vpip_set_time_precision(int pre)
/*
* $Log: vpi_time.cc,v $
* Revision 1.10 2003/02/01 05:50:04 steve
* Make $time and $realtime available to $display uniquely.
*
* Revision 1.9 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal