Make vvp use inttypes for the 64 bit printing info.

To get the correct print format for a 64 bit value it is much
better to use <inttypes.h> (when available) than building our
own value. This allows MinGW to use the non-standard I64.
(cherry picked from commit d237e35076)
This commit is contained in:
Cary R 2009-03-20 13:21:12 -07:00 committed by Stephen Williams
parent ff450cdcb8
commit 10f106f354
3 changed files with 36 additions and 10 deletions

View File

@ -50,7 +50,7 @@
# undef HAVE_NAN
/*
* Define this is you want to compile vvp with memory freeing and
* Define this if you want to compile vvp with memory freeing and
* special valgrind hooks for the memory pools.
*/
# undef CHECK_WITH_VALGRIND
@ -68,29 +68,55 @@
#endif
#ifdef HAVE_INTTYPES_H
/* This is needed in C++ to get the PRI?64 formats. */
# ifndef __STDC_FORMAT_MACROS
# define __STDC_FORMAT_MACROS
# endif
# include <inttypes.h>
#endif
typedef uint64_t vvp_time64_t;
# define TIME_FMT_O PRIo64
# define TIME_FMT_U PRIu64
# define TIME_FMT_X PRIx64
# if SIZEOF_UNSIGNED_LONG == 8
# define UL_AND_TIME64_SAME
# endif
#else /* HAVE_INTTYPES_H */
#if SIZEOF_UNSIGNED >= 8
typedef unsigned vvp_time64_t;
# define TIME_FMT ""
# define TIME_FMT_O "o"
# define TIME_FMT_U "u"
# define TIME_FMT_X "x"
#else
# if SIZEOF_UNSIGNED_LONG >= 8
typedef unsigned long vvp_time64_t;
# define UL_AND_TIME64_SAME
# define TIME_FMT "l"
# define TIME_FMT_O "lo"
# define TIME_FMT_U "lu"
# define TIME_FMT_X "lx"
# else
# if SIZEOF_UNSIGNED_LONG_LONG > SIZEOF_UNSIGNED_LONG
typedef unsigned long long vvp_time64_t;
# define TIME_FMT "ll"
# define TIME_FMT_O "llo"
# define TIME_FMT_U "llu"
# define TIME_FMT_X "llx"
# else
typedef unsigned long vvp_time64_t;
# define UL_AND_TIME64_SAME
# define TIME_FMT "l"
# define TIME_FMT_O "lo"
# define TIME_FMT_U "lu"
# define TIME_FMT_X "lx"
# endif
# endif
#endif
#endif /* HAVE_INTTYPES_H */
# include <math.h>
/* getrusage, /proc/self/statm */

View File

@ -483,7 +483,7 @@ void stop_handler(int rc)
}
vpi_mcd_printf(1,"** VVP Stop(%d) **\n", rc);
vpi_mcd_printf(1,"** Current simulation time is %" TIME_FMT "u ticks.\n",
vpi_mcd_printf(1,"** Current simulation time is %" TIME_FMT_U " ticks.\n",
schedule_simtime());
interact_flag = true;

View File

@ -265,17 +265,17 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp, bool is_int_func,
break;
case vpiDecStrVal:
sprintf(rbuf, "%" TIME_FMT "u", simtime);
sprintf(rbuf, "%" TIME_FMT_U, simtime);
vp->value.str = rbuf;
break;
case vpiOctStrVal:
sprintf(rbuf, "%" TIME_FMT "o", simtime);
sprintf(rbuf, "%" TIME_FMT_O, simtime);
vp->value.str = rbuf;
break;
case vpiHexStrVal:
sprintf(rbuf, "%" TIME_FMT "x", simtime);
sprintf(rbuf, "%" TIME_FMT_X, simtime);
vp->value.str = rbuf;
break;