From 8dca56521b014d1cae1f3bda43c9ece3efb452eb Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 1 Feb 2010 09:28:53 -0500 Subject: [PATCH] Fix MinGW compilation printing %lls, bug214 --- Changes | 2 +- include/verilated.cpp | 14 +++++----- include/verilated_vcd_c.cpp | 2 +- include/verilatedos.h | 10 +++++++ nodist/spdiff | 1 + src/V3EmitC.cpp | 10 +++---- src/V3File.cpp | 4 +-- src/V3Options.cpp | 6 ++-- .../{t_dist_uint.pl => t_dist_portability.pl} | 28 +++++++++++++++++-- test_regress/t/t_dpi_export_c.cpp | 3 +- test_regress/t/t_leak.cpp | 6 ++-- test_regress/t/t_math_imm2.cpp | 2 +- 12 files changed, 62 insertions(+), 26 deletions(-) rename test_regress/t/{t_dist_uint.pl => t_dist_portability.pl} (69%) diff --git a/Changes b/Changes index 4563c75a2..b0c9de3ce 100644 --- a/Changes +++ b/Changes @@ -70,7 +70,7 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix MSVC++ 2008 compile issues, bug209. [Amir Gonnen] -**** Fix MinGW compilation, bug184. [by Shankar Giri] +**** Fix MinGW compilation, bug184, bug214. [by Shankar Giri, Amir Gonnen] **** Fix Cygwin 1.7.x compiler error with uint32_t, bug204. [Ivan Djordjevic] diff --git a/include/verilated.cpp b/include/verilated.cpp index dbb85ad97..d632eb1ce 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -344,14 +344,14 @@ void _vl_vsformat(string& output, const char* formatp, va_list ap) { } break; case 'd': { // Signed decimal - int digits=sprintf(tmp,"%lld",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld))); + int digits=sprintf(tmp,"%" VL_PRI64 "d",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld))); int needmore = width-digits; if (needmore>0) output.append(needmore,' '); // Pre-pad spaces output += tmp; break; } case 'u': { // Unsigned decimal - int digits=sprintf(tmp,"%llu",ld); + int digits=sprintf(tmp,"%" VL_PRI64 "u",ld); int needmore = width-digits; if (needmore>0) output.append(needmore,' '); // Pre-pad spaces output += tmp; @@ -360,9 +360,9 @@ void _vl_vsformat(string& output, const char* formatp, va_list ap) { case 't': { // Time int digits; if (VL_TIME_MULTIPLIER==1) { - digits=sprintf(tmp,"%llu",ld); + digits=sprintf(tmp,"%" VL_PRI64 "u",ld); } else if (VL_TIME_MULTIPLIER==1000) { - digits=sprintf(tmp,"%llu.%03llu", + digits=sprintf(tmp,"%" VL_PRI64 "u.%03" VL_PRI64 "u", (QData)(ld/VL_TIME_MULTIPLIER), (QData)(ld%VL_TIME_MULTIPLIER)); } else { @@ -553,7 +553,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_"); if (!tmp[0]) goto done; vlsint64_t ld; - sscanf(tmp,"%lld",&ld); + sscanf(tmp,"%" VL_PRI64 "d",&ld); VL_SET_WQ(owp,ld); break; } @@ -563,7 +563,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_"); if (!tmp[0]) goto done; QData ld; - sscanf(tmp,"%llu",&ld); + sscanf(tmp,"%" VL_PRI64 "u",&ld); VL_SET_WQ(owp,ld); break; } @@ -887,7 +887,7 @@ IData VL_VALUEPLUSARGS_IW(int rbits, const char* prefixp, char fmt, WDataOutP rw break; case 'd': vlsint64_t ld; - sscanf(dp,"%lld",&ld); + sscanf(dp,"%" VL_PRI64 "d",&ld); VL_SET_WQ(rwp,ld); break; case 'b': diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 20eac0e0d..5a85c6cd5 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -202,7 +202,7 @@ void VerilatedVcd::printStr (const char* str) { void VerilatedVcd::printQuad (vluint64_t n) { char buf [100]; - sprintf(buf,"%llu",(long long unsigned)n); + sprintf(buf,"%" VL_PRI64 "u",(long long unsigned)n); printStr(buf); } diff --git a/include/verilatedos.h b/include/verilatedos.h index 058fffb0c..8f5e4a543 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -136,6 +136,16 @@ typedef long long vlsint64_t; ///< 64-bit signed type typedef unsigned long long vluint64_t; ///< 64-bit unsigned type #endif +//========================================================================= +// Printing printf/scanf formats +// Alas cinttypes isn't that standard yet + +#ifdef _WIN32 +# define VL_PRI64 "I64" +#else // Linux or compliant Unix flavors +# define VL_PRI64 "ll" +#endif + //========================================================================= // Integer size macros diff --git a/nodist/spdiff b/nodist/spdiff index b8e4d7adb..516b03ac3 100755 --- a/nodist/spdiff +++ b/nodist/spdiff @@ -125,6 +125,7 @@ sub prep { $wholefile =~ s/\bSpScBvExposer/VlScBvExposer/g; # $wholefile =~ s/\b(uint[0-9]+_t)/vl$1/g; + $wholefile =~ s/%ll/%" VL_PRI64 "/g; # $wholefile =~ s/\bSP_SC_BV/VL_SC_BV/g; $wholefile =~ s/\bSP_UNLIKELY/VL_UNLIKELY/g; diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index d6b189f3f..3d84a188c 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -531,17 +531,17 @@ public: } for (int word=VL_WORDS_I(nodep->num().minWidth())-1; word>0; word--) { // Only 32 bits - llx + long long here just to appease CPP format warning - ofp()->printf(",0x%08llx", (long long)(nodep->num().dataWord(word))); + ofp()->printf(",0x%08" VL_PRI64 "x", (long long)(nodep->num().dataWord(word))); } - ofp()->printf(",0x%08llx)", (long long)(nodep->num().dataWord(0))); + ofp()->printf(",0x%08" VL_PRI64 "x)", (long long)(nodep->num().dataWord(0))); } else if (nodep->isQuad()) { vluint64_t num = nodep->toUQuad(); - if (num<10) ofp()->printf("VL_ULL(%lld)", (long long)num); - else ofp()->printf("VL_ULL(0x%llx)", (long long)num); + if (num<10) ofp()->printf("VL_ULL(%" VL_PRI64 "d)", (long long)num); + else ofp()->printf("VL_ULL(0x%" VL_PRI64 "x)", (long long)num); } else { uint32_t num = nodep->toUInt(); if (num<10) puts(cvtToStr(num)); - else ofp()->printf("0x%llx", (long long)num); + else ofp()->printf("0x%" VL_PRI64 "x", (long long)num); //Unneeded-Causes %lx format warnings: // if (!nodep->num().isSigned() && (num & (1UL<<31))) puts("U"); } diff --git a/src/V3File.cpp b/src/V3File.cpp index 798ef9c77..8cd6de575 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -161,7 +161,7 @@ inline void V3FileDependImp::writeTimes(const string& filename, const string& cm *ofp<<"# DESCR"<<"IPTION: Verilator output: Timestamp data for --skip-identical. Delete at will."<::iterator iter=m_filenameList.begin(); @@ -258,7 +258,7 @@ void V3File::createMakeDir() { static bool created = false; if (!created) { created = true; -#ifndef __WIN32 +#ifndef _WIN32 mkdir(v3Global.opt.makeDir().c_str(), 0777); #else mkdir(v3Global.opt.makeDir().c_str()); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 99cecc4a1..53cc7a2ab 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -23,7 +23,7 @@ #include "verilatedos.h" #include #include -#if !defined(__WIN32) +#ifndef _WIN32 # include #endif #include @@ -330,7 +330,7 @@ void V3Options::setenvStr(const string& envvar, const string& value, const strin } else { UINFO(1,"export "<skip("Not in a git repository"); } else { + uint(); + printfll(); +} + +ok(1); + +sub uint { ### Must trim output before and after our file list #my $files = "*/*.c* */*.h test_regress/t/*.c* test_regress/t/*.h"; # src isn't clean, and probably doesn't need to be (yet?) @@ -31,7 +38,7 @@ if (!-r "$root/.git") { next if $line =~ m!include/svdpi.h!; # Not ours if ($line =~ /^([^:]+)/) { $names{$1} = 1; - print $line; + print "$line\n"; } } if (keys %names) { @@ -39,5 +46,22 @@ if (!-r "$root/.git") { } } -ok(1); +sub printfll { + my $files = "src/*.c* src/*.h include/*.c* include/*.h test_c/*.c* test_regress/t/*.c* test_regress/t/*.h"; + my $cmd = "cd $root && fgrep -n ll $files | sort"; + print "C $cmd\n"; + my $grep = `$cmd`; + my %names; + foreach my $line (split /\n/, $grep) { + next if $line !~ /%[^ ]*ll/; + if ($line =~ /^([^:]+)/) { + $names{$1} = 1; + print "$line\n"; + } + } + if (keys %names) { + $Self->error("Files with %ll instead of VL_PRI64: ",join(' ',sort keys %names)); + } +} + 1; diff --git a/test_regress/t/t_dpi_export_c.cpp b/test_regress/t/t_dpi_export_c.cpp index 826d90f0e..8a13edece 100644 --- a/test_regress/t/t_dpi_export_c.cpp +++ b/test_regress/t/t_dpi_export_c.cpp @@ -55,7 +55,8 @@ extern "C" { #define CHECK_RESULT(got, exp) \ if ((got) != (exp)) { \ - printf("%%Error: %s:%d: GOT = %llx EXP = %llx\n", __FILE__,__LINE__, (long long)(got), (long long)(exp)); \ + printf("%%Error: %s:%d: GOT = %" VL_PRI64 "x EXP = %" VL_PRI64 "x\n", \ + __FILE__,__LINE__, (long long)(got), (long long)(exp)); \ return __LINE__; \ } #define CHECK_RESULT_NNULL(got) \ diff --git a/test_regress/t/t_leak.cpp b/test_regress/t/t_leak.cpp index b5be1cdac..3af174bf2 100644 --- a/test_regress/t/t_leak.cpp +++ b/test_regress/t/t_leak.cpp @@ -31,7 +31,7 @@ long long get_memory_usage() { long long ps_vsize, ps_rss; int items = fscanf(fp, ("%d (%*[^) ]) %*1s %d %*d %*d %*d %*d %u" " %u %u %u %u %d %d %d %d" - " %*d %*d %*u %*u %d %llu %llu "), + " %*d %*d %*u %*u %d %" VL_PRI64 "u %" VL_PRI64 "u "), &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, &ps_ign, @@ -68,7 +68,7 @@ int main (int argc, char *argv[]) { make_and_destroy(); } firstUsage = get_memory_usage(); - printf("Memory size %lld bytes\n", firstUsage); + printf("Memory size %" VL_PRI64 "d bytes\n", firstUsage); int loops = 100*1000; for (int left=loops; left>0;) { @@ -79,7 +79,7 @@ int main (int argc, char *argv[]) { long long leaked = get_memory_usage() - firstUsage; if (leaked > 64*1024) { // Have to allow some slop for this code. - printf ("Leaked %lld bytes, or ~ %lld bytes/construt\n", leaked, leaked/loops); + printf ("Leaked %" VL_PRI64 "d bytes, or ~ %" VL_PRI64 "d bytes/construt\n", leaked, leaked/loops); vl_fatal(__FILE__,__LINE__,"top", "Leaked memory\n"); } diff --git a/test_regress/t/t_math_imm2.cpp b/test_regress/t/t_math_imm2.cpp index c0027b35f..cd552a560 100644 --- a/test_regress/t/t_math_imm2.cpp +++ b/test_regress/t/t_math_imm2.cpp @@ -30,7 +30,7 @@ int main (int argc, char *argv[]) { | MaskVal (sim->LowMaskSel_Bot, sim->HighMaskSel_Bot); if (sim->LogicImm != expected) { - printf ("%%Error: %d.%d,%d.%d -> %016llx/%016llx -> %016llx (expected %016llx)\n", + printf ("%%Error: %d.%d,%d.%d -> %016" VL_PRI64 "x/%016" VL_PRI64 "x -> %016" VL_PRI64 "x (expected %016" VL_PRI64 "x)\n", sim->LowMaskSel_Top, sim->HighMaskSel_Top, sim->LowMaskSel_Bot, sim->HighMaskSel_Bot, sim->LowLogicImm, sim->HighLogicImm,