From d21824cbae9e0fa73fc2b83b32746a21db7999eb Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 14 Oct 2017 13:00:25 -0400 Subject: [PATCH] Internals: Refactor verilated_vcd to move singleton into only .cpp. No functional change intended. --- include/verilated_vcd_c.cpp | 39 +++++++++++++++++++++++++++++-------- include/verilated_vcd_c.h | 6 ------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 90fe1618d..135c627b5 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -46,6 +46,34 @@ # define O_NONBLOCK 0 #endif +//============================================================================= +// VerilatedVcdImp +/// Base class to hold some static state +/// This is an internally used class + +class VerilatedVcdSingleton { +private: + typedef std::vector VcdVec; + struct Singleton { + VcdVec s_vcdVecp; ///< List of all created traces + }; + static Singleton& singleton() { static Singleton s; return s; } +public: + static void pushVcd(VerilatedVcd* vcdp) { + singleton().s_vcdVecp.push_back(vcdp); + } + static void removeVcd(const VerilatedVcd* vcdp) { + VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), vcdp); + if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); } + } + static void flush_all() { + for (VcdVec::const_iterator it=singleton().s_vcdVecp.begin(); it!=singleton().s_vcdVecp.end(); ++it) { + VerilatedVcd* vcdp = *it; + vcdp->flush(); + } + } +}; + //============================================================================= // VerilatedVcdCallInfo /// Internal callback routines for each module being traced. @@ -117,7 +145,7 @@ void VerilatedVcd::open (const char* filename) { // Set member variables m_filename = filename; - singleton().s_vcdVecp.push_back(this); + VerilatedVcdSingleton::pushVcd(this); // SPDIFF_OFF // Set callback so an early exit will flush us @@ -233,9 +261,7 @@ VerilatedVcd::~VerilatedVcd() { delete (*it); } m_callbacks.clear(); - // Remove from list of traces - VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), this); - if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); } + VerilatedVcdSingleton::removeVcd(this); } void VerilatedVcd::closePrev () { @@ -647,10 +673,7 @@ void VerilatedVcd::dumpDone () { // Static members void VerilatedVcd::flush_all() { - for (vluint32_t ent = 0; ent< singleton().s_vcdVecp.size(); ent++) { - VerilatedVcd* vcdp = singleton().s_vcdVecp[ent]; - vcdp->flush(); - } + VerilatedVcdSingleton::flush_all(); } //====================================================================== diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 46b18b763..9fa3eabf2 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -104,12 +104,6 @@ private: typedef std::map NameMap; NameMap* m_namemapp; ///< List of names for the header - typedef std::vector VcdVec; - struct Singleton { - VcdVec s_vcdVecp; ///< List of all created traces - }; - static Singleton& singleton() { static Singleton s; return s; } - void bufferResize(vluint64_t minsize); void bufferFlush(); inline void bufferCheck() {