Fix printf format for size_t values when using 64-bit MinGW.

The Microsoft C runtime does not support the %zu and %zd formats.
Previously these were replaced with %u and %d, but for 64-bit we
need to use %llu and %lld.
This commit is contained in:
Martin Whitaker 2015-05-08 20:20:14 +01:00
parent 3069b8dd51
commit 6a3edc63d5
6 changed files with 33 additions and 30 deletions

View File

@ -27,6 +27,10 @@
# endif
#endif
# define SIZEOF_UNSIGNED_LONG_LONG 0
# define SIZEOF_SIZE_T 0
# undef NEED_LU
# undef NEED_TU
# undef WLU
@ -62,4 +66,14 @@
*/
# undef CHECK_WITH_VALGRIND
#ifdef __MINGW32__
# if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG
# define SIZE_FMT_D "llu"
# else
# define SIZE_FMT_D "u"
# endif
#else
# define SIZE_FMT_D "zu"
#endif
#endif /* IVL_config_H */

View File

@ -131,6 +131,7 @@ CXXFLAGS="$iverilog_temp_cxxflags"
AC_CHECK_SIZEOF(unsigned long long)
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(unsigned)
AC_CHECK_SIZEOF(size_t)
# vvp uses these...
AC_CHECK_LIB(termcap, tputs)

View File

@ -1898,11 +1898,7 @@ static int load_next_input(void)
static void do_dump_precompiled_defines(FILE* out, struct define_t* table)
{
if (!table->keyword)
#ifdef __MINGW32__ /* MinGW does not know about z. */
fprintf(out, "%s:%d:%d:%s\n", table->name, table->argc, strlen(table->value), table->value);
#else
fprintf(out, "%s:%d:%zd:%s\n", table->name, table->argc, strlen(table->value), table->value);
#endif
fprintf(out, "%s:%d:%" SIZE_FMT_D ":%s\n", table->name, table->argc, strlen(table->value), table->value);
if (table->left) do_dump_precompiled_defines(out, table->left);

View File

@ -33,6 +33,8 @@
#endif
# define SIZEOF_UNSIGNED 0
# define SIZEOF_SIZE_T 0
# undef NEED_LU
# undef NEED_TU
# undef WLU
@ -133,6 +135,16 @@ typedef unsigned long vvp_time64_t;
#endif /* HAVE_INTTYPES_H */
#ifdef __MINGW32__
# if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG
# define SIZE_FMT_U "llu"
# else
# define SIZE_FMT_U "u"
# endif
#else
# define SIZE_FMT_U "zu"
#endif
# include <cmath>
/* getrusage, /proc/self/statm */

View File

@ -464,34 +464,18 @@ int main(int argc, char*argv[])
}
if (verbose_flag) {
#ifdef __MINGW32__ /* MinGW does not know about z. */
vpi_mcd_printf(1, " ... %8lu functors (net_fun pool=%u bytes)\n",
#else
vpi_mcd_printf(1, " ... %8lu functors (net_fun pool=%zu bytes)\n",
#endif
vpi_mcd_printf(1, " ... %8lu functors (net_fun pool=%" SIZE_FMT_U " bytes)\n",
count_functors, vvp_net_fun_t::heap_total());
vpi_mcd_printf(1, " %8lu logic\n", count_functors_logic);
vpi_mcd_printf(1, " %8lu bufif\n", count_functors_bufif);
vpi_mcd_printf(1, " %8lu resolv\n",count_functors_resolv);
vpi_mcd_printf(1, " %8lu signals\n", count_functors_sig);
#ifdef __MINGW32__ /* MinGW does not know about z. */
vpi_mcd_printf(1, " ... %8lu filters (net_fil pool=%u bytes)\n",
#else
vpi_mcd_printf(1, " ... %8lu filters (net_fil pool=%zu bytes)\n",
#endif
vpi_mcd_printf(1, " ... %8lu filters (net_fil pool=%" SIZE_FMT_U " bytes)\n",
count_filters, vvp_net_fil_t::heap_total());
#ifdef __MINGW32__ /* MinGW does not know about z. */
vpi_mcd_printf(1, " ... %8lu opcodes (%u bytes)\n",
#else
vpi_mcd_printf(1, " ... %8lu opcodes (%zu bytes)\n",
#endif
vpi_mcd_printf(1, " ... %8lu opcodes (%" SIZE_FMT_U " bytes)\n",
count_opcodes, size_opcodes);
vpi_mcd_printf(1, " ... %8lu nets\n", count_vpi_nets);
#ifdef __MINGW32__ /* MinGW does not know about z. */
vpi_mcd_printf(1, " ... %8lu vvp_nets (%u bytes)\n",
#else
vpi_mcd_printf(1, " ... %8lu vvp_nets (%zu bytes)\n",
#endif
vpi_mcd_printf(1, " ... %8lu vvp_nets (%" SIZE_FMT_U " bytes)\n",
count_vvp_nets, size_vvp_nets);
vpi_mcd_printf(1, " ... %8lu arrays (%lu words)\n",
count_net_arrays, count_net_array_words);

View File

@ -266,11 +266,7 @@ void vvp_udp_comb_s::compile_table(char**tab)
cur.maskx = 0;
if (port_count() > 8*sizeof(cur.mask0)) {
fprintf(stderr, "internal error: primitive port count=%u "
#ifdef __MINGW32__ /* MinGW does not know about z. */
" > %u\n", port_count(), sizeof(cur.mask0));
#else
" > %zu\n", port_count(), sizeof(cur.mask0));
#endif
" > %" SIZE_FMT_U "\n", port_count(), sizeof(cur.mask0));
assert(port_count() <= 8*sizeof(cur.mask0));
}
for (unsigned pp = 0 ; pp < port_count() ; pp += 1) {