Make %v print all the bits of a vector.

This patch reworks the %v code to print the strength information
for all the bits of a vector. The code previously only printed
the LSB information.
This commit is contained in:
Cary R 2008-04-09 18:16:21 -07:00 committed by Stephen Williams
parent 44767d8f70
commit ef3aacfe36
4 changed files with 71 additions and 87 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2008 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
@ -16,9 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: a_fetch_value.c,v 1.5 2003/06/17 16:55:07 steve Exp $"
#endif
# include <acc_user.h>
# include <vpi_user.h>
@ -104,7 +101,8 @@ static char* fetch_strength_value(handle obj)
val.format = vpiStrengthVal;
vpi_get_value(obj, &val);
vpip_format_strength(str, &val);
/* Should this iterate over the bits? It now matches the old code. */
vpip_format_strength(str, &val, 0);
if (pli_trace) {
fprintf(pli_trace, "acc_fetch_value(<%s>, \"%%v\") --> %s\n",
@ -125,30 +123,3 @@ char* acc_fetch_value(handle obj, const char*fmt, s_acc_value*value)
vpi_printf("XXXX acc_fetch_value(..., \"%s\", ...)\n", fmt);
return "<acc_fetch_value>";
}
/*
* $Log: a_fetch_value.c,v $
* Revision 1.5 2003/06/17 16:55:07 steve
* 1) setlinebuf() for vpi_trace
* 2) Addes error checks for trace file opens
* 3) removes now extraneous flushes
* 4) fixes acc_next() bug
*
* Revision 1.4 2003/05/18 00:16:35 steve
* Add PLI_TRACE tracing of PLI1 modules.
*
* Add tf_isetdelay and friends, and add
* callback return values for acc_vcl support.
*
* Revision 1.3 2003/04/24 02:02:37 steve
* Clean up some simple warnings.
*
* Revision 1.2 2003/04/20 02:49:07 steve
* acc_fetch_value support for %v format.
*
* Revision 1.1 2003/04/12 18:57:14 steve
* More acc_ function stubs.
*
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2008 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
@ -16,9 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: sys_display.c,v 1.79 2007/04/18 02:40:20 steve Exp $"
#endif
# include "vpi_config.h"
@ -320,11 +317,16 @@ static void format_time_real(unsigned mcd, int fsize,
}
static void format_strength(unsigned int mcd, s_vpi_value*value)
static void format_strength(unsigned int mcd, s_vpi_value*value,
unsigned size)
{
char str[4];
vpip_format_strength(str, value);
int bit;
for (bit = size-1; bit >= 0; bit -= 1) {
vpip_format_strength(str, value, (unsigned) bit);
my_mcd_printf(mcd, "%s", str);
}
}
static void format_error_msg(const char*msg, int leading_zero,
@ -695,7 +697,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
return 1;
}
format_strength(mcd, &value);
format_strength(mcd, &value, vpi_get(vpiSize, argv[idx]));
use_count = 1;
break;
@ -1322,12 +1324,16 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
s_vpi_value value;
char *result, *fmtb;
unsigned int size;
unsigned int max_size = 256; /* The initial size of the buffer. */
unsigned int ini_size = 256; /* The initial size of the buffer. */
/* Make sure the width fits in the initial buffer. */
if (width+1 > ini_size) ini_size = width + 1;
/* The default return value is the full format. */
result = malloc(max_size*sizeof(char));
result = malloc(ini_size*sizeof(char));
fmtb = format_as_string(ljust, plus, ld_zero, width, prec, fmt);
strcpy(result, fmtb);
size = strlen(result) + 1; /* fallback value if errors */
switch (fmt) {
case '%':
@ -1386,13 +1392,13 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
}
/* If the default buffer is too small, make it big enough. */
size = strlen(cp) + 1;
if (size > max_size) result = realloc(result, size*sizeof(char));
if (size > ini_size) result = realloc(result, size*sizeof(char));
if (ljust == 0) sprintf(result, "%*s", width, cp);
else sprintf(result, "%-*s", width, cp);
}
}
size = strlen(result) + 1;
}
}
break;
case 'c':
@ -1416,9 +1422,9 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
value.value.str[strlen(value.value.str)-1]);
else sprintf(result, "%-*c", width,
value.value.str[strlen(value.value.str)-1]);
}
}
size = strlen(result) + 1;
}
}
break;
case 'd':
@ -1451,13 +1457,13 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
strcpy(&tbuf[1], value.value.str);
} else strcpy(&tbuf[0], value.value.str);
/* If the default buffer is too small make it big enough. */
if (size > max_size) result = realloc(result, size*sizeof(char));
if (size > ini_size) result = realloc(result, size*sizeof(char));
if (ljust == 0) sprintf(result, "%*s", width, tbuf);
else sprintf(result, "%-*s", width, tbuf);
free(tbuf);
}
}
size = strlen(result) + 1;
}
}
break;
case 'e':
@ -1485,9 +1491,9 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
while (*cp != '>') cp++;
*cp = '\0';
sprintf(result, fmtb+1, value.value.real);
}
}
size = strlen(result) + 1;
}
}
break;
/* This Verilog format specifier is not currently supported!
@ -1496,7 +1502,6 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
case 'L':
vpi_printf("WARNING: %%%c currently unsupported %s%s.\n", fmt,
info->name, fmtb);
size = strlen(result) + 1;
break;
case 'm':
@ -1532,12 +1537,12 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
if (width == -1) width = 0;
/* If the default buffer is too small make it big enough. */
size = strlen(value.value.str) + 1;
if (size > max_size) result = realloc(result, size*sizeof(char));
if (size > ini_size) result = realloc(result, size*sizeof(char));
if (ljust == 0) sprintf(result, "%*s", width, value.value.str);
else sprintf(result, "%-*s", width, value.value.str);
}
}
size = strlen(result) + 1;
}
}
break;
case 't':
@ -1570,6 +1575,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
get_time_real(tbuf, value.value.real, prec, time_units);
if (ljust == 0) sprintf(result, "%*s", width, tbuf);
else sprintf(result, "%-*s", width, tbuf);
size = strlen(result) + 1;
}
} else {
value.format = vpiDecStrVal;
@ -1581,16 +1587,15 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
get_time(tbuf, value.value.str, prec, time_units);
if (ljust == 0) sprintf(result, "%*s", width, tbuf);
else sprintf(result, "%-*s", width, tbuf);
}
}
}
size = strlen(result) + 1;
}
}
}
break;
case 'u':
case 'U':
*idx += 1;
size = 0; /* fallback value if errors */
if (ljust != 0 || plus != 0 || ld_zero != 0 || width != -1 ||
prec != -1) {
vpi_printf("WARNING: invalid format %s%s.\n", info->name, fmtb);
@ -1610,7 +1615,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
veclen = (vpi_get(vpiSize, info->items[*idx])+31)/32;
size = veclen * 4 + 1;
/* If the default buffer is too small, make it big enough. */
if (size > max_size) result = realloc(result, size*sizeof(char));
if (size > ini_size) result = realloc(result, size*sizeof(char));
cp = result;
for (word = 0; word < veclen; word += 1) {
bits = value.value.vector[word].aval &
@ -1647,22 +1652,34 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
vpi_printf("WARNING: incompatible value for %s%s.\n", info->name,
fmtb);
} else {
char tbuf[4];
char tbuf[4], *rbuf;
PLI_INT32 nbits;
unsigned rsize;
int bit;
/* If a width was not given use a width of zero. */
if (width == -1) width = 0;
vpip_format_strength(tbuf, &value);
if (ljust == 0) sprintf(result, "%*s", width, tbuf);
else sprintf(result, "%-*s", width, tbuf);
}
nbits = vpi_get(vpiSize, info->items[*idx]);
rsize = nbits*3 + 1;
rbuf = malloc(rsize*sizeof(char));
if (rsize > ini_size) result = realloc(result, rsize*sizeof(char));
strcpy(rbuf, "");
for (bit = nbits-1; bit >= 0; bit -= 1) {
vpip_format_strength(tbuf, &value, bit);
strcat(rbuf, tbuf);
}
if (ljust == 0) sprintf(result, "%*s", width, rbuf);
else sprintf(result, "%-*s", width, rbuf);
free(rbuf);
size = strlen(result) + 1;
}
}
break;
case 'z':
case 'Z':
*idx += 1;
size = 0; /* fallback value if errors */
size = strlen(result) + 1; /* fallback value if errors */
if (ljust != 0 || plus != 0 || ld_zero != 0 || width != -1 ||
prec != -1) {
vpi_printf("WARNING: invalid format %s%s.\n", info->name, fmtb);
@ -1682,7 +1699,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
veclen = (vpi_get(vpiSize, info->items[*idx])+31)/32;
size = 2 * veclen * 4 + 1;
/* If the default buffer is too small, make it big enough. */
if (size > max_size) result = realloc(result, size*sizeof(char));
if (size > ini_size) result = realloc(result, size*sizeof(char));
cp = result;
for (word = 0; word < veclen; word += 1) {
/* Write the aval followed by the bval in endian order. */

View File

@ -1,7 +1,7 @@
#ifndef __vpi_user_H
#define __vpi_user_H
/*
* Copyright (c) 1999-2007 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2008 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
@ -560,7 +560,7 @@ extern DLLEXPORT void (*vlog_startup_routines[])();
/* Format a scalar a la %v. The str points to a 4byte character
buffer. The value must be a vpiStrengthVal. */
extern void vpip_format_strength(char*str, s_vpi_value*value);
extern void vpip_format_strength(char*str, s_vpi_value*value, unsigned bit);
EXTERN_C_END

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2008 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
@ -16,9 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpip_format.c,v 1.1 2003/04/20 02:49:07 steve Exp $"
#endif
# include <vpi_user.h>
# include <assert.h>
@ -44,7 +41,7 @@ static const char str_char2_table[256] = {
"50102010" "30102010" /* E0 EF */ "40102010" "30102010" /* F0 FF */ };
void vpip_format_strength(char*str, s_vpi_value*value)
void vpip_format_strength(char*str, s_vpi_value*value, unsigned bit)
{
str[0] = '.';
str[1] = '.';
@ -53,42 +50,42 @@ void vpip_format_strength(char*str, s_vpi_value*value)
assert(value->format == vpiStrengthVal);
switch (value->value.strength[0].logic) {
switch (value->value.strength[bit].logic) {
case vpi0:
str[0] = str_char1_table[value->value.strength[0].s0];
str[1] = str_char2_table[value->value.strength[0].s0];
str[0] = str_char1_table[value->value.strength[bit].s0];
str[1] = str_char2_table[value->value.strength[bit].s0];
str[2] = '0';
break;
case vpi1:
str[0] = str_char1_table[value->value.strength[0].s1];
str[1] = str_char2_table[value->value.strength[0].s1];
str[0] = str_char1_table[value->value.strength[bit].s1];
str[1] = str_char2_table[value->value.strength[bit].s1];
str[2] = '1';
break;
case vpiX:
if (value->value.strength[0].s0 == 1) {
str[0] = str_char1_table[value->value.strength[0].s1];
str[1] = str_char2_table[value->value.strength[0].s1];
if (value->value.strength[bit].s0 == 1) {
str[0] = str_char1_table[value->value.strength[bit].s1];
str[1] = str_char2_table[value->value.strength[bit].s1];
str[2] = 'H';
} else if (value->value.strength[0].s1 == 1) {
str[0] = str_char1_table[value->value.strength[0].s0];
str[1] = str_char2_table[value->value.strength[0].s0];
} else if (value->value.strength[bit].s1 == 1) {
str[0] = str_char1_table[value->value.strength[bit].s0];
str[1] = str_char2_table[value->value.strength[bit].s0];
str[2] = 'L';
} else if (value->value.strength[0].s1 ==
value->value.strength[0].s0) {
str[0] = str_char1_table[value->value.strength[0].s0];
str[1] = str_char2_table[value->value.strength[0].s0];
} else if (value->value.strength[bit].s1 ==
value->value.strength[bit].s0) {
str[0] = str_char1_table[value->value.strength[bit].s0];
str[1] = str_char2_table[value->value.strength[bit].s0];
str[2] = 'X';
} else {
int ss;
str[0] = '0';
ss = value->value.strength[0].s0;
ss = value->value.strength[bit].s0;
while (ss > 1) {
str[0] += 1;
ss >>= 1;
}
str[1] = '0';
ss = value->value.strength[0].s1;
ss = value->value.strength[bit].s1;
while (ss > 1) {
str[1] += 1;
ss >>= 1;
@ -103,8 +100,7 @@ void vpip_format_strength(char*str, s_vpi_value*value)
break;
default:
fprintf(stderr, "Unsupported type %d.\n",
value->value.strength[0].logic);
value->value.strength[bit].logic);
assert(0);
}
}