Make a plain $stime print in 10 digits (32 bits).

This patch makes $stime a unique call in display and returns
the lower 32 bits in a 10 digit field when it is called.
This commit is contained in:
Cary R 2009-01-08 19:10:15 -08:00 committed by Stephen Williams
parent 5d7f8c9706
commit cba8b42580
4 changed files with 75 additions and 16 deletions

View File

@ -867,7 +867,10 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
char*tmp = vpi_get_str(vpiName, item);
vpiHandle scope = vpi_handle(vpiScope, item);
/* This is wrong, but will be replaced with the
* the string formatting below soon. */
if (strcmp(tmp,"$time") == 0 ||
strcmp(tmp,"$stime") == 0 ||
strcmp(tmp,"$simtime") == 0) {
value.format = vpiTimeVal;
vpi_get_value(item, &value);
@ -2043,7 +2046,6 @@ static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info)
case vpiSysFuncCall:
func_name = vpi_get_str(vpiName, item);
/* For now this also handles $stime */
if (strcmp(func_name, "$time") == 0) {
value.format = vpiDecStrVal;
vpi_get_value(item, &value);
@ -2052,6 +2054,14 @@ static char *get_display(unsigned int *rtnsz, struct strobe_cb_info *info)
rtn = realloc(rtn, (size+width)*sizeof(char));
sprintf(rtn+size-1, "%*s", width, value.value.str);
} else if (strcmp(func_name, "$stime") == 0) {
value.format = vpiDecStrVal;
vpi_get_value(item, &value);
width = strlen(value.value.str);
if (width < 10) width = 10;
rtn = realloc(rtn, (size+width)*sizeof(char));
sprintf(rtn+size-1, "%*s", width, value.value.str);
} else if (strcmp(func_name, "$simtime") == 0) {
value.format = vpiDecStrVal;
vpi_get_value(item, &value);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -493,13 +493,13 @@ bool vpi_handle_resolv_list_s::resolve(bool mes)
void compile_vpi_lookup(vpiHandle *handle, char*label)
{
if (strcmp(label, "$time") == 0) {
*handle = vpip_sim_time(vpip_peek_current_scope());
*handle = vpip_sim_time(vpip_peek_current_scope(), false);
free(label);
return;
}
if (strcmp(label, "$stime") == 0) {
*handle = vpip_sim_time(vpip_peek_current_scope());
*handle = vpip_sim_time(vpip_peek_current_scope(), true);
free(label);
return;
}
@ -511,7 +511,7 @@ void compile_vpi_lookup(vpiHandle *handle, char*label)
}
if (strcmp(label, "$simtime") == 0) {
*handle = vpip_sim_time(0);
*handle = vpip_sim_time(0, false);
free(label);
return;
}

View File

@ -1,7 +1,7 @@
#ifndef __vpi_priv_H
#define __vpi_priv_H
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -176,6 +176,7 @@ struct __vpiScope {
bool is_automatic;
/* The scope has a system time of its own. */
struct __vpiSystemTime scoped_time;
struct __vpiSystemTime scoped_stime;
struct __vpiSystemTime scoped_realtime;
/* Keep an array of internal scope items. */
struct __vpiHandle**intern;
@ -526,7 +527,7 @@ extern void vpip_execute_vpi_call(vthread_t thr, vpiHandle obj);
* and to finish compilation in preparation for execution.
*/
vpiHandle vpip_sim_time(struct __vpiScope*scope);
vpiHandle vpip_sim_time(struct __vpiScope*scope, bool is_stime);
vpiHandle vpip_sim_realtime(struct __vpiScope*scope);
extern int vpip_get_time_precision(void);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -103,6 +103,17 @@ static int timevar_time_get(int code, vpiHandle ref)
}
}
static int timevar_stime_get(int code, vpiHandle ref)
{
switch (code) {
case vpiSize:
return 32;
default:
return timevar_time_get(code, ref);
}
}
static char* timevar_time_get_str(int code, vpiHandle ref)
{
switch (code) {
@ -115,6 +126,18 @@ static char* timevar_time_get_str(int code, vpiHandle ref)
}
}
static char* timevar_stime_get_str(int code, vpiHandle ref)
{
switch (code) {
case vpiName:
return simple_set_rbuf_str("$stime");
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_simtime_get_str(int code, vpiHandle ref)
{
switch (code) {
@ -143,7 +166,7 @@ static int timevar_realtime_get(int code, vpiHandle ref)
{
switch (code) {
case vpiSize:
return 64;
return 1;
case vpiSigned:
return 0;
@ -174,7 +197,8 @@ static vpiHandle timevar_handle(int code, vpiHandle ref)
}
}
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func)
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func,
bool is_stime)
{
/* Keep a persistent structure for passing time values back to
the caller. */
@ -204,6 +228,9 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func)
if ((divisor >= 10) && (simtime_fraction >= (divisor/2)))
simtime += 1;
/* If this is a call to $stime only return the lower 32 bits. */
if (is_stime) simtime &= 0xffffffff;
switch (vp->format) {
case vpiObjTypeVal:
/* The default format is vpiTimeVal. */
@ -260,12 +287,17 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func)
static void timevar_get_ivalue(vpiHandle ref, s_vpi_value*vp)
{
timevar_get_value(ref, vp, true);
timevar_get_value(ref, vp, true, false);
}
static void timevar_get_svalue(vpiHandle ref, s_vpi_value*vp)
{
timevar_get_value(ref, vp, true, true);
}
static void timevar_get_rvalue(vpiHandle ref, s_vpi_value*vp)
{
timevar_get_value(ref, vp, false);
timevar_get_value(ref, vp, false, false);
}
static const struct __vpirt vpip_system_time_rt = {
@ -278,6 +310,16 @@ static const struct __vpirt vpip_system_time_rt = {
0
};
static const struct __vpirt vpip_system_stime_rt = {
vpiSysFuncCall,
timevar_stime_get,
timevar_stime_get_str,
timevar_get_svalue,
0,
timevar_handle,
0
};
static const struct __vpirt vpip_system_simtime_rt = {
vpiSysFuncCall,
timevar_time_get,
@ -303,12 +345,18 @@ static const struct __vpirt vpip_system_realtime_rt = {
* $time and $stime system functions return a value scaled to a scope,
* and the $simtime returns the unscaled time.
*/
vpiHandle vpip_sim_time(struct __vpiScope*scope)
vpiHandle vpip_sim_time(struct __vpiScope*scope, bool is_stime)
{
if (scope) {
scope->scoped_time.base.vpi_type = &vpip_system_time_rt;
scope->scoped_time.scope = scope;
return &scope->scoped_time.base;
if (is_stime) {
scope->scoped_stime.base.vpi_type = &vpip_system_stime_rt;
scope->scoped_stime.scope = scope;
return &scope->scoped_stime.base;
} else {
scope->scoped_time.base.vpi_type = &vpip_system_time_rt;
scope->scoped_time.scope = scope;
return &scope->scoped_time.base;
}
} else {
global_simtime.base.vpi_type = &vpip_system_simtime_rt;
global_simtime.scope = 0;