From be4be5c650213dd47231b5e3bbeacb477da2f71d Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 4 Feb 2003 04:03:40 +0000 Subject: [PATCH] Add hex and binary formatting of real values. --- vvp/vpi_real.cc | 39 +++++++++++++++++++++++++++++++++++++-- vvp/vpi_vthr_vector.cc | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/vvp/vpi_real.cc b/vvp/vpi_real.cc index 456df4dfc..342d141af 100644 --- a/vvp/vpi_real.cc +++ b/vvp/vpi_real.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_real.cc,v 1.3 2003/02/02 01:40:24 steve Exp $" +#ident "$Id: vpi_real.cc,v 1.4 2003/02/04 04:03:40 steve Exp $" #endif # include "vpi_priv.h" @@ -39,7 +39,7 @@ static void real_var_get_value(vpiHandle ref, s_vpi_value*vp) { assert(ref->vpi_type->type_code == vpiRealVar); - static char buf[64]; + static char buf[66]; struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref; switch (vp->format) { @@ -48,11 +48,43 @@ static void real_var_get_value(vpiHandle ref, s_vpi_value*vp) case vpiRealVal: vp->value.real = rfp->value; break; + case vpiDecStrVal: sprintf(buf, "%0.0f", rfp->value); vp->value.str = buf; break; + case vpiHexStrVal: + sprintf(buf, "%lx", (long)rfp->value); + vp->value.str = buf; + break; + + case vpiBinStrVal: { + unsigned long val = (unsigned long)rfp->value; + unsigned len = 0; + + assert(8*sizeof(val) < sizeof buf); + + while (val > 0) { + len += 1; + val /= 2; + } + + val = (unsigned long)rfp->value; + for (unsigned idx = 0 ; idx < len ; idx += 1) { + buf[len-idx-1] = (val & 1)? '1' : '0'; + val /= 2; + } + + buf[len] = 0; + if (len == 0) { + buf[0] = '0'; + buf[1] = 0; + } + vp->value.str = buf; + break; + } + default: fprintf(stderr, "ERROR: Unsupported format code: %d\n", vp->format); @@ -101,6 +133,9 @@ vpiHandle vpip_make_real_var(const char*name) /* * $Log: vpi_real.cc,v $ + * Revision 1.4 2003/02/04 04:03:40 steve + * Add hex and binary formatting of real values. + * * Revision 1.3 2003/02/02 01:40:24 steve * Five vpi_free_object a default behavior. * diff --git a/vvp/vpi_vthr_vector.cc b/vvp/vpi_vthr_vector.cc index 625c7b57d..58971f382 100644 --- a/vvp/vpi_vthr_vector.cc +++ b/vvp/vpi_vthr_vector.cc @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_vthr_vector.cc,v 1.9 2003/01/26 18:16:22 steve Exp $" +#ident "$Id: vpi_vthr_vector.cc,v 1.10 2003/02/04 04:03:40 steve Exp $" #endif /* @@ -373,7 +373,7 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp) struct __vpiVThrWord*obj = (struct __vpiVThrWord*)ref; - static char buf[64]; + static char buf[66]; double val = vthread_get_real(vpip_current_vthread, obj->index); switch (vp->format) { @@ -389,6 +389,37 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp) vp->value.str = buf; break; + case vpiHexStrVal: + sprintf(buf, "%lx", (long)val); + vp->value.str = buf; + break; + + case vpiBinStrVal: { + unsigned long vali = (unsigned long)val; + unsigned len = 0; + + assert(8*sizeof(vali) < sizeof buf); + + while (vali > 0) { + len += 1; + vali /= 2; + } + + vali = (unsigned long)val; + for (unsigned idx = 0 ; idx < len ; idx += 1) { + buf[len-idx-1] = (vali & 1)? '1' : '0'; + vali /= 2; + } + + buf[len] = 0; + if (len == 0) { + buf[0] = '0'; + buf[1] = 0; + } + vp->value.str = buf; + break; + } + default: vp->format = vpiSuppressVal; break; @@ -422,6 +453,9 @@ vpiHandle vpip_make_vthr_word(unsigned base, const char*type) /* * $Log: vpi_vthr_vector.cc,v $ + * Revision 1.10 2003/02/04 04:03:40 steve + * Add hex and binary formatting of real values. + * * Revision 1.9 2003/01/26 18:16:22 steve * Add %cvt/ir and %cvt/ri instructions, and support * real values passed as arguments to VPI tasks.