Internals: Refactor verilated_vcd to move singleton into only .cpp. No functional change intended.

This commit is contained in:
Wilson Snyder
2017-10-14 13:00:25 -04:00
parent 124786ad1b
commit d21824cbae
2 changed files with 31 additions and 14 deletions
+31 -8
View File
@@ -46,6 +46,34 @@
# define O_NONBLOCK 0 # define O_NONBLOCK 0
#endif #endif
//=============================================================================
// VerilatedVcdImp
/// Base class to hold some static state
/// This is an internally used class
class VerilatedVcdSingleton {
private:
typedef std::vector<VerilatedVcd*> 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 // VerilatedVcdCallInfo
/// Internal callback routines for each module being traced. /// Internal callback routines for each module being traced.
@@ -117,7 +145,7 @@ void VerilatedVcd::open (const char* filename) {
// Set member variables // Set member variables
m_filename = filename; m_filename = filename;
singleton().s_vcdVecp.push_back(this); VerilatedVcdSingleton::pushVcd(this);
// SPDIFF_OFF // SPDIFF_OFF
// Set callback so an early exit will flush us // Set callback so an early exit will flush us
@@ -233,9 +261,7 @@ VerilatedVcd::~VerilatedVcd() {
delete (*it); delete (*it);
} }
m_callbacks.clear(); m_callbacks.clear();
// Remove from list of traces VerilatedVcdSingleton::removeVcd(this);
VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), this);
if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); }
} }
void VerilatedVcd::closePrev () { void VerilatedVcd::closePrev () {
@@ -647,10 +673,7 @@ void VerilatedVcd::dumpDone () {
// Static members // Static members
void VerilatedVcd::flush_all() { void VerilatedVcd::flush_all() {
for (vluint32_t ent = 0; ent< singleton().s_vcdVecp.size(); ent++) { VerilatedVcdSingleton::flush_all();
VerilatedVcd* vcdp = singleton().s_vcdVecp[ent];
vcdp->flush();
}
} }
//====================================================================== //======================================================================
-6
View File
@@ -104,12 +104,6 @@ private:
typedef std::map<std::string,std::string> NameMap; typedef std::map<std::string,std::string> NameMap;
NameMap* m_namemapp; ///< List of names for the header NameMap* m_namemapp; ///< List of names for the header
typedef std::vector<VerilatedVcd*> 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 bufferResize(vluint64_t minsize);
void bufferFlush(); void bufferFlush();
inline void bufferCheck() { inline void bufferCheck() {