Add vpiOctStrVal access to signals.

This commit is contained in:
steve 2001-03-25 20:45:09 +00:00
parent 25d25ff7fe
commit f7f5ccce05
2 changed files with 99 additions and 2 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: draw_tt.c,v 1.2 2001/03/25 19:37:26 steve Exp $"
#ident "$Id: draw_tt.c,v 1.3 2001/03/25 20:45:09 steve Exp $"
#endif
# include <stdio.h>
@ -156,6 +156,11 @@ static void draw_OR(void)
printf("};\n");
}
/*
* The hex_digits table is not a functor truth table per say, but a
* map of a 4-vbit value to a hex digit. The table handles the display
* of x, X, z, Z, etc.
*/
static void draw_hex_table()
{
unsigned idx;
@ -202,6 +207,52 @@ static void draw_hex_table()
printf("};\n");
}
static void draw_oct_table()
{
unsigned idx;
printf("extern const char oct_digits[64] = {\n");
for (idx = 0 ; idx < 64 ; idx += 1) {
unsigned cnt_z = 0, cnt_x = 0;
unsigned bv = 0, bdx;
for (bdx = 0 ; bdx < 3 ; bdx += 1) {
switch ((idx >> (bdx * 2)) & 3) {
case 0:
break;
case 1:
bv |= 1<<bdx;
break;
case 2:
cnt_x += 1;
break;
case 3:
cnt_z += 1;
break;
}
}
if (cnt_z == 3)
printf(" 'z',");
else if (cnt_x == 3)
printf(" 'x',");
else if ((cnt_z > 0) && (cnt_x == 0))
printf(" 'Z',");
else if (cnt_x > 0)
printf(" 'X',");
else
printf(" '%c',", "01234567"[bv]);
if (((idx+1) % 8) == 0)
printf("\n");
}
printf("};\n");
}
main()
{
printf("# include \"functor.h\"\n");
@ -210,11 +261,15 @@ main()
draw_NOT();
draw_OR();
draw_hex_table();
draw_oct_table();
return 0;
}
/*
* $Log: draw_tt.c,v $
* Revision 1.3 2001/03/25 20:45:09 steve
* Add vpiOctStrVal access to signals.
*
* Revision 1.2 2001/03/25 19:37:26 steve
* Calculate NOR and NOT tables, and also the hex_digits table.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_signal.cc,v 1.4 2001/03/25 19:38:05 steve Exp $"
#ident "$Id: vpi_signal.cc,v 1.5 2001/03/25 20:45:10 steve Exp $"
#endif
/*
@ -30,8 +30,21 @@
# include <malloc.h>
# include <assert.h>
/*
* Hex digits that represent 4-value bits of Verilog are not as
* trivially obvious to display as if the bits were the usual 2-value
* bits. So, although it is possible to write a function that
* generates a correct character for 4*4-value bits, it is easier to
* just perform the lookup in a table. This only takes 256 bytes,
* which is not many executable instructions:-)
*
* The table is calculated as compile time, therefore, by the
* draw_tt.c program.
*/
extern const char hex_digits[256];
extern const char oct_digits[256];
/*
* implement vpi_get for vpiReg objects.
*/
@ -132,6 +145,32 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
break;
}
case vpiOctStrVal: {
unsigned hval, hwid;
hwid = (wid + 2) / 3;
buf[hwid] = 0;
hval = 0;
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx);
functor_t fp = functor_index(fptr);
hval = hval | ((fp->oval&3) << 2*(idx % 3));
if (idx%3 == 2) {
hwid -= 1;
buf[hwid] = oct_digits[hval];
hval = 0;
}
}
if (hwid > 0) {
hwid -= 1;
buf[hwid] = oct_digits[hval];
hval = 0;
}
vp->value.str = buf;
break;
}
default:
/* XXXX Not implemented yet. */
assert(0);
@ -221,6 +260,9 @@ vpiHandle vpip_make_net(char*name, int msb, int lsb, vvp_ipoint_t base)
/*
* $Log: vpi_signal.cc,v $
* Revision 1.5 2001/03/25 20:45:10 steve
* Add vpiOctStrVal access to signals.
*
* Revision 1.4 2001/03/25 19:38:05 steve
* Support making hex strings.
*