From cfbc90812bb8a650cc073094940a8dcdba37b0ce Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 10 May 2015 11:45:42 +0100 Subject: [PATCH] Enable use of MinGW ANSI stdio routines. Defining __USE_MINGW_ANSI_STDIO=1 provides C99 compatible printf and scanf routines, which avoids the need for workarounds for the various failings of the Microsoft C runtime library. --- config.h.in | 14 -------------- configure.in | 5 ++++- ivlpp/lexor.lex | 2 +- tgt-vvp/draw_net_input.c | 4 ---- tgt-vvp/draw_vpi.c | 4 ---- tgt-vvp/modpath.c | 4 ---- tgt-vvp/stmt_assign.c | 5 ----- tgt-vvp/vvp_priv.h | 5 ----- tgt-vvp/vvp_process.c | 4 ---- vpi_user.h | 9 ++++++++- vvp/config.h.in | 18 ------------------ vvp/main.cc | 8 ++++---- vvp/udp.cc | 2 +- vvp/vpi_mcd.cc | 26 -------------------------- 14 files changed, 18 insertions(+), 92 deletions(-) diff --git a/config.h.in b/config.h.in index 8bac481be..30470a22b 100644 --- a/config.h.in +++ b/config.h.in @@ -27,10 +27,6 @@ # endif #endif -# define SIZEOF_UNSIGNED_LONG_LONG 0 - -# define SIZEOF_SIZE_T 0 - # undef NEED_LU # undef NEED_TU # undef WLU @@ -66,14 +62,4 @@ */ # 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 */ diff --git a/configure.in b/configure.in index 8d9be4ad9..1ddbfa86b 100644 --- a/configure.in +++ b/configure.in @@ -131,7 +131,6 @@ 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) @@ -224,6 +223,10 @@ case "${host}" in CPPFLAGS="-mieee $CPPFLAGS" CFLAGS="-mieee $CFLAGS" ;; + *-*-mingw*) + CXXFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $CXXFLAGS" + CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $CFLAGS" + ;; esac # Do some more operating system specific setup. We put the file64_support diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 38b78c995..ea84b86e0 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1898,7 +1898,7 @@ static int load_next_input(void) static void do_dump_precompiled_defines(FILE* out, struct define_t* table) { if (!table->keyword) - fprintf(out, "%s:%d:%" SIZE_FMT_D ":%s\n", table->name, table->argc, strlen(table->value), table->value); + fprintf(out, "%s:%d:%zd:%s\n", table->name, table->argc, strlen(table->value), table->value); if (table->left) do_dump_precompiled_defines(out, table->left); diff --git a/tgt-vvp/draw_net_input.c b/tgt-vvp/draw_net_input.c index 906be39a0..fe040601b 100644 --- a/tgt-vvp/draw_net_input.c +++ b/tgt-vvp/draw_net_input.c @@ -26,10 +26,6 @@ # include # include "ivl_alloc.h" -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - static ivl_signal_type_t signal_type_of_nexus(ivl_nexus_t nex) { unsigned idx; diff --git a/tgt-vvp/draw_vpi.c b/tgt-vvp/draw_vpi.c index 8e7f21642..3587815eb 100644 --- a/tgt-vvp/draw_vpi.c +++ b/tgt-vvp/draw_vpi.c @@ -23,10 +23,6 @@ # include # include "ivl_alloc.h" -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - struct args_info { char*text; /* True ('s' or 'u' if this argument is a calculated vec4. */ diff --git a/tgt-vvp/modpath.c b/tgt-vvp/modpath.c index 4c904496d..bdaf72e93 100644 --- a/tgt-vvp/modpath.c +++ b/tgt-vvp/modpath.c @@ -23,10 +23,6 @@ # include # include "ivl_alloc.h" -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - static ivl_signal_t find_path_source_port(ivl_delaypath_t path) { unsigned idx; diff --git a/tgt-vvp/stmt_assign.c b/tgt-vvp/stmt_assign.c index e2456ae25..7a788e807 100644 --- a/tgt-vvp/stmt_assign.c +++ b/tgt-vvp/stmt_assign.c @@ -22,11 +22,6 @@ # include # include -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - - /* * These functions handle the blocking assignment. Use the %set * instruction to perform the actual assignment, and calculate any diff --git a/tgt-vvp/vvp_priv.h b/tgt-vvp/vvp_priv.h index 7f0fbac77..e23916e03 100644 --- a/tgt-vvp/vvp_priv.h +++ b/tgt-vvp/vvp_priv.h @@ -23,11 +23,6 @@ # include "ivl_target.h" # include -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - - extern int debug_draw; /* diff --git a/tgt-vvp/vvp_process.c b/tgt-vvp/vvp_process.c index ffa07493c..3980b9575 100644 --- a/tgt-vvp/vvp_process.c +++ b/tgt-vvp/vvp_process.c @@ -23,10 +23,6 @@ # include # include -#ifdef __MINGW32__ /* MinGW has inconsistent %p output. */ -#define snprintf _snprintf -#endif - static int show_statement(ivl_statement_t net, ivl_scope_t sscope); unsigned local_count = 0; diff --git a/vpi_user.h b/vpi_user.h index 7bef96669..52f9a5f78 100644 --- a/vpi_user.h +++ b/vpi_user.h @@ -421,10 +421,17 @@ extern PLI_UINT32 vpi_mcd_open(char *name); extern PLI_UINT32 vpi_mcd_close(PLI_UINT32 mcd); extern char *vpi_mcd_name(PLI_UINT32 mcd); extern PLI_INT32 vpi_mcd_printf(PLI_UINT32 mcd, const char*fmt, ...) +#ifdef __MINGW32__ + __attribute__((format (gnu_printf,2,3))); +#else __attribute__((format (printf,2,3))); - +#endif extern PLI_INT32 vpi_printf(const char*fmt, ...) +#ifdef __MINGW32__ + __attribute__((format (gnu_printf,1,2))); +#else __attribute__((format (printf,1,2))); +#endif extern PLI_INT32 vpi_vprintf(const char*fmt, va_list ap); extern PLI_INT32 vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap); diff --git a/vvp/config.h.in b/vvp/config.h.in index 1a7151ac3..f21883dbe 100644 --- a/vvp/config.h.in +++ b/vvp/config.h.in @@ -33,8 +33,6 @@ #endif # define SIZEOF_UNSIGNED 0 -# define SIZEOF_SIZE_T 0 - # undef NEED_LU # undef NEED_TU # undef WLU @@ -88,15 +86,9 @@ typedef uint64_t vvp_time64_t; -#ifdef __MINGW32__ -# define TIME_FMT_O "I64o" -# define TIME_FMT_U "I64u" -# define TIME_FMT_X "I64x" -#else # define TIME_FMT_O PRIo64 # define TIME_FMT_U PRIu64 # define TIME_FMT_X PRIx64 -#endif # ifdef UINT64_T_AND_ULONG_SAME # define UL_AND_TIME64_SAME @@ -135,16 +127,6 @@ 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 /* getrusage, /proc/self/statm */ diff --git a/vvp/main.cc b/vvp/main.cc index 801ee4e35..94909d076 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -464,18 +464,18 @@ int main(int argc, char*argv[]) } if (verbose_flag) { - vpi_mcd_printf(1, " ... %8lu functors (net_fun pool=%" SIZE_FMT_U " bytes)\n", + vpi_mcd_printf(1, " ... %8lu functors (net_fun pool=%zu 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); - vpi_mcd_printf(1, " ... %8lu filters (net_fil pool=%" SIZE_FMT_U " bytes)\n", + vpi_mcd_printf(1, " ... %8lu filters (net_fil pool=%zu bytes)\n", count_filters, vvp_net_fil_t::heap_total()); - vpi_mcd_printf(1, " ... %8lu opcodes (%" SIZE_FMT_U " bytes)\n", + vpi_mcd_printf(1, " ... %8lu opcodes (%zu bytes)\n", count_opcodes, size_opcodes); vpi_mcd_printf(1, " ... %8lu nets\n", count_vpi_nets); - vpi_mcd_printf(1, " ... %8lu vvp_nets (%" SIZE_FMT_U " bytes)\n", + vpi_mcd_printf(1, " ... %8lu vvp_nets (%zu bytes)\n", count_vvp_nets, size_vvp_nets); vpi_mcd_printf(1, " ... %8lu arrays (%lu words)\n", count_net_arrays, count_net_array_words); diff --git a/vvp/udp.cc b/vvp/udp.cc index 8ea8b8e06..b311debd4 100644 --- a/vvp/udp.cc +++ b/vvp/udp.cc @@ -266,7 +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 " - " > %" SIZE_FMT_U "\n", port_count(), sizeof(cur.mask0)); + " > %zu\n", port_count(), sizeof(cur.mask0)); assert(port_count() <= 8*sizeof(cur.mask0)); } for (unsigned pp = 0 ; pp < port_count() ; pp += 1) { diff --git a/vvp/vpi_mcd.cc b/vvp/vpi_mcd.cc index d02bf174a..7a092c3c7 100644 --- a/vvp/vpi_mcd.cc +++ b/vvp/vpi_mcd.cc @@ -191,31 +191,6 @@ vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap) } va_copy(saved_ap, ap); -#ifdef __MINGW32__ - /* - * The MinGW runtime (version 3.14) fixes some things, but breaks - * %f for us, so we have to us the underlying version. - */ - rc = _vsnprintf(buffer, sizeof buffer, fmt, ap); - /* - * Windows returns -1 to indicate the result was truncated (thanks for - * following the standard!). Since we don't know how big to make the - * buffer just keep doubling it until it works. - */ - if (rc == -1) { - size_t buf_size = sizeof buffer; - buf_ptr = NULL; - need_free = true; - while (rc == -1) { - va_list tmp_ap; - va_copy(tmp_ap, saved_ap); - buf_size *= 2; - buf_ptr = (char *)realloc(buf_ptr, buf_size); - rc = vsnprintf(buf_ptr, buf_size, fmt, tmp_ap); - va_end(tmp_ap); - } - } -#else rc = vsnprintf(buffer, sizeof buffer, fmt, ap); assert(rc >= 0); /* @@ -227,7 +202,6 @@ vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap) need_free = true; rc = vsnprintf(buf_ptr, rc+1, fmt, saved_ap); } -#endif va_end(saved_ap); for(int i = 0; i < 31; i++) {