diff --git a/include/verilated.h b/include/verilated.h index 51d1c2f8e..96d1ccdcd 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -127,8 +127,7 @@ class VL_CAPABILITY("mutex") VerilatedMutex { /// Lock guard for mutex (ala std::lock_guard), wrapped to allow -fthread_safety checks class VL_SCOPED_CAPABILITY VerilatedLockGuard { - VerilatedLockGuard(); ///< N/A, always use named constructor below - VerilatedLockGuard(const VerilatedLockGuard&); ///< N/A, no copy constructor + VL_UNCOPYABLE(VerilatedLockGuard); private: VerilatedMutex& m_mutexr; public: @@ -182,10 +181,9 @@ public: /// Base class for all Verilated module classes class VerilatedModule { + VL_UNCOPYABLE(VerilatedModule); private: const char* m_namep; ///< Module name - VerilatedModule() VL_EQ_DELETE; ///< N/A, always use named constructor below - VerilatedModule(const VerilatedModule& ) VL_EQ_DELETE; ///< N/A, no copy constructor public: explicit VerilatedModule(const char* namep); ///< Create module with given hierarchy name ~VerilatedModule(); @@ -346,8 +344,11 @@ class Verilated { ~ThreadLocal(); } t_s; -public: +private: + // CONSTRUCTORS + VL_UNCOPYABLE(Verilated); +public: // METHODS - User called /// Select initial value of otherwise uninitialized signals. diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index a14d06e69..34855cdea 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -111,6 +111,7 @@ private: m_insertFilenamep = NULL; m_insertLineno = 0; } + VL_UNCOPYABLE(VerilatedCovImp); public: ~VerilatedCovImp() { clearGuts(); } static VerilatedCovImp& imp() VL_MT_SAFE { diff --git a/include/verilated_cov.h b/include/verilated_cov.h index 18b82b87f..82dbf62a2 100644 --- a/include/verilated_cov.h +++ b/include/verilated_cov.h @@ -85,6 +85,7 @@ template< class T> std::string vlCovCvtToStr (const T& t) VL_PURE { /// All public methods in this class are thread safe. class VerilatedCov { + VL_UNCOPYABLE(VerilatedCov); public: // GLOBAL METHODS /// Return default filename diff --git a/include/verilated_imp.h b/include/verilated_imp.h index 2a427c559..c37a06399 100644 --- a/include/verilated_imp.h +++ b/include/verilated_imp.h @@ -86,8 +86,8 @@ public: // CONSTRUCTORS VerilatedEvalMsgQueue() : m_depth(0) { } ~VerilatedEvalMsgQueue() { } - VerilatedEvalMsgQueue(const VerilatedEvalMsgQueue&) = delete; - VerilatedEvalMsgQueue& operator=(const VerilatedEvalMsgQueue&) = delete; +private: + VL_UNCOPYABLE(VerilatedEvalMsgQueue); public: // METHODS //// Add message to queue (called by producer) @@ -133,9 +133,8 @@ public: // The only call of this with a non-empty queue is a fatal error. // So this does not flush the queue, as the destination queue is not known to this class. } - VerilatedThreadMsgQueue(const VerilatedThreadMsgQueue&) = delete; - VerilatedThreadMsgQueue& operator=(const VerilatedThreadMsgQueue&) = delete; private: + VL_UNCOPYABLE(VerilatedThreadMsgQueue); // METHODS static VerilatedThreadMsgQueue& threadton() { static VL_THREAD_LOCAL VerilatedThreadMsgQueue t_s; @@ -207,6 +206,9 @@ public: // But only for verilated*.cpp m_fdps[2] = stderr; } ~VerilatedImp() {} +private: + VL_UNCOPYABLE(VerilatedImp); +public: static void internalsDump() VL_MT_SAFE { VerilatedLockGuard guard(s_s.m_argMutex); VL_PRINTF_MT("internalsDump:\n"); diff --git a/include/verilated_save.h b/include/verilated_save.h index f62c53281..29c3549da 100644 --- a/include/verilated_save.h +++ b/include/verilated_save.h @@ -45,8 +45,10 @@ protected: void header() VL_MT_UNSAFE_ONE; void trailer() VL_MT_UNSAFE_ONE; + + // CONSTRUCTORS + VL_UNCOPYABLE(VerilatedSerialize); public: - // CREATORS VerilatedSerialize() { m_isOpen = false; m_bufp = new vluint8_t [bufferSize()]; @@ -73,7 +75,6 @@ public: return *this; // For function chaining } private: - VerilatedSerialize(const VerilatedSerialize&) VL_EQ_DELETE; ///< N/A, no copy constructor VerilatedSerialize& bufferCheck() VL_MT_UNSAFE_ONE { // Flush the write buffer if there's not enough space left for new information // We only call this once per vector, so we need enough slop for a very wide "b###" line @@ -105,8 +106,10 @@ protected: virtual void fill() = 0; void header() VL_MT_UNSAFE_ONE; void trailer() VL_MT_UNSAFE_ONE; + + // CONSTRUCTORS + VL_UNCOPYABLE(VerilatedDeserialize); public: - // CREATORS VerilatedDeserialize() { m_isOpen = false; m_bufp = new vluint8_t [bufferSize()]; @@ -137,7 +140,6 @@ public: VerilatedDeserialize& readAssert(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE; VerilatedDeserialize& readAssert(vluint64_t data) VL_MT_UNSAFE_ONE { return readAssert(&data, sizeof(data)); } private: - VerilatedDeserialize(const VerilatedDeserialize&) VL_EQ_DELETE; ///< N/A, no copy constructor bool readDiffers(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE; VerilatedDeserialize& bufferCheck() VL_MT_UNSAFE_ONE { // Flush the write buffer if there's not enough space left for new information @@ -158,7 +160,7 @@ private: int m_fd; ///< File descriptor we're writing to public: - // CREATORS + // CONSTRUCTORS VerilatedSave() { m_fd=-1; } virtual ~VerilatedSave() { close(); } // METHODS @@ -177,7 +179,7 @@ private: int m_fd; ///< File descriptor we're writing to public: - // CREATORS + // CONSTRUCTORS VerilatedRestore() { m_fd=-1; } virtual ~VerilatedRestore() { close(); } diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 5460e51da..b0b186d7e 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -96,7 +96,7 @@ protected: VerilatedVcdCallback_t m_changecb; ///< Incremental Dumping Callback function void* m_userthis; ///< Fake "this" for caller vluint32_t m_code; ///< Starting code number - // CREATORS + // CONSTRUCTORS VerilatedVcdCallInfo (VerilatedVcdCallback_t icb, VerilatedVcdCallback_t fcb, VerilatedVcdCallback_t changecb, void* ut, vluint32_t code) diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index f0b6bf392..4cfd7f41b 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -147,14 +147,9 @@ private: return out + static_cast((code)%94+33); } - VerilatedVcd(const VerilatedVcd&) VL_EQ_DELETE; ///< N/A, no copy constructor - -protected: - // METHODS - void evcd(bool flag) { m_evcd = flag; } - + // CONSTRUCTORS + VL_UNCOPYABLE(VerilatedVcd); public: - // CREATORS explicit VerilatedVcd(VerilatedVcdFile* filep=NULL); ~VerilatedVcd(); @@ -396,6 +391,10 @@ public: fullFloat (code, newval); } } + +protected: + // METHODS + void evcd(bool flag) { m_evcd = flag; } }; //============================================================================= @@ -406,10 +405,13 @@ public: class VerilatedVcdC { VerilatedVcd m_sptrace; ///< Trace file being created -public: + // CONSTRUCTORS + VL_UNCOPYABLE(VerilatedVcdC); +public: explicit VerilatedVcdC(VerilatedVcdFile* filep=NULL) : m_sptrace(filep) {} ~VerilatedVcdC() {} +public: // ACCESSORS /// Is file open? bool isOpen() const { return m_sptrace.isOpen(); } diff --git a/include/verilated_vcd_sc.h b/include/verilated_vcd_sc.h index 8f22f882f..065ded755 100644 --- a/include/verilated_vcd_sc.h +++ b/include/verilated_vcd_sc.h @@ -39,6 +39,8 @@ class VerilatedVcdSc : sc_trace_file , public VerilatedVcdC { + // CONSTRUCTORS + VL_UNCOPYABLE(VerilatedVcdSc); public: VerilatedVcdSc() { sc_get_curr_simcontext()->add_trace_file(this); @@ -58,8 +60,9 @@ public: spTrace()->set_time_resolution(sc_get_time_resolution().to_string()); # endif } - virtual ~VerilatedVcdSc() {} + + // METHODS /// Called by SystemC simulate() virtual void cycle (bool delta_cycle) { # if (SYSTEMC_VERSION>20011000) diff --git a/include/verilatedos.h b/include/verilatedos.h index 2b8b45651..52c796e4a 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -311,6 +311,14 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type /// Words this number of bits needs (1 bit=1 word) #define VL_WORDS_I(nbits) (((nbits)+(VL_WORDSIZE-1))/VL_WORDSIZE) +//========================================================================= +// Class definition helpers + +// Used to declare a class as uncopyable; put after a private: +#define VL_UNCOPYABLE(Type) \ + Type(const Type& other) VL_EQ_DELETE; \ + Type& operator= (const Type&) VL_EQ_DELETE + //========================================================================= // Verilated function size macros diff --git a/src/V3Ast.h b/src/V3Ast.h index d971c3376..c491f04f7 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -942,7 +942,7 @@ public: inline bool operator== (const V3Hash& rh) const { return m_both==rh.m_both; } inline bool operator!= (const V3Hash& rh) const { return m_both!=rh.m_both; } inline bool operator< (const V3Hash& rh) const { return m_both StrList; +private: + V3InFilterImp* m_impp; + + // CONSTRUCTORS + VL_UNCOPYABLE(V3InFilter); +public: + explicit V3InFilter(const string& command); + ~V3InFilter(); + // METHODS // Read file contents and return it. Return true on success. bool readWholefile(const string& filename, StrList& outl); - - // CONSTRUCTORS - explicit V3InFilter(const string& command); - ~V3InFilter(); }; //============================================================================ diff --git a/src/V3Global.h b/src/V3Global.h index 535825701..d9a72ece1 100644 --- a/src/V3Global.h +++ b/src/V3Global.h @@ -75,7 +75,7 @@ public: V3Options opt; // All options; let user see them directly public: - // CREATORS + // CONSTRUCTORS V3Global() { m_debugFileNumber = 0; m_widthMinUsage = VWidthMinUsage::LINT_WIDTH; diff --git a/src/V3Options.h b/src/V3Options.h index 6d0662225..64227fd09 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -180,10 +180,9 @@ class V3Options { bool parseLangExt(const char* swp, const char* langswp, const V3LangCode& lc); string filePathCheckOneDir(const string& modname, const string& dirname); - V3Options(const V3Options&) VL_EQ_DELETE; ///< N/A, no copy constructor - + // CONSTRUCTORS + VL_UNCOPYABLE(V3Options); public: - // CREATORS V3Options(); ~V3Options(); void setDebugMode(int level); diff --git a/src/V3Parse.h b/src/V3Parse.h index fcab13b88..1b67cc633 100644 --- a/src/V3Parse.h +++ b/src/V3Parse.h @@ -36,9 +36,9 @@ class V3Parse { private: V3ParseImp* m_impp; - V3Parse(const V3Parse&) VL_EQ_DELETE; ///< N/A, no copy constructor -public: // CONSTRUCTORS + VL_UNCOPYABLE(V3Parse); +public: // We must allow reading multiple files into one parser V3Parse(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* symp); ~V3Parse(); diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 9ca603356..8fd75af31 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -210,7 +210,7 @@ public: V3ParseSym* symp() { return m_symp; } public: - // CREATORS + // CONSTRUCTORS V3ParseImp(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* parserSymp) : m_rootp(rootp), m_filterp(filterp), m_symp(parserSymp) { m_fileline = NULL; diff --git a/src/V3ParseSym.h b/src/V3ParseSym.h index f98accaf3..98b0c7d20 100644 --- a/src/V3ParseSym.h +++ b/src/V3ParseSym.h @@ -43,6 +43,17 @@ private: VSymEnt* m_symCurrentp; // Active symbol table for additions/lookups SymStack m_sympStack; // Stack of upper nodes with pending symbol tables +public: + // CONSTRUCTORS + explicit V3ParseSym(AstNetlist* rootp) + : m_syms(rootp) { + s_anonNum = 0; // Number of next anonymous object + pushScope(findNewTable(rootp)); + m_symTableNextId = NULL; + m_symCurrentp = symCurrentp(); + } + ~V3ParseSym() {} + private: // METHODS static VSymEnt* getTable(AstNode* nodep) { @@ -146,16 +157,6 @@ public: // Export *::* from remote packages symCurrentp()->exportStarStar(&m_syms); } -public: - // CREATORS - explicit V3ParseSym(AstNetlist* rootp) - : m_syms(rootp) { - s_anonNum = 0; // Number of next anonymous object - pushScope(findNewTable(rootp)); - m_symTableNextId = NULL; - m_symCurrentp = symCurrentp(); - } - ~V3ParseSym() {} }; #endif // Guard diff --git a/src/V3SymTable.h b/src/V3SymTable.h index c7c06658c..4ba87d406 100644 --- a/src/V3SymTable.h +++ b/src/V3SymTable.h @@ -245,18 +245,24 @@ class VSymGraph { // TYPES typedef vector SymStack; -private: // MEMBERS VSymEnt* m_symRootp; // Root symbol table SymStack m_symsp; // All symbol tables, to cleanup - VSymGraph(const VSymGraph&) VL_EQ_DELETE; ///< N/A, no copy constructor - -protected: - friend class VSymEnt; - void pushNewEnt(VSymEnt* entp) { m_symsp.push_back(entp); } + // CONSTRUCTORS + VL_UNCOPYABLE(VSymGraph); +public: + explicit VSymGraph(AstNetlist* nodep) { + m_symRootp = new VSymEnt(this, nodep); + } + ~VSymGraph() { + for (SymStack::iterator it = m_symsp.begin(); it != m_symsp.end(); ++it) { + delete (*it); + } + } public: + // METHODS VSymEnt* rootp() const { return m_symRootp; } // Debug void dump(ostream& os, const string& indent="") { @@ -280,16 +286,10 @@ public: dump(*logp, ""); } } -public: - // CREATORS - explicit VSymGraph(AstNetlist* nodep) { - m_symRootp = new VSymEnt(this, nodep); - } - ~VSymGraph() { - for (SymStack::iterator it = m_symsp.begin(); it != m_symsp.end(); ++it) { - delete (*it); - } - } + +protected: + friend class VSymEnt; + void pushNewEnt(VSymEnt* entp) { m_symsp.push_back(entp); } }; //###################################################################### diff --git a/src/VlcOptions.h b/src/VlcOptions.h index 17c2e1eed..6c1c7bb16 100644 --- a/src/VlcOptions.h +++ b/src/VlcOptions.h @@ -52,7 +52,7 @@ private: bool onoff(const char* sw, const char* arg, bool& flag); public: - // CREATORS + // CONSTRUCTORS VlcOptions() { m_annotateAll = false; m_annotateMin = 10;