From df52e481fb5b03338d45cc881270e75ba8c02108 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 23 Apr 2020 21:22:47 -0400 Subject: [PATCH] Collected minor output code cleanups. --- include/verilated.h | 8 ++++++-- include/verilatedos.h | 2 ++ src/V3EmitC.cpp | 8 +++++--- src/V3EmitCMain.cpp | 13 +++++++++---- src/V3Options.cpp | 4 ++++ 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/verilated.h b/include/verilated.h index c2bc2bfad..086838c47 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -853,9 +853,13 @@ double vl_time_multiplier(int scale); /// Evaluate expression if debug enabled #ifdef VL_DEBUG -# define VL_DEBUG_IF(text) {if (VL_UNLIKELY(Verilated::debug())) {text}} +# define VL_DEBUG_IF(text) \ + do { \ + if (VL_UNLIKELY(Verilated::debug())) {text} \ + } while (false) #else -# define VL_DEBUG_IF(text) +// We intentionally do not compile the text to improve compile speed +# define VL_DEBUG_IF(text) do {} while (false) #endif /// Collect coverage analysis for this line diff --git a/include/verilatedos.h b/include/verilatedos.h index ae2f14048..8f689190b 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -205,6 +205,7 @@ # define VL_INCLUDE_UNORDERED_SET # endif # define VL_FINAL final +# define VL_MUTABLE mutable # define VL_OVERRIDE override #else # define VL_EQ_DELETE @@ -212,6 +213,7 @@ # define VL_INCLUDE_UNORDERED_MAP "verilated_unordered_set_map.h" # define VL_INCLUDE_UNORDERED_SET "verilated_unordered_set_map.h" # define VL_FINAL +# define VL_MUTABLE # define VL_OVERRIDE #endif diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 89053334c..28c3ace73 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -2334,7 +2334,9 @@ void EmitCImp::emitDestructorImp(AstNodeModule* modp) { puts("\n"); puts(prefixNameProtect(modp) + "::~" + prefixNameProtect(modp) + "() {\n"); if (modp->isTop()) { - if (v3Global.opt.mtasks()) puts("delete __Vm_threadPoolp; __Vm_threadPoolp = NULL;\n"); + if (v3Global.opt.mtasks()) { + puts("VL_DO_CLEAR(delete __Vm_threadPoolp, __Vm_threadPoolp = NULL);\n"); + } // Call via function in __Trace.cpp as this .cpp file does not have trace header if (v3Global.needTraceDumper()) { puts("#ifdef VM_TRACE\n"); @@ -2343,7 +2345,7 @@ void EmitCImp::emitDestructorImp(AstNodeModule* modp) { } } emitTextSection(AstType::atScDtor); - if (modp->isTop()) puts("delete __VlSymsp; __VlSymsp=NULL;\n"); + if (modp->isTop()) puts("VL_DO_CLEAR(delete __VlSymsp, __VlSymsp = NULL);\n"); puts("}\n"); splitSizeInc(10); } @@ -3326,7 +3328,7 @@ class EmitCTrace : EmitCStmts { puts("void " + topClassName() + "::_traceDumpClose() {\n"); puts("VerilatedLockGuard lock(__VlSymsp->__Vm_dumperMutex);\n"); puts("__VlSymsp->__Vm_dumping = false;\n"); - puts("delete __VlSymsp->__Vm_dumperp; __VlSymsp->__Vm_dumperp = NULL;\n"); + puts("VL_DO_CLEAR(delete __VlSymsp->__Vm_dumperp, __VlSymsp->__Vm_dumperp = NULL);\n"); puts("}\n"); splitSizeInc(10); } diff --git a/src/V3EmitCMain.cpp b/src/V3EmitCMain.cpp index 14e67ed2a..f74bae3b0 100644 --- a/src/V3EmitCMain.cpp +++ b/src/V3EmitCMain.cpp @@ -76,10 +76,15 @@ private: puts("// Simulate until $finish\n"); puts("while (!Verilated::gotFinish()) {\n"); - /**/ puts("// Evaluate model\n"); - /**/ puts("topp->eval();\n"); - /**/ puts("// Advance time\n"); - /**/ puts("++main_time;\n"); + puts(/**/ "// Evaluate model\n"); + puts(/**/ "topp->eval();\n"); + puts(/**/ "// Advance time\n"); + puts(/**/ "++main_time;\n"); + puts("}\n"); + puts("\n"); + + puts("if (!Verilated::gotFinish()) {\n"); + puts(/**/ "VL_DEBUG_IF(VL_PRINTF(\"+ Exiting without $finish; no events left\\n\"););\n"); puts("}\n"); puts("\n"); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index a39b2387b..29b058b72 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -633,6 +633,10 @@ void V3Options::notify() { && !v3Global.opt.xmlOnly()); } + if (v3Global.opt.main() && v3Global.opt.systemC()) { + cmdfl->v3error("--main not usable with SystemC. Suggest see examples for sc_main()."); + } + // --trace-threads implies --threads 1 unless explicitly specified if (traceThreads() && !threads()) m_threads = 1;