From 0dbdbffba7afaed6206493dff91da8cb44647bc1 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 15 Apr 2014 18:50:04 -0400 Subject: [PATCH] Fix double I/O port warnings. --- src/V3AstNodes.cpp | 4 ++-- src/V3AstNodes.h | 2 +- src/V3EmitC.cpp | 17 +++++++++++++++-- src/V3EmitCBase.h | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 4749c7246..19c99fe3b 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -200,7 +200,7 @@ string AstVar::verilogKwd() const { } } -string AstVar::vlArgType(bool named, bool forReturn) const { +string AstVar::vlArgType(bool named, bool forReturn, bool forFunc) const { if (forReturn) named=false; if (forReturn) v3fatalSrc("verilator internal data is never passed as return, but as first argument"); string arg; @@ -233,7 +233,7 @@ string AstVar::vlArgType(bool named, bool forReturn) const { arg += " (& "+name(); arg += ")["+cvtToStr(widthWords())+"]"; } else { - if (isOutput() || (strtype && isInput())) arg += "&"; + if (forFunc && (isOutput() || (strtype && isInput()))) arg += "&"; if (named) arg += " "+name(); } return arg; diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 501d8f498..29354236c 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -965,7 +965,7 @@ public: string scType() const; // Return SysC type: bool, uint32_t, uint64_t, sc_bv string cPubArgType(bool named, bool forReturn) const; // Return C /*public*/ type for argument: bool, uint32_t, uint64_t, etc. string dpiArgType(bool named, bool forReturn) const; // Return DPI-C type for argument - string vlArgType(bool named, bool forReturn) const; // Return Verilator internal type for argument: CData, SData, IData, WData + string vlArgType(bool named, bool forReturn, bool forFunc) const; // Return Verilator internal type for argument: CData, SData, IData, WData string vlEnumType() const; // Return VerilatorVarType: VLVT_UINT32, etc string vlEnumDir() const; // Return VerilatorVarDir: VLVD_INOUT, etc void combineType(AstVarType type); diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 9a7e2df4b..65fa36bd4 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -604,7 +604,15 @@ public: } ofp()->printf(",0x%08" VL_PRI64 "x)", (vluint64_t)(nodep->num().dataWord(0))); } else if (nodep->isDouble()) { - ofp()->printf("%.17g", nodep->num().toDouble()); + if (int(nodep->num().toDouble()) == nodep->num().toDouble() + && nodep->num().toDouble() < 1000 + && nodep->num().toDouble() > -1000) { + ofp()->printf("%3.1f", nodep->num().toDouble()); // Force decimal point + } else { + // Not %g as will not always put in decimal point, so not obvious to compiler + // is a real number + ofp()->printf("%.17e", nodep->num().toDouble()); + } } else if (nodep->isQuad()) { vluint64_t num = nodep->toUQuad(); if (num<10) ofp()->printf("VL_ULL(%" VL_PRI64 "d)", num); @@ -922,6 +930,11 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) { puts(nodep->name()); emitDeclArrayBrackets(nodep); puts(";\n"); + } else if (basicp && basicp->isOpaque()) { + // strings and other fundamental c types; no VL_ macro can be used + puts(nodep->vlArgType(true,false,false)); + emitDeclArrayBrackets(nodep); + puts(";\n"); } else { // C++ signals ofp()->putAlign(nodep->isStatic(), nodep->dtypeSkipRefp()->widthAlignBytes(), nodep->dtypeSkipRefp()->widthTotalBytes()); @@ -945,7 +958,7 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) { } } else if (basicp && basicp->isOpaque()) { // strings and other fundamental c types - puts(nodep->vlArgType(true,false)); + puts(nodep->vlArgType(true,false,false)); emitDeclArrayBrackets(nodep); puts(";\n"); } else { diff --git a/src/V3EmitCBase.h b/src/V3EmitCBase.h index 61d6e2ce1..354b84402 100644 --- a/src/V3EmitCBase.h +++ b/src/V3EmitCBase.h @@ -78,7 +78,7 @@ public: args += portp->dpiArgType(true,false); else if (nodep->funcPublic()) args += portp->cPubArgType(true,false); - else args += portp->vlArgType(true,false); + else args += portp->vlArgType(true,false,true); } } }