Add hex and binary formatting of real values.
This commit is contained in:
parent
ce489d8d84
commit
be4be5c650
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_CVS_IDENT
|
#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
|
#endif
|
||||||
|
|
||||||
# include "vpi_priv.h"
|
# 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);
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
||||||
|
|
||||||
static char buf[64];
|
static char buf[66];
|
||||||
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
||||||
|
|
||||||
switch (vp->format) {
|
switch (vp->format) {
|
||||||
|
|
@ -48,11 +48,43 @@ static void real_var_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
case vpiRealVal:
|
case vpiRealVal:
|
||||||
vp->value.real = rfp->value;
|
vp->value.real = rfp->value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case vpiDecStrVal:
|
case vpiDecStrVal:
|
||||||
sprintf(buf, "%0.0f", rfp->value);
|
sprintf(buf, "%0.0f", rfp->value);
|
||||||
vp->value.str = buf;
|
vp->value.str = buf;
|
||||||
break;
|
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:
|
default:
|
||||||
fprintf(stderr, "ERROR: Unsupported format code: %d\n",
|
fprintf(stderr, "ERROR: Unsupported format code: %d\n",
|
||||||
vp->format);
|
vp->format);
|
||||||
|
|
@ -101,6 +133,9 @@ vpiHandle vpip_make_real_var(const char*name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_real.cc,v $
|
* $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
|
* Revision 1.3 2003/02/02 01:40:24 steve
|
||||||
* Five vpi_free_object a default behavior.
|
* Five vpi_free_object a default behavior.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_CVS_IDENT
|
#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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -373,7 +373,7 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
|
|
||||||
struct __vpiVThrWord*obj = (struct __vpiVThrWord*)ref;
|
struct __vpiVThrWord*obj = (struct __vpiVThrWord*)ref;
|
||||||
|
|
||||||
static char buf[64];
|
static char buf[66];
|
||||||
double val = vthread_get_real(vpip_current_vthread, obj->index);
|
double val = vthread_get_real(vpip_current_vthread, obj->index);
|
||||||
|
|
||||||
switch (vp->format) {
|
switch (vp->format) {
|
||||||
|
|
@ -389,6 +389,37 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
vp->value.str = buf;
|
vp->value.str = buf;
|
||||||
break;
|
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:
|
default:
|
||||||
vp->format = vpiSuppressVal;
|
vp->format = vpiSuppressVal;
|
||||||
break;
|
break;
|
||||||
|
|
@ -422,6 +453,9 @@ vpiHandle vpip_make_vthr_word(unsigned base, const char*type)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: vpi_vthr_vector.cc,v $
|
* $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
|
* Revision 1.9 2003/01/26 18:16:22 steve
|
||||||
* Add %cvt/ir and %cvt/ri instructions, and support
|
* Add %cvt/ir and %cvt/ri instructions, and support
|
||||||
* real values passed as arguments to VPI tasks.
|
* real values passed as arguments to VPI tasks.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue