From 10f106f3548b73631feca30297a1fa7a450e1c6d Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 20 Mar 2009 13:21:12 -0700 Subject: [PATCH] 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 (when available) than building our own value. This allows MinGW to use the non-standard I64. (cherry picked from commit d237e3507641af8b8ce871101154b07d3fe39772) --- vvp/config.h.in | 38 ++++++++++++++++++++++++++++++++------ vvp/stop.cc | 2 +- vvp/vpi_time.cc | 6 +++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/vvp/config.h.in b/vvp/config.h.in index ef94b3202..a9d5605f1 100644 --- a/vvp/config.h.in +++ b/vvp/config.h.in @@ -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 -#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 /* getrusage, /proc/self/statm */ diff --git a/vvp/stop.cc b/vvp/stop.cc index d3da3fe3f..07b6e2af8 100644 --- a/vvp/stop.cc +++ b/vvp/stop.cc @@ -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; diff --git a/vvp/vpi_time.cc b/vvp/vpi_time.cc index 7876208e8..d434b7ac8 100644 --- a/vvp/vpi_time.cc +++ b/vvp/vpi_time.cc @@ -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;