Implement the swrite* and sformat system tasks plus a few other fixes.

This patch implements the swrite* and sformat system tasks. It also
makes $simtime distinguishable from the other integer time tasks.
This was needed to get the correct time units when $simtime was given
as an argument to $swrite*. The string constant code was also modified
to allow a string to be returned as a vector (0/1 bit pattern).

Here are some more specifics about the swrite* changes.
1. They do not share formatting code with the other display functions,
   so they may/will produce different results.
2. All %{alpha} codes allow a width and justification. Others have been
   enhanced (%t allows the default width and precision to be overridden,
   time functions print with time formatting, better error checking and
   messages, etc.).
3. %u and %z formatting codes have been added. It is important to note
   that these two formats can produce embedded NULLs, since these
   functions are returning a string anything after the first NULL will
   not be reachable! memcpy is used instead of regular string processing
   where needed so that the original string will contain the total
   result. The size returned when the string is created is the true
   length.  A warning will be printed if a string with embedded NULLs is
   produced (strlen() does not match the true length).
4. Real numbers are printed with %g instead of %f.

Once this new formatting code has been evaluated we should incorporate
the changes/fixes into the formatting code for the other functions or
the other functions could be modified to use this new code. The true
string length is available so we should be able to work around the
embedded NULL problem.
This commit is contained in:
Cary R 2007-08-13 15:56:02 -07:00 committed by Stephen Williams
parent 268e2df011
commit 239523b3c7
3 changed files with 914 additions and 268 deletions

File diff suppressed because it is too large Load Diff

View File

@ -60,6 +60,7 @@ static int string_get(int code, vpiHandle ref)
static void string_value(vpiHandle ref, p_vpi_value vp)
{
unsigned uint_value;
p_vpi_vecval vecp;
struct __vpiStringConst*rfp = (struct __vpiStringConst*)ref;
int size = strlen(rfp->value);
char*rbuf = 0;
@ -135,6 +136,22 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
}
break;
case vpiVectorVal:
vp->value.vector = (p_vpi_vecval) calloc((size+3)/4,
sizeof(s_vpi_vecval));
uint_value = 0;
vecp = vp->value.vector;
for(int i=0; i<size;i ++){
vecp->aval |= rfp->value[i] << uint_value*8;
uint_value += 1;
if (uint_value > 3) {
uint_value = 0;
vecp += 1;
}
}
break;
default:
fprintf(stderr, "ERROR (vpi_const.cc): vp->format: %d\n", vp->format);
assert(0);
@ -632,33 +649,3 @@ vpiHandle vpip_make_real_const(double value)
return vpip_make_real_const(obj, value);
}
/*
* $Log: vpi_const.cc,v $
* Revision 1.39 2007/04/12 04:45:52 steve
* Support for vpi_get_value of scaler values. (ravi@bluespec)
*
* Revision 1.38 2007/04/12 04:25:58 steve
* vpip_make_binary_const cannot free the string passed in to it.
*
* Revision 1.37 2007/02/25 23:08:24 steve
* Process Verilog escape sequences much earlier.
*
* Revision 1.36 2006/06/18 04:15:50 steve
* Add support for system functions in continuous assignments.
*
* Revision 1.35 2006/03/18 22:51:10 steve
* Syntax for carrying sign with parameter.
*
* Revision 1.34 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.33 2006/03/06 05:43:15 steve
* Cleanup vpi_const to use vec4 values.
*
* Revision 1.32 2004/10/04 01:10:59 steve
* Clean up spurious trailing white space.
*
* Revision 1.31 2004/05/18 18:43:38 steve
* Allow vpiParamter as a string type.
*/

View File

@ -88,6 +88,18 @@ static char* timevar_time_get_str(int code, vpiHandle ref)
}
}
static char* timevar_simtime_get_str(int code, vpiHandle ref)
{
switch (code) {
case vpiName:
return "$simtime";
default:
fprintf(stderr, "Code: %d\n", code);
assert(0);
return 0;
}
}
static char* timevar_realtime_get_str(int code, vpiHandle ref)
{
switch (code) {
@ -226,6 +238,16 @@ static const struct __vpirt vpip_system_time_rt = {
0
};
static const struct __vpirt vpip_system_simtime_rt = {
vpiSysFuncCall,
timevar_time_get,
timevar_simtime_get_str,
timevar_get_value,
0,
timevar_handle,
0
};
static const struct __vpirt vpip_system_realtime_rt = {
vpiSysFuncCall,
timevar_realtime_get,
@ -248,7 +270,7 @@ vpiHandle vpip_sim_time(struct __vpiScope*scope)
scope->scoped_time.scope = scope;
return &scope->scoped_time.base;
} else {
global_simtime.base.vpi_type = &vpip_system_time_rt;
global_simtime.base.vpi_type = &vpip_system_simtime_rt;
global_simtime.scope = 0;
return &global_simtime.base;
}
@ -271,67 +293,3 @@ void vpip_set_time_precision(int pre)
vpi_time_precision = pre;
}
/*
* $Log: vpi_time.cc,v $
* Revision 1.17 2005/12/05 21:19:55 steve
* Be more careful with double types.
*
* Revision 1.16 2004/10/04 01:11:00 steve
* Clean up spurious trailing white space.
*
* Revision 1.15 2003/03/14 18:01:00 steve
* Refix vpiRealVal scaling of time.
*
* Revision 1.14 2003/03/13 20:31:41 steve
* Warnings about long long time.
*
* Revision 1.13 2003/03/13 04:59:21 steve
* Use rbufs instead of static buffers.
*
* Revision 1.12 2003/02/03 01:09:20 steve
* Allow $display of $simtime.
*
* Revision 1.11 2003/02/02 02:14:14 steve
* Proper rounding of scaled integer time.
*
* 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
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.8 2002/08/12 01:35:09 steve
* conditional ident string using autoconfig.
*
* Revision 1.7 2002/04/20 04:33:23 steve
* Support specified times in cbReadOnlySync, and
* add support for cbReadWriteSync.
* Keep simulation time in a 64bit number.
*
* Revision 1.6 2002/01/15 03:06:29 steve
* Support vpiSize and vpiSigned for time objects.
*
* Revision 1.5 2001/10/15 02:55:03 steve
* sign warning.
*
* Revision 1.4 2001/08/16 03:29:31 steve
* Support various other string formats for time.
*
* Revision 1.3 2001/06/30 23:03:17 steve
* support fast programming by only writing the bits
* that are listed in the input file.
*
* Revision 1.2 2001/04/03 03:46:14 steve
* VPI access time as a decimal string, and
* stub vpi access to the scopes.
*
* Revision 1.1 2001/03/31 19:00:44 steve
* Add VPI support for the simulation time.
*
*/